-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #289 from adrianxx321/ImplementLanguageSwitching
Implement language switching
- Loading branch information
Showing
40 changed files
with
599 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
app/screens/Languages/LanguagesScreen.navigationOptions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from "react"; | ||
import { StackNavigationOptions } from "@react-navigation/stack"; | ||
|
||
import { Text } from "components"; | ||
import { t } from "utils"; | ||
import { Colors, ComponentsStyle } from "style"; | ||
|
||
const navigationOptions = (): StackNavigationOptions => ({ | ||
...ComponentsStyle.transitionBetweenScreenPresets, | ||
headerStyle: { | ||
...ComponentsStyle.header, | ||
}, | ||
headerBackTitleVisible: false, | ||
headerTintColor: Colors.grey100, | ||
headerTitle: () => <Text.H1>{t("LANGUAGES_SCREEN_TITLE")}</Text.H1>, | ||
}); | ||
|
||
export default navigationOptions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { StyleSheet } from "react-native"; | ||
|
||
import { Layout } from "style"; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
...Layout.containerWithPadding, | ||
}, | ||
}); | ||
|
||
export default styles; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React, { useCallback, useContext } from "react"; | ||
import { View, ScrollView } from "react-native"; | ||
import { useDispatch } from "react-redux"; | ||
|
||
import { SelectableListItem } from "components"; | ||
import { userPreferences } from "ducks"; | ||
import { LocalizationContext, supportedLanguages } from "utils"; | ||
|
||
import navigationOptions from "./LanguagesScreen.navigationOptions"; | ||
import styles from "./LanguagesScreen.styles"; | ||
|
||
const Language: React.FC<{ | ||
selectedLanguage: string; | ||
language: string; | ||
onSelectLanguage: (language: string) => void; | ||
}> = ({ language, onSelectLanguage, selectedLanguage }) => { | ||
const onClickLanguage = useCallback(() => { | ||
onSelectLanguage?.(language); | ||
}, [language, onSelectLanguage]); | ||
|
||
return ( | ||
<SelectableListItem | ||
key={language} | ||
selected={selectedLanguage === language} | ||
title={supportedLanguages[language]} | ||
onPress={onClickLanguage} | ||
/> | ||
); | ||
}; | ||
|
||
const LanguagesScreen = () => { | ||
const dispatch = useDispatch(); | ||
const { language, setLanguage } = useContext(LocalizationContext); | ||
const onPress = useCallback( | ||
(lang: string) => { | ||
dispatch(userPreferences.actions.changeLanguage(lang)); | ||
setLanguage(lang); | ||
}, | ||
[dispatch, setLanguage] | ||
); | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<ScrollView> | ||
{Object.keys(supportedLanguages).map((lang: string) => ( | ||
<Language | ||
key={lang} | ||
selectedLanguage={language} | ||
language={lang} | ||
onSelectLanguage={onPress} | ||
/> | ||
))} | ||
</ScrollView> | ||
</View> | ||
); | ||
}; | ||
|
||
LanguagesScreen.navigationOptions = navigationOptions; | ||
|
||
export default LanguagesScreen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from "react"; | ||
import { create } from "react-test-renderer"; | ||
|
||
import LanguagesScreen from "../LanguagesScreen"; | ||
|
||
// jest.unmock("../"); | ||
|
||
it("LanguageScreen renders correctly", () => { | ||
const tree = create(<LanguagesScreen />).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); |
Oops, something went wrong.