From 8796960cb9aed10b6692ddb85e39576024fd4e01 Mon Sep 17 00:00:00 2001 From: Miguel Bolivar Date: Thu, 6 Feb 2020 12:09:33 -0400 Subject: [PATCH 1/6] New structure for class and functional components examples - Adding new code blocks as shown by @rachelnabors - Adding better styling for example - Only initial functional example added --- docs/modal.md | 115 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 106 insertions(+), 9 deletions(-) diff --git a/docs/modal.md b/docs/modal.md index 08bedd65c32..3438146c95c 100644 --- a/docs/modal.md +++ b/docs/modal.md @@ -5,47 +5,144 @@ title: Modal The Modal component is a basic way to present content above an enclosing view. +### Example -```SnackPlayer name=rn-modal + + +```SnackPlayer name=rn-modal-function-example import React, {Component, useState} from 'react'; -import {Modal, Text, TouchableHighlight, View, Alert} from 'react-native'; +import {Modal, Text, TouchableHighlight, View, Alert, StyleSheet} from 'react-native'; export default function App() { const [modalVisible, setModalVisible] = useState(false); return ( - + { Alert.alert('Modal has been closed.'); }}> - - - Hello World! + + + 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' + }, + 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" + } +}) + +``` + + + +```SnackPlayer name=rn-modal-class-example +import React, {Component} from 'react'; +import {Modal, Text, TouchableHighlight, View, Alert} from 'react-native'; + +class ModalExample extends Component { + state = { + modalVisible: false, + }; + + setModalVisible(visible) { + this.setState({modalVisible: visible}); + } + + render() { + return ( + + { + Alert.alert('Modal has been closed.'); + }}> + + + Hello World! + + { + this.setModalVisible(!this.state.modalVisible); + }}> + Hide Modal + + + + + + { + this.setModalVisible(true); + }}> + Show Modal + + + ); + } +} ``` + + --- # Reference From a5d0315e38d7f8fef066aebff501c90a01f55732 Mon Sep 17 00:00:00 2001 From: Miguel Bolivar Date: Thu, 13 Feb 2020 15:40:23 -0400 Subject: [PATCH 2/6] Updating example of class based component --- docs/modal.md | 136 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 101 insertions(+), 35 deletions(-) diff --git a/docs/modal.md b/docs/modal.md index 3438146c95c..10132036c28 100644 --- a/docs/modal.md +++ b/docs/modal.md @@ -10,29 +10,38 @@ The Modal component is a basic way to present content above an enclosing view. ```SnackPlayer name=rn-modal-function-example -import React, {Component, useState} from 'react'; -import {Modal, Text, TouchableHighlight, View, Alert, StyleSheet} from 'react-native'; - -export default function App() { +import React, { Component, useState } from "react"; +import { + Modal, + Text, + TouchableHighlight, + View, + Alert, + StyleSheet +} from "react-native"; + +const App = () => { const [modalVisible, setModalVisible] = useState(false); return ( - + { - Alert.alert('Modal has been closed.'); - }}> - - + Alert.alert("Modal has been closed."); + }} + > + + Hello World! { setModalVisible(!modalVisible); - }}> + }} + > Hide Modal @@ -43,7 +52,8 @@ export default function App() { style={styles.openButton} onPress={() => { setModalVisible(true); - }}> + }} + > Show Modal @@ -53,23 +63,24 @@ export default function App() { const styles = StyleSheet.create({ centeredView: { flex: 1, - justifyContent: 'center', - alignItems: 'center' + justifyContent: "center", + alignItems: "center", + marginTop: 22 }, modalView: { margin: 20, backgroundColor: "white", borderRadius: 20, padding: 35, - alignItems: 'center', + alignItems: "center", shadowColor: "#000", shadowOffset: { width: 0, - height: 2, + height: 2 }, shadowOpacity: 0.25, shadowRadius: 3.84, - elevation: 5, + elevation: 5 }, openButton: { backgroundColor: "#F194FF", @@ -86,17 +97,25 @@ const styles = StyleSheet.create({ marginBottom: 15, textAlign: "center" } -}) +}); +export default App; ``` ```SnackPlayer name=rn-modal-class-example import React, {Component} from 'react'; -import {Modal, Text, TouchableHighlight, View, Alert} from 'react-native'; - -class ModalExample extends Component { +import { + Modal, + Text, + TouchableHighlight, + View, + Alert, + StyleSheet +} from "react-native"; + +class App extends Component { state = { modalVisible: false, }; @@ -106,39 +125,86 @@ class ModalExample extends Component { } render() { + const { modalVisible } = this.state; return ( - + { - Alert.alert('Modal has been closed.'); - }}> - - - Hello World! + Alert.alert("Modal has been closed."); + }} + > + + + Hello World! { - this.setModalVisible(!this.state.modalVisible); - }}> - Hide Modal + setModalVisible(!modalVisible); + }} + > + Hide Modal { - this.setModalVisible(true); - }}> - Show Modal + 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; ``` From 321d37107e293d4c1b76b5f13cdfcb9899b58b49 Mon Sep 17 00:00:00 2001 From: Miguel Bolivar Date: Thu, 13 Feb 2020 15:53:00 -0400 Subject: [PATCH 3/6] Prettier code and adding correct SnackPlayer naming --- docs/modal.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/modal.md b/docs/modal.md index 10132036c28..6d6324c2534 100644 --- a/docs/modal.md +++ b/docs/modal.md @@ -9,15 +9,15 @@ The Modal component is a basic way to present content above an enclosing view. -```SnackPlayer name=rn-modal-function-example +```SnackPlayer name=Modal&supportedPlatforms=android,ios import React, { Component, useState } from "react"; import { + Alert, Modal, + StyleSheet, Text, TouchableHighlight, - View, - Alert, - StyleSheet + View } from "react-native"; const App = () => { @@ -58,7 +58,7 @@ const App = () => { ); -} +}; const styles = StyleSheet.create({ centeredView: { @@ -104,24 +104,24 @@ export default App; -```SnackPlayer name=rn-modal-class-example -import React, {Component} from 'react'; +```SnackPlayer name=Modal&supportedPlatforms=android,ios +import React, { Component } from "react"; import { + Alert, Modal, + StyleSheet, Text, TouchableHighlight, - View, - Alert, - StyleSheet + View } from "react-native"; class App extends Component { state = { - modalVisible: false, + modalVisible: false }; setModalVisible(visible) { - this.setState({modalVisible: visible}); + this.setState({ modalVisible: visible }); } render() { From 4bfc8beea0083d8cc8c341898e142499aee49bd0 Mon Sep 17 00:00:00 2001 From: Miguel Bolivar Date: Thu, 13 Feb 2020 16:02:40 -0400 Subject: [PATCH 4/6] Adding toggles for function or class component and fixing 'setModalVisible' call --- docs/modal.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/modal.md b/docs/modal.md index 6d6324c2534..ab9d58b5703 100644 --- a/docs/modal.md +++ b/docs/modal.md @@ -7,6 +7,17 @@ The Modal component is a basic way to present content above an enclosing view. ### Example +
+
    + + +
+
+ ```SnackPlayer name=Modal&supportedPlatforms=android,ios @@ -120,7 +131,7 @@ class App extends Component { modalVisible: false }; - setModalVisible(visible) { + setModalVisible = (visible) => { this.setState({ modalVisible: visible }); } @@ -143,7 +154,7 @@ class App extends Component { { - setModalVisible(!modalVisible); + this.setModalVisible(!modalVisible); }} > Hide Modal From d01b8e89221e9142fd0e2d499f2faeeaa735ee0f Mon Sep 17 00:00:00 2001 From: Miguel Bolivar Date: Thu, 13 Feb 2020 16:21:07 -0400 Subject: [PATCH 5/6] Adding missing this.setModalVisible on class example --- docs/modal.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/modal.md b/docs/modal.md index ab9d58b5703..6407a50a5af 100644 --- a/docs/modal.md +++ b/docs/modal.md @@ -166,7 +166,7 @@ class App extends Component { { - setModalVisible(true); + this.setModalVisible(true); }} > Show Modal From 5ace07a69cf971991a9dd7d296915f23ed3bbae0 Mon Sep 17 00:00:00 2001 From: Rachel Nabors Date: Mon, 17 Feb 2020 00:44:29 +0000 Subject: [PATCH 6/6] Update modal.md Seems like modal should work on Web --- docs/modal.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/modal.md b/docs/modal.md index 6407a50a5af..4d2d96a1b1c 100644 --- a/docs/modal.md +++ b/docs/modal.md @@ -20,7 +20,7 @@ The Modal component is a basic way to present content above an enclosing view. -```SnackPlayer name=Modal&supportedPlatforms=android,ios +```SnackPlayer name=Modal import React, { Component, useState } from "react"; import { Alert,