Browse Source

Renamed from js to tsx

Tom Underhill 4 years ago
parent
commit
a5103b0c26
5 changed files with 165 additions and 182 deletions
  1. 0
    169
      example/App.js
  2. 165
    13
      example/App.tsx
  3. 0
    0
      example/examples/Alerts.tsx
  4. 0
    0
      example/examples/Background.tsx
  5. 0
    0
      example/examples/Scrolling.tsx

+ 0
- 169
example/App.js View File

@@ -1,169 +0,0 @@
1
-/**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @format
8
- * @flow
9
- */
10
-
11
-import React, {Component} from 'react';
12
-import {
13
-  StyleSheet,
14
-  SafeAreaView,
15
-  Text,
16
-  TouchableOpacity,
17
-  View,
18
-  Keyboard,
19
-  Button,
20
-} from 'react-native';
21
-
22
-import Alerts from './examples/Alerts';
23
-import Scrolling from './examples/Scrolling';
24
-import Background from './examples/Background';
25
-
26
-const TESTS = {
27
-  Alerts: {
28
-    title: 'Alerts',
29
-    testId: 'alerts',
30
-    description: 'Alerts tests',
31
-    render() {
32
-      return <Alerts />;
33
-    },
34
-  },
35
-  Scrolling: {
36
-    title: 'Scrolling',
37
-    testId: 'scrolling',
38
-    description: 'Scrolling event test',
39
-    render() {
40
-      return <Scrolling />;
41
-    },
42
-  },
43
-  Background: {
44
-    title: 'Background',
45
-    testId: 'background',
46
-    description: 'Background color test',
47
-    render() {
48
-      return <Background />;
49
-    },
50
-  },
51
-};
52
-
53
-type Props = {};
54
-type State = {restarting: boolean, currentTest: Object};
55
-
56
-export default class App extends Component<Props, State> {
57
-  state = {
58
-    restarting: false,
59
-    currentTest: TESTS.Alerts,
60
-  };
61
-
62
-  _simulateRestart = () => {
63
-    this.setState({restarting: true}, () => this.setState({restarting: false}));
64
-  };
65
-
66
-  _changeTest = testName => {
67
-    this.setState({currentTest: TESTS[testName]});
68
-  };
69
-
70
-  render() {
71
-    const {restarting, currentTest} = this.state;
72
-    return (
73
-      <SafeAreaView style={styles.container}>
74
-        <TouchableOpacity
75
-          style={styles.closeKeyboardView}
76
-          onPress={() => Keyboard.dismiss()}
77
-          testID="closeKeyboard"
78
-        />
79
-
80
-        <TouchableOpacity
81
-          testID="restart_button"
82
-          onPress={this._simulateRestart}
83
-          style={styles.restartButton}
84
-          activeOpacity={0.6}>
85
-          <Text>Simulate Restart</Text>
86
-        </TouchableOpacity>
87
-
88
-        <View style={styles.testPickerContainer}>
89
-          <Button
90
-            testID="testType_alerts"
91
-            title="Alerts"
92
-            onPress={() => this._changeTest('Alerts')}
93
-          />
94
-          <Button
95
-            testID="testType_scrolling"
96
-            title="Scrolling"
97
-            onPress={() => this._changeTest('Scrolling')}
98
-          />
99
-          <Button
100
-            testID="testType_background"
101
-            title="Background"
102
-            onPress={() => this._changeTest('Background')}
103
-          />
104
-        </View>
105
-
106
-        {restarting ? null : (
107
-          <View
108
-            testID={`example-${currentTest.testId}`}
109
-            key={currentTest.title}
110
-            style={styles.exampleContainer}>
111
-            <Text style={styles.exampleTitle}>{currentTest.title}</Text>
112
-            <Text style={styles.exampleDescription}>
113
-              {currentTest.description}
114
-            </Text>
115
-            <View style={styles.exampleInnerContainer}>
116
-              {currentTest.render()}
117
-            </View>
118
-          </View>
119
-        )}
120
-      </SafeAreaView>
121
-    );
122
-  }
123
-}
124
-
125
-const styles = StyleSheet.create({
126
-  container: {
127
-    flex: 1,
128
-    backgroundColor: '#F5FCFF',
129
-    padding: 8,
130
-  },
131
-  exampleContainer: {
132
-    padding: 16,
133
-    backgroundColor: '#FFF',
134
-    borderColor: '#EEE',
135
-    borderTopWidth: 1,
136
-    borderBottomWidth: 1,
137
-    flex: 1,
138
-  },
139
-  exampleTitle: {
140
-    fontSize: 18,
141
-  },
142
-  exampleDescription: {
143
-    color: '#333333',
144
-    marginBottom: 16,
145
-  },
146
-  exampleInnerContainer: {
147
-    borderColor: '#EEE',
148
-    borderTopWidth: 1,
149
-    paddingTop: 10,
150
-    flex: 1,
151
-  },
152
-  restartButton: {
153
-    padding: 6,
154
-    fontSize: 16,
155
-    borderRadius: 5,
156
-    backgroundColor: '#F3F3F3',
157
-    alignItems: 'center',
158
-    justifyContent: 'center',
159
-    alignSelf: 'flex-end',
160
-  },
161
-  closeKeyboardView: {
162
-    width: 5,
163
-    height: 5,
164
-  },
165
-  testPickerContainer: {
166
-    flexDirection: 'row',
167
-    flexWrap: 'wrap',
168
-  },
169
-});

+ 165
- 13
example/App.tsx View File

