components#LanguageToggle TypeScript Examples
The following examples show how to use
components#LanguageToggle.
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: Onboarding.tsx From mobile with Apache License 2.0 | 4 votes |
OnboardingScreen = () => {
const [i18n] = useI18n();
const [currentIndex, setCurrentIndex] = useState(0);
const carouselRef = useRef(null);
const {setOnboarded} = useStorage();
const navigation = useNavigation();
const startExposureNotificationService = useStartExposureNotificationService();
const handlePermissions = useCallback(async () => {
setOnboarded(true);
navigation.reset({
index: 0,
routes: [{name: 'Home'}],
});
await startExposureNotificationService();
}, [navigation, setOnboarded, startExposureNotificationService]);
const maxWidth = useMaxContentWidth();
const renderItem = useCallback(
({item}: {item: ViewKey}) => {
const ItemComponent = viewComponents[item];
return (
<Box maxWidth={maxWidth} alignSelf="center">
<ItemComponent />
</Box>
);
},
[maxWidth],
);
const nextItem = useCallback(() => {
if (carouselRef.current) {
if (currentIndex === contentData.length - 1) {
handlePermissions();
return;
}
(carouselRef.current! as CarouselStatic<ViewKey>).snapToNext();
}
}, [currentIndex, handlePermissions]);
const prevItem = useCallback(() => {
if (carouselRef.current) {
(carouselRef.current! as CarouselStatic<ViewKey>).snapToPrev();
}
}, []);
const isStart = currentIndex === 0;
const isEnd = currentIndex === contentData.length - 1;
const BackButton = <Button text={i18n.translate('Onboarding.ActionBack')} variant="subduedText" onPress={prevItem} />;
const LanguageButton = <LanguageToggle />;
const [layout, setLayout] = useState<LayoutRectangle | undefined>();
const onLayout = useCallback(({nativeEvent: {layout}}: LayoutChangeEvent) => {
setLayout(layout);
}, []);
return (
<Box flex={1} backgroundColor="overlayBackground">
<SafeAreaView style={styles.flex}>
<Header isOverlay />
<Box flex={1} justifyContent="center" onLayout={onLayout}>
{layout && (
<Carousel
ref={carouselRef}
data={contentData}
renderItem={renderItem}
sliderWidth={layout.width}
itemWidth={layout.width}
itemHeight={layout.height}
onSnapToItem={newIndex => setCurrentIndex(newIndex)}
/>
)}
</Box>
<Box flexDirection="row" padding="l">
<Box flex={1}>{isStart ? LanguageButton : BackButton}</Box>
<Box flex={1} justifyContent="center">
<ProgressCircles alignSelf="center" numberOfSteps={contentData.length} activeStep={currentIndex + 1} />
</Box>
<Box flex={1}>
<Button
text={i18n.translate(`Onboarding.Action${isEnd ? 'End' : 'Next'}`)}
variant="text"
onPress={nextItem}
/>
</Box>
</Box>
</SafeAreaView>
</Box>
);
}
Example #2
Source File: TestScreen.tsx From mobile with Apache License 2.0 | 4 votes |
Content = () => {
const i18n = useI18n();
const {reset} = useStorage();
const onShowSampleNotification = useCallback(() => {
PushNotification.presentLocalNotification({
alertTitle: i18n.translate('Notification.ExposedMessageTitle'),
alertBody: i18n.translate('Notification.ExposedMessageBody'),
});
}, [i18n]);
const exposureNotificationService = useExposureNotificationService();
const updateExposureStatus = useUpdateExposureStatus();
const {fetchAndSubmitKeys} = useReportDiagnosis();
const [UUID, setUUID] = useState('');
const onApplyUUID = useCallback(() => {
setLogUUID(UUID);
}, [UUID]);
useEffect(() => {
(async () => {
setUUID(await getLogUUID());
})();
}, []);
return (
<Box marginHorizontal="m">
<Section>
<Text paddingLeft="m" paddingRight="m" fontWeight="bold" paddingBottom="s" color="overlayBodyText">
Demo menu
</Text>
</Section>
<Section>
<Button text="Show sample notification" onPress={onShowSampleNotification} variant="bigFlat" />
</Section>
<Section>
<Item title="Force screen" />
<ScreenRadioSelector />
</Section>
<Section>
<Item title="Skip 'You're all set'" />
<SkipAllSetRadioSelector />
</Section>
<Section>
<Item title="UUID for debugging" />
<Box flexDirection="row">
<TextInput style={styles.uuidTextInput} placeholder="UUID..." value={UUID} onChangeText={setUUID} />
<Button variant="thinFlat" text="Apply" onPress={onApplyUUID} />
</Box>
</Section>
<Section>
<Button
text="Force upload keys"
variant="bigFlat"
onPress={async () => {
captureMessage('Force upload keys');
fetchAndSubmitKeys({dateType: ContagiousDateType.None, date: null});
}}
/>
</Section>
<Section>
<Button
text="Clear exposure history"
variant="bigFlat"
onPress={async () => {
captureMessage('Clear exposure history');
exposureNotificationService.exposureStatusUpdatePromise = null;
exposureNotificationService.exposureStatus.set({type: ExposureStatusType.Monitoring});
}}
/>
</Section>
<Section>
<Button
text="Force exposure check"
variant="bigFlat"
onPress={async () => {
captureMessage('Forcing Exposure Check');
updateExposureStatus(true);
}}
/>
</Section>
<Section>
<LanguageToggle />
</Section>
<Section>
<Button text="Clear data" onPress={reset} variant="danger50Flat" />
</Section>
<Section>
<Item title={`Version: ${APP_VERSION_NAME} (${APP_VERSION_CODE})`} />
</Section>
</Box>
);
}