|
|
@@ -1,5 +1,5 @@
|
|
|
-import React from 'react';
|
|
|
-import { View, Text, TouchableOpacity, StyleSheet, Alert } from 'react-native';
|
|
|
+import React, {useEffect, useState} from 'react';
|
|
|
+import { View, Text, TouchableOpacity, StyleSheet, Alert, Switch } from 'react-native';
|
|
|
import { useTranslation } from '../../../../util/hooks/useTranslation';
|
|
|
import { Language } from '../../../../i18n/types';
|
|
|
|
|
|
@@ -13,58 +13,52 @@ const LanguageSwitcher: React.FC = () => {
|
|
|
|
|
|
const languages = getSupportedLanguages();
|
|
|
const currentLanguage = getCurrentLanguageConfig();
|
|
|
+
|
|
|
+ const [isEnabled, setIsEnabled] = useState<boolean>(false);
|
|
|
+ useEffect(() => {
|
|
|
+ console.log('currentLanguage....', currentLanguage);
|
|
|
+ const init = async () => {
|
|
|
+ const aa = await currentLanguage?.value || false;
|
|
|
+ setIsEnabled(aa);
|
|
|
+ };
|
|
|
+ init();
|
|
|
+ }, [currentLanguage]);
|
|
|
|
|
|
- const handleLanguageChange = (language: Language) => {
|
|
|
- Alert.alert(
|
|
|
- format('common.confirm'),
|
|
|
- `${format('settings.language')}: ${languages.find(lang => lang.code === language)?.nativeName}`,
|
|
|
- [
|
|
|
- { text: format('common.cancel'), style: 'cancel' },
|
|
|
- {
|
|
|
- text: format('common.confirm'),
|
|
|
- onPress: () => switchLanguage(language)
|
|
|
- },
|
|
|
- ]
|
|
|
- );
|
|
|
+ const handleLanguageChange = async (newValue: boolean) => {
|
|
|
+ if (newValue) {
|
|
|
+ await switchLanguage('zh-TW');
|
|
|
+ } else {
|
|
|
+ await switchLanguage('en');
|
|
|
+ }
|
|
|
+ await setIsEnabled(newValue);
|
|
|
};
|
|
|
|
|
|
return (
|
|
|
<View style={styles.container}>
|
|
|
- <Text style={styles.title}>{format('settings.language')}</Text>
|
|
|
- <View style={styles.languageList}>
|
|
|
- {languages.map(language => (
|
|
|
- <TouchableOpacity
|
|
|
- key={language.code}
|
|
|
- style={[
|
|
|
- styles.languageItem,
|
|
|
- currentLanguage?.code === language.code && styles.selectedLanguage
|
|
|
- ]}
|
|
|
- onPress={() => handleLanguageChange(language.code)}
|
|
|
- >
|
|
|
- <Text style={[
|
|
|
- styles.languageText,
|
|
|
- currentLanguage?.code === language.code && styles.selectedLanguageText
|
|
|
- ]}>
|
|
|
- {language.nativeName}
|
|
|
- </Text>
|
|
|
- {currentLanguage?.code === language.code && (
|
|
|
- <Text style={styles.selectedIndicator}>✓</Text>
|
|
|
- )}
|
|
|
- </TouchableOpacity>
|
|
|
- ))}
|
|
|
- </View>
|
|
|
+ <Text style={styles.title}>En</Text>
|
|
|
+ <Switch
|
|
|
+ trackColor={{ false: "#cccccc", true: "#02677D" }}
|
|
|
+ thumbColor={isEnabled ? "#ffffff" : "#f4f3f4"}
|
|
|
+ onValueChange={handleLanguageChange}
|
|
|
+ value={isEnabled}
|
|
|
+ />
|
|
|
+ <Text style={styles.title}>繁</Text>
|
|
|
</View>
|
|
|
);
|
|
|
};
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
container: {
|
|
|
- padding: 16,
|
|
|
+ flexDirection: 'row',
|
|
|
+ alignItems: 'center',
|
|
|
+ marginTop: 10,
|
|
|
+ marginLeft: 10,
|
|
|
},
|
|
|
title: {
|
|
|
+ color: '#333333',
|
|
|
+ marginRight: 5,
|
|
|
+ marginLeft: 5,
|
|
|
fontSize: 18,
|
|
|
- fontWeight: 'bold',
|
|
|
- marginBottom: 12,
|
|
|
},
|
|
|
languageList: {
|
|
|
backgroundColor: '#f5f5f5',
|