48
loading...
This website collects cookies to deliver better user experience
Here are some of the features:
Example of how it works with Text:
const DemoComponent = () => {
<Text style={DEMO_TEXT}>Hey, I am normal text</Text>
}
const DEMO_TEXT: TextStyle = {
fontWeight: 'bold',
fontSize: 14,
color: 'white'
}
const DemoComponent = () => {
<Text style={apply(DEMO_TEXT)}>Hey, I am themed text</Text>
}
const DEMO_TEXT: TTextStyle = {
fontWeight: 'bold',
fontSize: 14,
color: 'white',
colorDark: 'black'
}
Changes:
import {
appearanceHook,
apply,
StyleSheet
} from '@theme'
const DemoComponent = () => {
// theme state
const [theme, setTheme] = useState(appearanceHook.activeTheme)
// theme toggle fun
const toggleTheme = useCallback(async () => {
appearanceHook.switch(appearanceHook.activeTheme === 'dark' ? 'light' : 'dark')
setTheme(theme === 'dark' ? 'light' : 'dark')
}, [appearanceHook.activeTheme])
return (
// button toggle
<Button
text={'Switch theme'}
onPress={toggleTheme}
/>
// themed text with StyleSheet
<Text style={apply(styles.DEMO_TEXT_THEMED)}>Hey, I am themed text</Text>
// normal text with StyleSheet
<Text style={styles.DEMO_TEXT_NORMAL}>Hey, I am normal text</Text>
)}
const styles = StyleSheet.create({
DEMO_TEXT_THEMED: {
fontWeight: 'bold',
fontSize: 14,
color: 'white',
colorDark: 'black'
},
DEMO_TEXT_NORMAL: {
fontWeight: 'bold',
fontSize: 14,
color: 'white',
}
})