react-native-gesture-handler#Switch TypeScript Examples
The following examples show how to use
react-native-gesture-handler#Switch.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Sentry.tsx From jellyfin-audio-player with MIT License | 6 votes |
export default function Sentry() {
const defaultStyles = useDefaultStyles();
const [isReportingEnabled, setReporting] = useState(isSentryEnabled);
const [activeSections, setActiveSections] = useState<number[]>([]);
const toggleSwitch = () => setReporting(previousState => !previousState);
useEffect(() => {
setSentryStatus(isReportingEnabled);
});
return (
<Container>
<Text>{t('error-reporting-description')}</Text>
<Text />
<Text>{t('error-reporting-rationale')}</Text>
<SwitchContainer>
<Label>{t('error-reporting')}</Label>
<Switch value={isReportingEnabled} onValueChange={toggleSwitch} />
</SwitchContainer>
<Accordion
sections={questions}
renderHeader={renderHeader}
renderContent={renderContent}
activeSections={activeSections}
onChange={setActiveSections}
underlayColor={defaultStyles.activeBackground.backgroundColor}
/>
</Container>
);
}
Example #2
Source File: BluetoothSettings.tsx From hamagen-react-native with MIT License | 5 votes |
BluetoothSettings: FunctionComponent<Props> = ({ navigation }) => {
const { isRTL, strings: {
bluetoothSettings: { title, description, recommendation, BLEOn, BLEOff }
} } = useSelector<Store, LocaleReducer>(state => state.locale);
const { enableBle } = useSelector<Store, GeneralReducer>(state => state.general);
const switchValue: boolean = useMemo(() => {
switch (enableBle) {
case 'true':
return true;
case 'false':
case 'blocked':
case null:
default:
return false;
}
}, [enableBle]);
return (
<View style={styles.container}>
<HeaderButton onPress={navigation.goBack} />
<View style={{ alignItems: 'center', }}>
<Icon
width={106}
customStyles={{ marginBottom: 20 }}
source={require('../../../assets/onboarding/bluetoothBig.png')}
/>
<Text style={styles.title} bold>{title}</Text>
<Text style={styles.description}>{description}</Text>
<Text style={{ fontSize: 16, color: 'rgb(98,98,98)', lineHeight: 24, }} bold>{recommendation}</Text>
</View>
<View
style={[{
...BASIC_SHADOW_STYLES,
paddingVertical: IS_SMALL_SCREEN ? 16 : 24,
paddingHorizontal: IS_SMALL_SCREEN ? 8 : 16,
borderRadius: 13,
flexDirection: isRTL ? 'row-reverse' : 'row',
justifyContent: 'space-between',
alignItems: 'center'
}]}
>
<Text style={{ flex: 1, color: 'rgb(98,98,98)', textAlign: isRTL ? 'right' : 'left' }} bold>{enableBle ? BLEOn : BLEOff}</Text>
<Switch
thumbColor={switchValue ? MAIN_COLOR : WHITE}
trackColor={{ true: 'rgb(145,199,231)', false: 'rgb(190,190,190)' }}
ios_backgroundColor="rgb(190,190,190)"
style={{ [isRTL ? 'marginRight' : 'marginLeft']: 10 }}
value={switchValue}
onValueChange={() => {
switch (enableBle) {
case 'blocked':
navigation.replace('BluetoothDenied');
break;
case null:
navigation.replace('Bluetooth');
break;
case 'true':
case 'false':
default:
toggleBLEService(enableBle !== 'true');
}
}}
/>
</View>
</View>
);
}