diff --git a/docs/modal.md b/docs/modal.md index 08bedd65c32..4d2d96a1b1c 100644 --- a/docs/modal.md +++ b/docs/modal.md @@ -5,47 +5,221 @@ title: Modal The Modal component is a basic way to present content above an enclosing view. - -```SnackPlayer name=rn-modal -import React, {Component, useState} from 'react'; -import {Modal, Text, TouchableHighlight, View, Alert} from 'react-native'; - -export default function App() { +### Example + +
+ +
+ + + +```SnackPlayer name=Modal +import React, { Component, useState } from "react"; +import { + Alert, + Modal, + StyleSheet, + Text, + TouchableHighlight, + View +} from "react-native"; + +const App = () => { const [modalVisible, setModalVisible] = useState(false); return ( - + { - Alert.alert('Modal has been closed.'); - }}> - - - Hello World! + Alert.alert("Modal has been closed."); + }} + > + + + Hello World! { setModalVisible(!modalVisible); - }}> - Hide Modal + }} + > + Hide Modal { setModalVisible(true); - }}> - Show Modal + }} + > + Show Modal ); +}; + +const styles = StyleSheet.create({ + centeredView: { + flex: 1, + justifyContent: "center", + alignItems: "center", + marginTop: 22 + }, + modalView: { + margin: 20, + backgroundColor: "white", + borderRadius: 20, + padding: 35, + alignItems: "center", + shadowColor: "#000", + shadowOffset: { + width: 0, + height: 2 + }, + shadowOpacity: 0.25, + shadowRadius: 3.84, + elevation: 5 + }, + openButton: { + backgroundColor: "#F194FF", + borderRadius: 20, + padding: 10, + elevation: 2 + }, + textStyle: { + color: "white", + fontWeight: "bold", + textAlign: "center" + }, + modalText: { + marginBottom: 15, + textAlign: "center" + } +}); + +export default App; +``` + + + +```SnackPlayer name=Modal&supportedPlatforms=android,ios +import React, { Component } from "react"; +import { + Alert, + Modal, + StyleSheet, + Text, + TouchableHighlight, + View +} from "react-native"; + +class App extends Component { + state = { + modalVisible: false + }; + + setModalVisible = (visible) => { + this.setState({ modalVisible: visible }); + } + + render() { + const { modalVisible } = this.state; + return ( + + { + Alert.alert("Modal has been closed."); + }} + > + + + Hello World! + + { + this.setModalVisible(!modalVisible); + }} + > + Hide Modal + + + + + + { + this.setModalVisible(true); + }} + > + Show Modal + + + ); + } } + +const styles = StyleSheet.create({ + centeredView: { + flex: 1, + justifyContent: "center", + alignItems: "center", + marginTop: 22 + }, + modalView: { + margin: 20, + backgroundColor: "white", + borderRadius: 20, + padding: 35, + alignItems: "center", + shadowColor: "#000", + shadowOffset: { + width: 0, + height: 2 + }, + shadowOpacity: 0.25, + shadowRadius: 3.84, + elevation: 5 + }, + openButton: { + backgroundColor: "#F194FF", + borderRadius: 20, + padding: 10, + elevation: 2 + }, + textStyle: { + color: "white", + fontWeight: "bold", + textAlign: "center" + }, + modalText: { + marginBottom: 15, + textAlign: "center" + } +}); + +export default App; ``` + + --- # Reference