瀏覽代碼

Update Android alert

Guy Carmeli 4 年之前
父節點
當前提交
eb2febeff2
共有 2 個檔案被更改,包括 40 行新增48 行删除
  1. 9
    18
      playground/src/app.js
  2. 31
    30
      playground/src/screens/Alert.js

+ 9
- 18
playground/src/app.js 查看文件

@@ -7,25 +7,16 @@ const testIDs = require('./testIDs');
7 7
 const Screens = require('./screens/Screens');
8 8
 
9 9
 if (Platform.OS === 'android') {
10
-  alert = (title) => {
11
-    Navigation.showOverlay({
12
-      component: {
13
-        name: Screens.Alert,
14
-        passProps: {
15
-          title
16
-        },
17
-        options: {
18
-          layout: {
19
-            componentBackgroundColor: 'transparent'
20
-          },
21
-          overlay: {
22
-            interceptTouchOutside: true
23
-          }
24
-        }
10
+  alert = (title, message) => Navigation.showOverlay({
11
+    component: {
12
+      name: Screens.Alert,
13
+      passProps: {
14
+        title,
15
+        message
25 16
       }
26
-    });
27
-  };
28
-}
17
+    }
18
+  });
19
+};
29 20
 
30 21
 function start() {
31 22
   registerScreens();

+ 31
- 30
playground/src/screens/Alert.js 查看文件

@@ -1,52 +1,53 @@
1 1
 const React = require('react');
2
-const { PureComponent } = require('react');
3
-
4 2
 const { Text, Button, View } = require('react-native');
5 3
 const { Navigation } = require('react-native-navigation');
6
-
7 4
 const testIDs = require('../testIDs');
8 5
 
9
-class Alert extends PureComponent {
6
+function Alert({ componentId, title, message }) {
7
+  const onCLickOk = () => Navigation.dismissOverlay(componentId);
10 8
 
11
-  render() {
12
-    return (
13
-      <View style={styles.root} key={'overlay'}>
14
-        <View style={styles.alert}>
15
-          <Text style={styles.h1} testID={testIDs.DIALOG_HEADER}>{this.props.title}</Text>
16
-          <View style={styles.buttonContainer}>
17
-            <Button title='OK' testID={testIDs.OK_BUTTON} onPress={() => this.onCLickOk()} />
18
-          </View>
19
-        </View>
9
+  return (
10
+    <View style={styles.root} key={'overlay'}>
11
+      <View style={styles.alert}>
12
+        <Text style={styles.title} testID={testIDs.DIALOG_HEADER}>{title}</Text>
13
+        <Text style={styles.message}>{message}</Text>
14
+        <Button title='OK' testID={testIDs.OK_BUTTON} onPress={onCLickOk} />
20 15
       </View>
21
-    );
22
-  }
23
-
24
-  onCLickOk() {
25
-    Navigation.dismissOverlay(this.props.componentId);
26
-  }
16
+    </View>
17
+  );
27 18
 }
28 19
 
29 20
 const styles = {
30 21
   root: {
22
+    flex: 1,
31 23
     justifyContent: 'center',
32 24
     alignItems: 'center',
33
-    flex: 1
25
+    backgroundColor: '#00000050',
34 26
   },
35 27
   alert: {
36 28
     alignItems: 'center',
37
-    backgroundColor: '#efefef',
29
+    backgroundColor: 'whitesmoke',
38 30
     width: 250,
39
-    height: 100,
40
-    elevation: 4
31
+    elevation: 4,
32
+    padding: 16
41 33
   },
42
-  buttonContainer: {
43
-    width: '50%',
44
-    alignItems: 'center'
45
-  },
46
-  h1: {
34
+  title: {
47 35
     fontSize: 18,
48
-    margin: 10
36
+  },
37
+  message: {
38
+    marginVertical: 8
49 39
   }
50 40
 };
51 41
 
52
-module.exports = Alert;
42
+Alert.options = (props) => {
43
+  return ({
44
+    layout: {
45
+      componentBackgroundColor: 'transparent'
46
+    },
47
+    overlay: {
48
+      interceptTouchOutside: true
49
+    }
50
+  });
51
+}
52
+
53
+module.exports = Alert;