简体   繁体   English

如何使用React Native创建模态窗口?

[英]How to create Modal Window using React Native?

developers! 开发商!

I have tried to create a simple Modal Window with React. 我试图用React创建一个简单的模态窗口。

But my window still not appeared! 但是我的窗户仍然没有出现!

So, my code have two parts: JS-part and CSS-part. 因此,我的代码分为两部分:JS部分和CSS部分。

I used "Modal" keyword, constructor and render(). 我使用了“ Modal”关键字,构造函数和render()。 All my code was written in CodePen area, so I'm able to see the result. 我所有的代码都是在CodePen区域编写的,因此我可以看到结果。 But still something missing. 但是仍然缺少一些东西。 What is it? 它是什么?

It will be mobile application. 它将是移动应用程序。 So, should I use keyword "Native" somewhere? 因此,我应该在某处使用关键字“ Native”吗?

 import "./modal.scss"; class Modal extends React.Component { constructor(props) { super(props); } shouldComponentUpdate(nextProps) { return !I.is(this.props.data, nextProps.data); } render() { let isOpen = this.props.data.get("isOpen"); return ( <div className={`flex middle center modal ${isOpen ? "open" : ""}`}> {isOpen ? (<div className={`row modal-content ${this.props.size || ""}`}> <div className="col-12 middle modal-title">{this.props.title}</div> <div className="col-12 modal-body"> {this.props.body} </div> <div className="col-12 middle modal-footer">{this.props.footer}</div> </div>) : null } </div>); } } export default Modal; 
 .modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 10000; padding: 2rem; background-color: rgba(0, 0, 0, 0.55); .modal-content { background-color: white; max-height: 80%; height: 80%; .modal-title { padding: 0 2.25rem; height: 5rem; max-height: 5rem; text-transform: uppercase; font-size: 1.8rem; } .modal-body { height: calc(100% - 16rem); overflow-y: scroll; padding: 0 2rem; } .modal-footer { height: 5rem; max-height: 5rem; padding: 0 2.25rem; } } } 

See also a fragment from CodePen: enter image description here 另请参阅来自CodePen的片段: 在此处输入图片描述

import Modal from "react-native-modal";

render () {
    return (
      <View>
        <Modal isVisible={true}>
          <View style={{ flex: 1 }}>
            <Text>I am the modal content!</Text>
          </View>
        </Modal>
      </View>
    )
  }

See also https://github.com/react-native-community/react-native-modal 另请参阅https://github.com/react-native-community/react-native-modal

I think what you're trying to do is make a mobile application. 我认为您想要做的是制作一个移动应用程序。 The best way to do that would be to use React React Native instead of React 最好的方法是使用React React Native而不是React

Check this out: 看一下这个:

https://github.com/react-community/create-react-native-app https://github.com/react-community/create-react-native-app

Once you're started showing a modal on a screen is quite simple. 一旦开始在屏幕上显示模式,就非常简单。

https://facebook.github.io/react-native/docs/modal#docsNav https://facebook.github.io/react-native/docs/modal#docsNav

If this is your first time, it would be best to follow the getting started guide on React Native's website. 如果您是第一次,那么最好遵循React Native网站上的入门指南。 Its helpful. 它有帮助。 There are no divs, but inLine styling can still be used. 没有div,但仍可以使用InLine样式。

https://facebook.github.io/react-native/docs/getting-started https://facebook.github.io/react-native/docs/getting-started

Hope this helps 希望这可以帮助

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

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