Skip to content

Commit 9d3274b

Browse files
committed
feat(App): review safearea
1 parent 421e061 commit 9d3274b

5 files changed

Lines changed: 36 additions & 81 deletions

File tree

template/src/app/components/AppProvider.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, {FC, PropsWithChildren} from 'react';
22
import {NavigationProvider} from './NavigationProvider';
33
import {ThemeProvider} from './ThemeProvider';
4+
import {ThemedSafeAreaProvider} from './ThemedSafeAreaProvider';
45

56
type Props = React.ComponentProps<typeof ThemeProvider>;
67

@@ -10,7 +11,9 @@ export const AppProvider: FC<PropsWithChildren<Props>> = ({
1011
}) => {
1112
return (
1213
<ThemeProvider themeVariants={themeVariants}>
13-
<NavigationProvider>{children}</NavigationProvider>
14+
<ThemedSafeAreaProvider>
15+
<NavigationProvider>{children}</NavigationProvider>
16+
</ThemedSafeAreaProvider>
1417
</ThemeProvider>
1518
);
1619
};

template/src/app/components/ThemeProvider.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import {DefaultTheme} from '@react-navigation/native';
21
import React, {FC, PropsWithChildren, useMemo} from 'react';
3-
import {useColorScheme} from 'react-native';
2+
import {StatusBar, useColorScheme} from 'react-native';
3+
import {themeVariants as defaultThemeVariants} from '../themes';
44
import {Theme, ThemeVariants} from '../types/theme';
55

6-
export const ThemeContext = React.createContext<Theme>(DefaultTheme);
6+
export const ThemeContext = React.createContext<Theme>(
7+
defaultThemeVariants.light,
8+
);
79

810
type Props = {
911
themeVariants: ThemeVariants;
@@ -21,6 +23,9 @@ export const ThemeProvider: FC<PropsWithChildren<Props>> = ({
2123
);
2224

2325
return (
24-
<ThemeContext.Provider value={theme}>{children}</ThemeContext.Provider>
26+
<>
27+
<StatusBar barStyle={theme.statusBarStyle} />
28+
<ThemeContext.Provider value={theme}>{children}</ThemeContext.Provider>
29+
</>
2530
);
2631
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React, {FC, PropsWithChildren} from 'react';
2+
import {SafeAreaProvider} from 'react-native-safe-area-context';
3+
import useAppStyles, {StylesCallback} from '../hooks/useAppStyles';
4+
5+
const getStyles: StylesCallback = ({colors}) => ({
6+
safeArea: {
7+
backgroundColor: colors.background,
8+
},
9+
});
10+
11+
export const ThemedSafeAreaProvider: FC<PropsWithChildren> = ({children}) => {
12+
const styles = useAppStyles(getStyles);
13+
return (
14+
<SafeAreaProvider style={styles.safeArea}>{children}</SafeAreaProvider>
15+
);
16+
};

template/src/app/types/theme.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {Theme as NavigationTheme} from '@react-navigation/native';
2-
import {ColorSchemeName} from 'react-native';
2+
import {ColorSchemeName, StatusBarStyle} from 'react-native';
33

4-
export interface Theme extends NavigationTheme {}
4+
export interface Theme extends NavigationTheme {
5+
statusBarStyle: StatusBarStyle;
6+
}
57

68
type Colors = Pick<keyof ColorSchemeName, 'light' | 'dark'>;
79

template/src/app/views/App.tsx

Lines changed: 3 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -5,87 +5,16 @@
55
* @format
66
*/
77

8-
import type {PropsWithChildren} from 'react';
98
import React from 'react';
10-
import {
11-
SafeAreaView,
12-
StatusBar,
13-
StyleSheet,
14-
Text,
15-
useColorScheme,
16-
View,
17-
} from 'react-native';
189

19-
import {Colors} from 'react-native/Libraries/NewAppScreen';
2010
import {RootStackNavigator} from '../../navigation/components/RootStackNavigator';
2111
import {AppProvider} from '../components/AppProvider';
2212
import {themeVariants} from '../themes';
2313

24-
type SectionProps = PropsWithChildren<{
25-
title: string;
26-
}>;
27-
28-
function Section({children, title}: SectionProps): JSX.Element {
29-
const isDarkMode = useColorScheme() === 'dark';
30-
return (
31-
<View style={styles.sectionContainer}>
32-
<Text
33-
style={[
34-
styles.sectionTitle,
35-
{
36-
color: isDarkMode ? Colors.white : Colors.black,
37-
},
38-
]}>
39-
{title}
40-
</Text>
41-
<Text
42-
style={[
43-
styles.sectionDescription,
44-
{
45-
color: isDarkMode ? Colors.light : Colors.dark,
46-
},
47-
]}>
48-
{children}
49-
</Text>
50-
</View>
51-
);
52-
}
53-
5414
export function App(): JSX.Element {
55-
const isDarkMode = useColorScheme() === 'dark';
56-
57-
const backgroundStyle = {
58-
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
59-
};
60-
6115
return (
62-
<SafeAreaView style={[{flex: 1}, backgroundStyle]}>
63-
<AppProvider themeVariants={themeVariants}>
64-
<StatusBar
65-
barStyle={isDarkMode ? 'light-content' : 'dark-content'}
66-
backgroundColor={backgroundStyle.backgroundColor}
67-
/>
68-
<RootStackNavigator />
69-
</AppProvider>
70-
</SafeAreaView>
16+
<AppProvider themeVariants={themeVariants}>
17+
<RootStackNavigator />
18+
</AppProvider>
7119
);
7220
}
73-
74-
const styles = StyleSheet.create({
75-
sectionContainer: {
76-
marginTop: 32,
77-
paddingHorizontal: 24,
78-
},
79-
sectionTitle: {
80-
fontSize: 24,
81-
fontWeight: '600',
82-
},
83-
sectionDescription: {
84-
marginTop: 8,
85-
fontSize: 18,
86-
fontWeight: '400',
87-
},
88-
highlight: {
89-
fontWeight: '700',
90-
},
91-
});

0 commit comments

Comments
 (0)