From 94f5f21909cf6ed220de9b0b47c2c4d5814a6ff4 Mon Sep 17 00:00:00 2001 From: souyahia-monk Date: Fri, 3 Nov 2023 17:35:06 +0100 Subject: [PATCH] Fixed the language dropdown --- package.json | 5 +- src/screens/Landing/LanguageSwitch/index.js | 86 ++++++++++++--------- 2 files changed, 53 insertions(+), 38 deletions(-) diff --git a/package.json b/package.json index 0c2dd0b45..791c4a57f 100644 --- a/package.json +++ b/package.json @@ -102,6 +102,7 @@ "react-i18next": "^11.18.0", "react-native": "0.64.3", "react-native-canvas": "^0.1.38", + "react-native-element-dropdown": "^2.10.0", "react-native-masked-text": "^1.13.0", "react-native-paper": "^4.12.0", "react-native-prompt-android": "^1.1.0", @@ -151,12 +152,12 @@ "peerDependencies": { "@monkvision/camera": "*", "@monkvision/corejs": "*", + "@monkvision/feedback": "*", + "@monkvision/inspection-report": "*", "@monkvision/sights": "*", "@monkvision/toolkit": "*", "@monkvision/ui": "*", "@monkvision/visualization": "*", - "@monkvision/inspection-report": "*", - "@monkvision/feedback": "*", "react-native-svg": "*" }, "resolutions": { diff --git a/src/screens/Landing/LanguageSwitch/index.js b/src/screens/Landing/LanguageSwitch/index.js index 1b5cc0ae7..016bb5729 100644 --- a/src/screens/Landing/LanguageSwitch/index.js +++ b/src/screens/Landing/LanguageSwitch/index.js @@ -1,53 +1,67 @@ +import { useMonitoring } from '@monkvision/corejs'; import AsyncStorage from '@react-native-async-storage/async-storage'; -import React, { useCallback, useState } from 'react'; +import React from 'react'; import { useTranslation } from 'react-i18next'; -import { ActivityIndicator, Button, Menu } from 'react-native-paper'; -import { useMonitoring } from '@monkvision/corejs'; +import { StyleSheet } from 'react-native'; +import { Dropdown } from 'react-native-element-dropdown'; export const ASYNC_STORAGE_LANG_KEY = '@lang_Storage'; +const options = [ + { label: 'πŸ‡¬πŸ‡§ English', value: 'en' }, + { label: 'πŸ‡«πŸ‡· French', value: 'fr' }, +]; + +const styles = StyleSheet.create({ + dropdown: { + margin: 16, + height: 50, + borderBottomColor: 'gray', + borderBottomWidth: 0.5, + cursor: 'pointer', + }, + selectedTextStyle: { + fontSize: 14, + color: '#efefef', + }, + iconStyle: { + width: 20, + height: 20, + }, + containerStyle: { + backgroundColor: '#313240', + color: '#efefef', + }, + itemTextStyle: { + color: '#efefef', + }, +}); + export default function LanguageSwitch() { - const [isLoading, setIsLoading] = useState(false); - const [visible, setVisible] = React.useState(false); const { errorHandler } = useMonitoring(); const { i18n } = useTranslation(); - const openMenu = () => setVisible(true); - const closeMenu = () => setVisible(false); - const setLanguage = (lng) => { - setIsLoading(true); - closeMenu(); i18n.changeLanguage(lng) .then(() => AsyncStorage.setItem(ASYNC_STORAGE_LANG_KEY, lng)) - .then(() => setIsLoading(false)) - .catch((err) => { - setIsLoading(false); - errorHandler(err); - }); + .catch((err) => errorHandler(err)); }; - const getButtonContent = useCallback(() => { - if (isLoading) { - return ; - } - const en = 'πŸ‡¬πŸ‡§ β–Ό'; - const fr = 'πŸ‡«πŸ‡· β–Ό'; - if (!i18n.language) { - setLanguage('en'); - return en; - } - return i18n.language.startsWith('fr') ? fr : en; - }, [isLoading, i18n.language]); - return ( - {getButtonContent()}} - > - setLanguage('en')} title="πŸ‡¬πŸ‡§ English" /> - setLanguage('fr')} title="πŸ‡«πŸ‡· FranΓ§ais" /> - + setLanguage(item.value)} + backgroundColor="#00000080" + /> ); }