React native app in dark and light mode
import React from 'react';
import { SafeAreaView, View, Text, StyleSheet, useColorScheme} from 'react-native';
function AppPro():JSX.Element {
const isDarkMode = useColorScheme() === 'dark';
return (
<View style={isDarkMode ? styles.darkContainer : styles.container}>
<Text style={isDarkMode ? styles.whiteText : styles.darkText }>Hello</Text>
</View>
);
}
const styles = StyleSheet.create({
container:{
flex:1,
alignItems:'center',
//backgroundColor:'grey',
},
darkContainer:{
backgroundColor:'grey',
flex:1,
},
whiteText:{
color:'white',
},
darkText:{
color:'black',
},
});
useColorScheme() === ‘dark’ returns boolean value true when dark mode is enabled in device’s settings.