简体   繁体   English

使用 React-native 模态框形成和设置适当的对话框或警告框

[英]Forming and styling a proper dialog or alert like box with React-native modal

I want to make a general dialog box with the help of react native modal.我想在 react native modal 的帮助下制作一个通用对话框。 I have made the code as follows:我制作的代码如下:

<Modal isVisible={isModalVisible} style={styles.modalStyle} >                                      
   <Text>Hello World!</Text>                               
</Modal>

And below the style is mentioned:下面提到了样式:

const styles = StyleSheet.create({
    modalStyle : {
      top                   : '50%',
      left                  : '50%',
      right                 : 'auto',
      bottom                : 'auto',
      marginRight           : '-50%',

    },
}

But the modal dialog is consuming the whole screen!但是模态对话框正在消耗整个屏幕!

I have also tried editing the code to:我还尝试将代码编辑为:

<Modal>
  <View style={{ flex: 1, top: 50%, left: 50%, width: 70%, height : 50% }}>
       <Text>Hello World!</Text>
  </View>
</Modal>

removing the style in the Modal.删除 Modal 中的样式。 But still the same result!但还是一样的结果!

In-Built Modal of react-native is sometimes difficult to customise. react-native的内置模态有时难以定制。 There is this awesome library I have used number of times.有一个很棒的库,我用过很多次。 See this .看到这个

I've used react native modal, and to show the modal partially, what i did is, where the height is 100, so you can cutsomise the height我使用了反应原生模态,并部分显示模态,我所做的是,高度为 100,所以你可以削减高度

<Modal isVisible={true} style={{justifyContent: "flex-end"}} >
<View style={{height:100}}>
</View>
</Modal>

now, try once.现在,尝试一次。 and letme know if this works.让我知道这是否有效。 coz it works for me.因为它对我有用。 otherwise ill alter it.否则生病改变它。

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

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