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