BlueWallet/screen/settings/language.js

60 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-07-15 19:32:59 +02:00
import React, { useState, useEffect, useCallback } from 'react';
import { FlatList, StyleSheet } from 'react-native';
2020-11-22 09:04:04 +01:00
import { SafeBlueArea, BlueListItem, BlueCard, BlueLoadingHook, BlueNavigationStyle, BlueText } from '../../BlueComponents';
import { AvailableLanguages } from '../../loc/languages';
2020-07-20 15:38:46 +02:00
import loc from '../../loc';
2020-08-28 10:05:41 +02:00
const styles = StyleSheet.create({
flex: {
flex: 1,
},
});
2020-07-15 19:32:59 +02:00
const Language = () => {
const [isLoading, setIsLoading] = useState(true);
const [language, setLanguage] = useState(loc.getLanguage());
2020-07-15 19:32:59 +02:00
useEffect(() => {
setIsLoading(false);
}, []);
const renderItem = useCallback(
({ item }) => {
return (
2020-09-22 03:53:28 +02:00
<BlueListItem
2020-07-15 19:32:59 +02:00
onPress={() => {
console.log('setLanguage', item.value);
loc.saveLanguage(item.value);
setLanguage(item.value);
}}
title={item.label}
{...(language === item.value
? {
2020-09-22 03:53:28 +02:00
rightIcon: { name: 'check', type: 'octaicon', color: '#0070FF' },
2020-07-15 19:32:59 +02:00
}
: { hideChevron: true })}
/>
2020-07-15 19:32:59 +02:00
);
},
[language],
);
return isLoading ? (
<BlueLoadingHook />
) : (
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={styles.flex}>
<FlatList style={styles.flex} keyExtractor={(_item, index) => `${index}`} data={AvailableLanguages} renderItem={renderItem} />
<BlueCard>
2020-11-22 09:04:04 +01:00
<BlueText>{loc.settings.language_restart}</BlueText>
2020-07-15 19:32:59 +02:00
</BlueCard>
</SafeBlueArea>
);
};
2020-07-15 19:32:59 +02:00
Language.navigationOptions = () => ({
...BlueNavigationStyle(),
headerTitle: loc.settings.language,
});
export default Language;