|
8 | 8 | * @format |
9 | 9 | */ |
10 | 10 |
|
11 | | -import React from 'react'; |
12 | | -import { |
13 | | - SafeAreaView, |
14 | | - StyleSheet, |
15 | | - ScrollView, |
16 | | - View, |
17 | | - Text, |
18 | | - StatusBar, |
19 | | -} from 'react-native'; |
| 11 | + import React from 'react'; |
| 12 | + import type {Node} from 'react'; |
| 13 | + import { |
| 14 | + SafeAreaView, |
| 15 | + ScrollView, |
| 16 | + StatusBar, |
| 17 | + StyleSheet, |
| 18 | + Text, |
| 19 | + useColorScheme, |
| 20 | + View, |
| 21 | + } from 'react-native'; |
20 | 22 |
|
21 | | -import { |
22 | | - Header, |
23 | | - LearnMoreLinks, |
24 | | - Colors, |
25 | | - DebugInstructions, |
26 | | - ReloadInstructions, |
27 | | -} from 'react-native/Libraries/NewAppScreen'; |
| 23 | + import { |
| 24 | + Colors, |
| 25 | + DebugInstructions, |
| 26 | + Header, |
| 27 | + LearnMoreLinks, |
| 28 | + ReloadInstructions, |
| 29 | + } from 'react-native/Libraries/NewAppScreen'; |
28 | 30 |
|
29 | | -declare const global: {HermesInternal: null | {}}; |
| 31 | + const Section = ({children, title}): Node => { |
| 32 | + const isDarkMode = useColorScheme() === 'dark'; |
| 33 | + return ( |
| 34 | + <View style={styles.sectionContainer}> |
| 35 | + <Text |
| 36 | + style={[ |
| 37 | + styles.sectionTitle, |
| 38 | + { |
| 39 | + color: isDarkMode ? Colors.white : Colors.black, |
| 40 | + }, |
| 41 | + ]}> |
| 42 | + {title} |
| 43 | + </Text> |
| 44 | + <Text |
| 45 | + style={[ |
| 46 | + styles.sectionDescription, |
| 47 | + { |
| 48 | + color: isDarkMode ? Colors.light : Colors.dark, |
| 49 | + }, |
| 50 | + ]}> |
| 51 | + {children} |
| 52 | + </Text> |
| 53 | + </View> |
| 54 | + ); |
| 55 | + }; |
30 | 56 |
|
31 | | -const App = () => { |
32 | | - return ( |
33 | | - <> |
34 | | - <StatusBar barStyle="dark-content" /> |
35 | | - <SafeAreaView> |
36 | | - <ScrollView |
37 | | - contentInsetAdjustmentBehavior="automatic" |
38 | | - style={styles.scrollView}> |
39 | | - <Header /> |
40 | | - {global.HermesInternal == null ? null : ( |
41 | | - <View style={styles.engine}> |
42 | | - <Text style={styles.footer}>Engine: Hermes</Text> |
43 | | - </View> |
44 | | - )} |
45 | | - <View style={styles.body}> |
46 | | - <View style={styles.sectionContainer}> |
47 | | - <Text style={styles.sectionTitle}>Step One</Text> |
48 | | - <Text style={styles.sectionDescription}> |
49 | | - Edit <Text style={styles.highlight}>App.tsx</Text> to change this |
50 | | - screen and then come back to see your edits. |
51 | | - </Text> |
52 | | - </View> |
53 | | - <View style={styles.sectionContainer}> |
54 | | - <Text style={styles.sectionTitle}>See Your Changes</Text> |
55 | | - <Text style={styles.sectionDescription}> |
56 | | - <ReloadInstructions /> |
57 | | - </Text> |
58 | | - </View> |
59 | | - <View style={styles.sectionContainer}> |
60 | | - <Text style={styles.sectionTitle}>Debug</Text> |
61 | | - <Text style={styles.sectionDescription}> |
62 | | - <DebugInstructions /> |
63 | | - </Text> |
64 | | - </View> |
65 | | - <View style={styles.sectionContainer}> |
66 | | - <Text style={styles.sectionTitle}>Learn More</Text> |
67 | | - <Text style={styles.sectionDescription}> |
68 | | - Read the docs to discover what to do next: |
69 | | - </Text> |
70 | | - </View> |
71 | | - <LearnMoreLinks /> |
72 | | - </View> |
73 | | - </ScrollView> |
74 | | - </SafeAreaView> |
75 | | - </> |
76 | | - ); |
77 | | -}; |
| 57 | + const App: () => Node = () => { |
| 58 | + const isDarkMode = useColorScheme() === 'dark'; |
78 | 59 |
|
79 | | -const styles = StyleSheet.create({ |
80 | | - scrollView: { |
81 | | - backgroundColor: Colors.lighter, |
82 | | - }, |
83 | | - engine: { |
84 | | - position: 'absolute', |
85 | | - right: 0, |
86 | | - }, |
87 | | - body: { |
88 | | - backgroundColor: Colors.white, |
89 | | - }, |
90 | | - sectionContainer: { |
91 | | - marginTop: 32, |
92 | | - paddingHorizontal: 24, |
93 | | - }, |
94 | | - sectionTitle: { |
95 | | - fontSize: 24, |
96 | | - fontWeight: '600', |
97 | | - color: Colors.black, |
98 | | - }, |
99 | | - sectionDescription: { |
100 | | - marginTop: 8, |
101 | | - fontSize: 18, |
102 | | - fontWeight: '400', |
103 | | - color: Colors.dark, |
104 | | - }, |
105 | | - highlight: { |
106 | | - fontWeight: '700', |
107 | | - }, |
108 | | - footer: { |
109 | | - color: Colors.dark, |
110 | | - fontSize: 12, |
111 | | - fontWeight: '600', |
112 | | - padding: 4, |
113 | | - paddingRight: 12, |
114 | | - textAlign: 'right', |
115 | | - }, |
116 | | -}); |
| 60 | + const backgroundStyle = { |
| 61 | + backgroundColor: isDarkMode ? Colors.darker : Colors.lighter, |
| 62 | + }; |
117 | 63 |
|
118 | | -export default App; |
| 64 | + return ( |
| 65 | + <SafeAreaView style={backgroundStyle}> |
| 66 | + <StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} /> |
| 67 | + <ScrollView |
| 68 | + contentInsetAdjustmentBehavior="automatic" |
| 69 | + style={backgroundStyle}> |
| 70 | + <Header /> |
| 71 | + <View |
| 72 | + style={{ |
| 73 | + backgroundColor: isDarkMode ? Colors.black : Colors.white, |
| 74 | + }}> |
| 75 | + <Section title="Step One"> |
| 76 | + Edit <Text style={styles.highlight}>App.js</Text> to change this |
| 77 | + screen and then come back to see your edits. |
| 78 | + </Section> |
| 79 | + <Section title="See Your Changes"> |
| 80 | + <ReloadInstructions /> |
| 81 | + </Section> |
| 82 | + <Section title="Debug"> |
| 83 | + <DebugInstructions /> |
| 84 | + </Section> |
| 85 | + <Section title="Learn More"> |
| 86 | + Read the docs to discover what to do next: |
| 87 | + </Section> |
| 88 | + <LearnMoreLinks /> |
| 89 | + </View> |
| 90 | + </ScrollView> |
| 91 | + </SafeAreaView> |
| 92 | + ); |
| 93 | + }; |
| 94 | + |
| 95 | + const styles = StyleSheet.create({ |
| 96 | + sectionContainer: { |
| 97 | + marginTop: 32, |
| 98 | + paddingHorizontal: 24, |
| 99 | + }, |
| 100 | + sectionTitle: { |
| 101 | + fontSize: 24, |
| 102 | + fontWeight: '600', |
| 103 | + }, |
| 104 | + sectionDescription: { |
| 105 | + marginTop: 8, |
| 106 | + fontSize: 18, |
| 107 | + fontWeight: '400', |
| 108 | + }, |
| 109 | + highlight: { |
| 110 | + fontWeight: '700', |
| 111 | + }, |
| 112 | + }); |
| 113 | + |
| 114 | + export default App; |
0 commit comments