I want to use the colors from my react native paper theme inside the stylesheet create function inside my component. Here's my code
import { StyleSheet, Text, View } from 'react-native';
import { useTheme } from 'react-native-paper';
const Home = () => {
const { colors } = useTheme();
return (
<View style={[styles.container, { backgroundColor: colors.background }]}>
<Text>Home Page</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
export default Home;
I want to have the backgroundColor: "#fff" in the stylesheet to reference the colors.background coming from the useTheme hook. Is this possible?
I prefer to use it like this
const makeStyles = (colors: any) => StyleSheet.create({
container: {
backgroundColor: colors.red,
}
})
then, in render()
const Home = () => {
const { colors } = useTheme();
const styles = makeStyles(colors)
return (
<View style={[styles.container, { backgroundColor: colors.background }]}>
<Text>Home Page</Text>
</View>
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With