Dark mode — light/dark theme support.
UseColorScheme hook:
1import { useColorScheme } from 'react-native';23function App() {4 const colorScheme = useColorScheme();5 const isDark = colorScheme === "dark";67 return (8 <View style={{9 backgroundColor: isDark ? "#000" : "#fff",10 }}>11 <Text style={{12 color: isDark ? "#fff" : "#000",13 }}>Hello</Text>14 </View>15 );16}
Custom theme provider:
1const themes = {2 light: { bg: "#fff", text: "#000" },3 dark: { bg: "#000", text: "#fff" },4};56const ThemeContext = createContext(themes.light);78function ThemeProvider({ children }) {9 const colorScheme = useColorScheme();10 const theme = themes[colorScheme ?? "light"];1112 return (13 <ThemeContext.Provider value={theme}>14 {children}15 </ThemeContext.Provider>16 );17}
With StatusBar:
1<StatusBar2 barStyle={isDark ? "light-content" : "dark-content"}3/>