React native 具有打开对话框的元素的ListView

React native 具有打开对话框的元素的ListView,react-native,modal-dialog,react-navigation,React Native,Modal Dialog,React Navigation,我会尽力解释我的情况 我收集了一个“事件”数组,然后ListView处理所有这些行,如我所期望的那样显示 <ListView dataSource={this.state.dataSource} enableEmptySections={true} // For warning... renderRow={(rowData) => <EventComponent data={rowData} />} /> } /> 是呈现所有行的一个 我现在需

我会尽力解释我的情况

我收集了一个“事件”数组,然后
ListView
处理所有这些行,如我所期望的那样显示

<ListView
   dataSource={this.state.dataSource}
   enableEmptySections={true} // For warning...
   renderRow={(rowData) => <EventComponent data={rowData} />}
/>
}
/>
是呈现所有行的一个

我现在需要做的是: 显示有关每个事件的更多信息,单击事件标题(换句话说,单击并弹出)

我第一次想到它是模态的

class EventComponent extends Component {
constructor(props) {
    super(props);
    this.state = {
        modalVisible: false,
    }
}

render() {
    return (
        <View style={styles.userDefined.event}>

            <MoreInfo data={this.props.data} show={this.state.modalVisible}/>   <------ my solution

            <View style={{flex:0.02, backgroundColor: this.props.data.color}} />
            <View style={{flex: 0.98, marginLeft: 5}}>
                <Text onLongPress={() => !this.state.modalVisible} style={[styles.userDefined.eventName, {color: this.props.data.color}]}>{this.props.data.name}</Text>
                <Text style={styles.userDefined.eventBy}>{this.props.data.owner}</Text>
                <Text style={styles.userDefined.eventContent}>{this.props.data.startTime} - {this.props.data.endTime}</Text>
                <Text style={styles.userDefined.eventContent}>Espacio: {this.props.data.space}</Text>
            </View>
        </View>
    )
}
}
类EventComponent扩展组件{
建造师(道具){
超级(道具);
此.state={
modalVisible:错误,
}
}
render(){
返回(
{this.props.data.name}
{this.props.data.owner}
{this.props.data.startTime}-{this.props.data.endTime}
Espacio:{this.props.data.space}
)
}
}
到目前为止,
组件是我的解决方案,但我有两个问题(这就是它如何证明我是react的新手)

  • 我需要在按下事件(
    )时显示模式(
  • 我需要检索一个
    事件id
    (已在
    中使用
    this.props.data.event\u id
    )到模式
    中,然后对数据库进行查询并显示结果
  • 你觉得怎么样?可能吗


    向我的朋友们问好是的,你所做的完全正确。 我的意思是,使用状态
    modalvisible
    来控制模态的可见性(实际上是对话框)并将
    this.props.data
    传递给模态是合理的


    那你担心什么呢?如果你在使用过程中没有任何问题,就不必考虑最佳实践。p> 是的,你所做的完全正确。 我的意思是,使用状态
    modalvisible
    来控制模态的可见性(实际上是对话框)并将
    this.props.data
    传递给模态是合理的


    那你担心什么呢?如果你在使用过程中没有任何问题,就不必考虑最佳实践。p> 这更像是一个设计问题,但您要做的是保持源代码完整,而不是在组件中。这样,通过映射每个源,您就有了要操作的值。例如this.state.sources.map(obj=>{obj.title});对不起,你的回答让我有点困惑。我需要的是将父组件的id传递给组件
    ,但我无法检索它这更像是一个设计问题,但您要做的是保持源代码完好无损,而不是在组件中。这样,通过映射每个源,您就有了要操作的值。例如this.state.sources.map(obj=>{obj.title});对不起,你的回答让我有点困惑。我需要的是将父组件
    的id传递给组件
    ,但我现在无法检索itLet的坚持!结束这个项目的时间很短。谢谢德莱,我们现在就坚持下去!结束这个项目的时间很短。谢谢D