javascript - react-native 在模态内打开一个模态

标签 javascript react-native

我正在使用 react-native-sectioned-multi-select图书馆。单击确认按钮后,我想打开另一个模态视图。

我觉得我的代码是正确的,但这行不通。是否可以在该库中打开一个新模式?

const items = [
  {
    name: "Fruits",
    id: 0,
    children: [{
        name: "Apple",
        id: 10,
      },{
        name: "Strawberry",
        id: 17,
      },{
        name: "Pineapple",
        id: 13,
      },{
        name: "Banana",
        id: 14,
      },{
        name: "Watermelon",
        id: 15,
      },{
        name: "Kiwi fruit",
        id: 16,
      }]
  }]

export default class TestScreen extends Component {
  constructor(){
    super()
    this.state = {
      selectedItems: [],
      modalVisible: false,
    }
  }

  setModalVisible(visible) {
    this.setState({modalVisible: visible});
  }

  onSelectedItemsChange = (selectedItems) => {
    this.setState({ selectedItems });
    console.log(selectedItems)
  }

  openModal = () => {
   return(
      <SafeAreaView style={{flex:1}}>
         <View style={{width:300, height:400, backgroundColor:'red'}}>
           <Modal
             animationType="slide"
             transparent={false}
             visible={this.state.modalVisible}
             onRequestClose={() => {
               Alert.alert('Modal has been closed.');
             }}>
             <View style={{marginTop: 22}}>
               <View>
                 <Text>Hello World!</Text>

                 <TouchableHighlight
                   onPress={() => {
                     this.setModalVisible(!this.state.modalVisible);
                   }}>
                   <Text>Hide Modal</Text>
                 </TouchableHighlight>
               </View>
             </View>
           </Modal>

           <TouchableHighlight
             onPress={() => {
               this.setModalVisible(true);
             }}>
             <Text>Show Modal</Text>
           </TouchableHighlight>
         </View>
        </SafeAreaView>
    )
  }

  render() {
    return (
    <SafeAreaView style={{flex:1}}>
    <View>
        <SectionedMultiSelect
          items={items}
          uniqueKey='id'
          subKey='children'
          selectText='Choose some things...'
          showDropDowns={true}
          readOnlyHeadings={true}
          onSelectedItemsChange={this.onSelectedItemsChange}
          selectedItems={this.state.selectedItems}
//Here I call the openModal function but nothing appears

          onConfirm={()=> {this.openModal}}
        />
      </View>
    </SafeAreaView>
    );
  }
} 

如有任何意见或建议,我们将不胜感激!提前致谢! :)

已编辑

如果我不能一次打开两个模态框,我希望在关闭第一个模态框后打开新的模态框。

最佳答案

多个同时打开的模式在 React Native 中不起作用。你可以:

  • 在打开第二个模式之前关闭第一个模式,然后在完成第二个模式后重新打开第一个模式
  • 使用“position:absolute”样式滚动您自己的模态

关于javascript - react-native 在模态内打开一个模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53983781/

相关文章:

javascript - 使用 LinkedIn 登录授权 promise 未定义

reactjs - NPM 还是 yarn ?启动 React Native 项目和管理包的标准做法是什么?

javascript - 无法将表单标签添加到表中

javascript - 对不同文件进行 native 导航 react

javascript - 如何在主页中保存模态弹出窗口值

javascript - 公理 : How to run multiple requests one after the other?

javascript - 垂直滑动/切换菜单

用于服务器端验证的 javascript 事务日志

javascript - 尝试从本地 JSON 文件调用图像时,图像不会加载

ios - React Native SVG - (iOS) 不变违规 : Native component for "RNSVGSvgView" does not exist