@@ -1,17 +1,169 @@
1
-import React from 'react';
2
-import {SafeAreaView, StyleSheet} from 'react-native';
3
-import {WebView} from 'react-native-webview';
1
+/**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @flow
9
+ */
4 10
 
5
-const styles = StyleSheet.create({
6
-  container: {flex: 1, backgroundColor: '#20232a'},
7
-});
11
+import React, {Component} from 'react';
12
+import {
13
+  StyleSheet,
14
+  SafeAreaView,
15
+  Text,
16
+  TouchableOpacity,
17
+  View,
18
+  Keyboard,
19
+  Button,
20
+} from 'react-native';
8 21
 
9
-const App = () => {
10
-  return (
11
-    <SafeAreaView style={styles.container}>
12
-      <WebView source={{uri: 'https://facebook.github.io/react-native/'}} />
13
-    </SafeAreaView>
14
-  );
22
+import Alerts from './examples/Alerts';
23
+import Scrolling from './examples/Scrolling';
24
+import Background from './examples/Background';
25
+
26
+const TESTS = {
27
+  Alerts: {
28
+    title: 'Alerts',
29
+    testId: 'alerts',
30
+    description: 'Alerts tests',
31
+    render() {
32
+      return <Alerts />;
33
+    },
34
+  },
35
+  Scrolling: {
36
+    title: 'Scrolling',
37
+    testId: 'scrolling',
38
+    description: 'Scrolling event test',
39
+    render() {
40
+      return <Scrolling />;
41
+    },
42
+  },
43
+  Background: {
44
+    title: 'Background',
45
+    testId: 'background',
46
+    description: 'Background color test',
47
+    render() {
48
+      return <Background />;
49
+    },
50
+  },
15 51
 };
16 52
 
17
-export default App;
53
+type Props = {};
54
+type State = {restarting: boolean, currentTest: Object};
55
+
56
+export default class App extends Component<Props, State> {
57
+  state = {
58
+    restarting: false,
59
+    currentTest: TESTS.Alerts,
60
+  };
61
+
62
+  _simulateRestart = () => {
63
+    this.setState({restarting: true}, () => this.setState({restarting: false}));
64
+  };
65
+
66
+  _changeTest = testName => {
67
+    this.setState({currentTest: TESTS[testName]});
68
+  };
69
+
70
+  render() {
71
+    const {restarting, currentTest} = this.state;
72
+    return (
73
+      <SafeAreaView style={styles.container}>
74
+        <TouchableOpacity
75
+          style={styles.closeKeyboardView}
76
+          onPress={() => Keyboard.dismiss()}
77
+          testID="closeKeyboard"
78
+        />
79
+
80
+        <TouchableOpacity
81
+          testID="restart_button"
82
+          onPress={this._simulateRestart}
83
+          style={styles.restartButton}
84
+          activeOpacity={0.6}>
85
+          <Text>Simulate Restart</Text>
86
+        </TouchableOpacity>
87
+
88
+        <View style={styles.testPickerContainer}>
89
+          <Button
90
+            testID="testType_alerts"
91
+            title="Alerts"
92
+            onPress={() => this._changeTest('Alerts')}
93
+          />
94
+          <Button
95
+            testID="testType_scrolling"
96
+            title="Scrolling"
97
+            onPress={() => this._changeTest('Scrolling')}
98
+          />
99
+          <Button
100
+            testID="testType_background"
101
+            title="Background"
102
+            onPress={() => this._changeTest('Background')}
103
+          />
104
+        </View>
105
+
106
+        {restarting ? null : (
107
+          <View
108
+            testID={`example-${currentTest.testId}`}
109
+            key={currentTest.title}
110
+            style={styles.exampleContainer}>
111
+            <Text style={styles.exampleTitle}>{currentTest.title}</Text>
112
+            <Text style={styles.exampleDescription}>
113
+              {currentTest.description}
114
+            </Text>
115
+            <View style={styles.exampleInnerContainer}>
116
+              {currentTest.render()}
117
+            </View>
118
+          </View>
119
+        )}
120
+      </SafeAreaView>
121
+    );
122
+  }
123
+}
124
+
125
+const styles = StyleSheet.create({
126
+  container: {
127
+    flex: 1,
128
+    backgroundColor: '#F5FCFF',
129
+    padding: 8,
130
+  },
131
+  exampleContainer: {
132
+    padding: 16,
133
+    backgroundColor: '#FFF',
134
+    borderColor: '#EEE',
135
+    borderTopWidth: 1,
136
+    borderBottomWidth: 1,
137
+    flex: 1,
138
+  },
139
+  exampleTitle: {
140
+    fontSize: 18,
141
+  },
142
+  exampleDescription: {
143
+    color: '#333333',
144
+    marginBottom: 16,
145
+  },
146
+  exampleInnerContainer: {
147
+    borderColor: '#EEE',
148
+    borderTopWidth: 1,
149
+    paddingTop: 10,
150
+    flex: 1,
151
+  },
152
+  restartButton: {
153
+    padding: 6,
154
+    fontSize: 16,
155
+    borderRadius: 5,
156
+    backgroundColor: '#F3F3F3',
157
+    alignItems: 'center',
158
+    justifyContent: 'center',
159
+    alignSelf: 'flex-end',
160
+  },
161
+  closeKeyboardView: {
162
+    width: 5,
163
+    height: 5,
164
+  },
165
+  testPickerContainer: {
166
+    flexDirection: 'row',
167
+    flexWrap: 'wrap',
168
+  },
169
+});

example/examples/Alerts.js → example/examples/Alerts.tsx View File


example/examples/Background.js → example/examples/Background.tsx View File


example/examples/Scrolling.js → example/examples/Scrolling.tsx View File