简体   繁体   English

如何在本机反应中垂直和水平对齐模态

[英]How to Vertically and Horizontally align Modal in react native

I am trying to write a signup form and its loading screen modal.我正在尝试编写一个注册表单及其加载屏幕模式。

For some reason the modal is not vertically and horizontally align由于某种原因,模态不是垂直和水平对齐

<View style={{flex: 1,flexDirection: 'column',alignItems: 'center'}}>

      <View>
         <Text>Something</Text>
         <Text>Something</Text>
         <Text>Something</Text>
         <Text>Something</Text> 
         <Text>Something</Text>

        <TouchableOpacity style={styles.button} onPress={() => alert('hello')}>
          <Text style={styles.button_text}>CREATE YOUR NEW ACCOUNT</Text>
        </TouchableOpacity>
      </View>

      <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
        <Modal
          animationType="slide"
          transparent={true}
          visible={modalVisible}
          onRequestClose={() => {
            Alert.alert('Modal has been closed.');
            setModalVisible(!modalVisible);
          }}>
          <View
            style={{width: 300, height: 300, backgroundColor: 'red'}}></View>
        </Modal>
      </View>
    </View>

Can someone help please, here is how current situation is, I want the modal to horizontally and vertically align in the screen有人可以帮忙吗,这是目前的情况,我希望模态在屏幕上水平和垂直对齐

现在的情况

Try this尝试这个

    <Modal
      animationType="slide"
      transparent={true}
      visible={modalVisible}
      onRequestClose={() => {
        Alert.alert('Modal has been closed.');
        setModalVisible(!modalVisible);
      }}>
      <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
         <View style={{width: 300, height: 300, backgroundColor: 'red'}}>
            ...other components you need
         </View>
      </View>
    </Modal>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM