Skip to content

Commit b2fd630

Browse files
authored
chore: migrate example app to TypeScript (#721)
When upgrading Flow (from upgrading react-native), a bunch of errors come from the test app. Taking this opportunity to migrate to TypeScript to avoid future issues. Next up would be to convert the rest of the Flow files.
1 parent 8f6d464 commit b2fd630

File tree

14 files changed

+530
-476
lines changed

14 files changed

+530
-476
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,5 @@ jobs:
6464
working-directory: example/windows
6565
- name: Build
6666
run: |
67-
MSBuild -t:Rebuild -p:Configuration=Release -p:Platform=x64 ReactTestApp.sln
67+
MSBuild -t:Rebuild -p:Configuration=Release -p:Platform=x64 -p:BundleEntryFile=index.ts ReactTestApp.sln
6868
working-directory: example/windows

example/App.js

Lines changed: 0 additions & 167 deletions
This file was deleted.

example/App.tsx

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
8+
import React, { useCallback, useState } from 'react';
9+
import {
10+
Button,
11+
Keyboard,
12+
SafeAreaView,
13+
StyleSheet,
14+
Text,
15+
TouchableOpacity,
16+
View
17+
} from 'react-native';
18+
import BasicExample from './examples/Basic';
19+
import GetSetClear from './examples/GetSetClear';
20+
import MergeItem from './examples/MergeItem';
21+
22+
const TESTS = {
23+
GetSetClear: {
24+
title: 'Simple Get/Set value',
25+
testId: 'get-set-clear',
26+
description: 'Store and retrieve persisted data',
27+
render() {
28+
return <GetSetClear />;
29+
},
30+
},
31+
MergeItem: {
32+
title: 'Merge item',
33+
testId: 'merge-item',
34+
description: 'Merge object with already stored data',
35+
render() {
36+
return <MergeItem />;
37+
},
38+
},
39+
Basic: {
40+
title: 'Basic',
41+
testId: 'basic',
42+
description: 'Basic functionality test',
43+
render() {
44+
return <BasicExample />;
45+
},
46+
},
47+
};
48+
49+
export default function App(): JSX.Element {
50+
const [iteration, setIteration] = useState(0);
51+
const [currentTest, setCurrentTest] = useState(TESTS.GetSetClear);
52+
53+
const dismissKeyboard = useCallback(() => Keyboard.dismiss(), []);
54+
const simulateRestart = useCallback(() => setIteration(iteration + 1), [iteration]);
55+
const testBasic = useCallback(() => setCurrentTest(TESTS.Basic), []);
56+
const testGetSetClear = useCallback(() => setCurrentTest(TESTS.GetSetClear), []);
57+
const testMergeItem = useCallback(() => setCurrentTest(TESTS.MergeItem), []);
58+
59+
return (
60+
<SafeAreaView style={styles.container}>
61+
<TouchableOpacity
62+
style={styles.closeKeyboardView}
63+
onPress={dismissKeyboard}
64+
testID="closeKeyboard"
65+
/>
66+
67+
<TouchableOpacity
68+
testID="restart_button"
69+
onPress={simulateRestart}
70+
style={styles.restartButton}
71+
activeOpacity={0.6}>
72+
<Text>Simulate Restart</Text>
73+
</TouchableOpacity>
74+
75+
<View style={styles.testPickerContainer}>
76+
<Button
77+
testID="testType_getSetClear"
78+
title="Get/Set/Clear"
79+
onPress={testGetSetClear}
80+
/>
81+
<Button
82+
testID="testType_mergeItem"
83+
title="Merge Item"
84+
onPress={testMergeItem}
85+
/>
86+
<Button
87+
title={TESTS.Basic.title}
88+
onPress={testBasic}
89+
/>
90+
</View>
91+
92+
<View
93+
testID={`example-${currentTest.testId}`}
94+
key={currentTest.title + iteration}
95+
style={styles.exampleContainer}>
96+
<Text style={styles.exampleTitle}>{currentTest.title}</Text>
97+
<Text style={styles.exampleDescription}>
98+
{currentTest.description}
99+
</Text>
100+
<View style={styles.exampleInnerContainer}>
101+
{currentTest.render()}
102+
</View>
103+
</View>
104+
</SafeAreaView>
105+
);
106+
}
107+
108+
const styles = StyleSheet.create({
109+
container: {
110+
flex: 1,
111+
backgroundColor: '#F5FCFF',
112+
padding: 8,
113+
},
114+
exampleContainer: {
115+
padding: 4,
116+
backgroundColor: '#FFF',
117+
borderColor: '#EEE',
118+
borderTopWidth: 1,
119+
borderBottomWidth: 1,
120+
flex: 1,
121+
},
122+
exampleTitle: {
123+
fontSize: 18,
124+
},
125+
exampleDescription: {
126+
color: '#333333',
127+
marginBottom: 16,
128+
},
129+
exampleInnerContainer: {
130+
borderColor: '#EEE',
131+
borderTopWidth: 1,
132+
paddingTop: 10,
133+
flex: 1,
134+
},
135+
restartButton: {
136+
padding: 6,
137+
borderRadius: 5,
138+
backgroundColor: '#F3F3F3',
139+
alignItems: 'center',
140+
justifyContent: 'center',
141+
alignSelf: 'flex-end',
142+
},
143+
closeKeyboardView: {
144+
width: 5,
145+
height: 5,
146+
},
147+
testPickerContainer: {
148+
flexDirection: 'row',
149+
flexWrap: 'wrap',
150+
},
151+
});

0 commit comments

Comments
 (0)