Last active
May 19, 2021 16:58
-
-
Save enzomanuelmangano/eb50d340fa1d5428433a605f82535b66 to your computer and use it in GitHub Desktop.
Switch Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react'; | |
import { View, StyleSheet } from 'react-native'; | |
import { Switch } from 'react-native-gesture-handler'; | |
const Colors = { | |
dark: { | |
background: '#1E1E1E', | |
circle: '#252525', | |
text: '#F8F8F8', | |
}, | |
light: { | |
background: '#F8F8F8', | |
circle: '#FFF', | |
text: '#1E1E1E', | |
}, | |
}; | |
const SWITCH_TRACK_COLOR = { | |
true: 'rgba(256, 0, 256, 0.2)', | |
false: 'rgba(0,0,0,0.1)', | |
}; | |
type Theme = 'light' | 'dark'; | |
export default function App() { | |
const [theme, setTheme] = useState<Theme>('light'); | |
return ( | |
<View style={styles.container}> | |
<Switch | |
value={theme === 'dark'} | |
onValueChange={(toggled) => { | |
setTheme(toggled ? 'dark' : 'light'); | |
}} | |
trackColor={SWITCH_TRACK_COLOR} | |
thumbColor={'violet'} | |
/> | |
</View> | |
); | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
alignItems: 'center', | |
justifyContent: 'center', | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment