Skip to content

Instantly share code, notes, and snippets.

@enzomanuelmangano
Last active May 19, 2021 16:58
Show Gist options
  • Save enzomanuelmangano/eb50d340fa1d5428433a605f82535b66 to your computer and use it in GitHub Desktop.
Save enzomanuelmangano/eb50d340fa1d5428433a605f82535b66 to your computer and use it in GitHub Desktop.
Switch Component
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