Browse Source

Close modal button (#1739)

* Add a button to the modal example to hide modal

* Render button only for iOS
Frank von Hoven III 7 years ago
parent
commit
d3997e6441
1 changed files with 46 additions and 1 deletions
  1. 46
    1
      example/src/screens/types/Modal.js

+ 46
- 1
example/src/screens/types/Modal.js View File

@@ -1,7 +1,34 @@
1 1
 import React, {Component} from 'react';
2
-import {StyleSheet, View, Text, Button} from 'react-native';
2
+import {StyleSheet, View, Text, Button, TouchableOpacity, Platform} from 'react-native';
3
+import {Navigation} from 'react-native-navigation';
4
+
5
+const CloseModalButton = ({text}) =>
6
+<TouchableOpacity
7
+  style={[styles.buttonContainer]}
8
+  onPress={() => navigator.dismissModal()}
9
+>
10
+  <View style={styles.closeModalButton}>
11
+    <Text style={styles.buttonText}>{text}</Text>
12
+  </View>
13
+</TouchableOpacity>;
14
+Navigation.registerComponent('CloseModalButton', () => CloseModalButton);
3 15
 
4 16
 class Modal extends Component {
17
+  static navigatorButtons = {
18
+    rightButtons: [
19
+      {
20
+        id: 'close-modal-button',
21
+        component: Platform.OS === 'ios' ? 'CloseModalButton' : null,
22
+        passProps: {
23
+          text: 'Close'
24
+        }
25
+      }
26
+    ]
27
+  };
28
+
29
+  componentWillMount() {
30
+    navigator = this.props.navigator;
31
+  }
5 32
 
6 33
   onPushScreen = () => {
7 34
     this.props.navigator.push({
@@ -58,6 +85,24 @@ const styles = StyleSheet.create({
58 85
   },
59 86
   button: {
60 87
     marginTop: 16
88
+  },
89
+  buttonContainer: {
90
+    width: 48,
91
+    height: 48,
92
+    justifyContent: 'center',
93
+    alignItems: 'center'
94
+  },
95
+  closeModalButton: {
96
+    backgroundColor: 'tomato',
97
+    width: 50,
98
+    height: 25,
99
+    borderRadius: 2,
100
+    overflow: 'hidden',
101
+    justifyContent: 'center',
102
+    alignItems: 'center'
103
+  },
104
+  buttonText: {
105
+    color: 'white'
61 106
   }
62 107
 });
63 108