BlueWallet/screen/settings/language.js
2020-12-04 13:40:13 +00:00

60 lines
1.6 KiB
JavaScript

import React, { useState, useEffect, useCallback } from 'react';
import { FlatList, StyleSheet } from 'react-native';
import { SafeBlueArea, BlueListItem, BlueCard, BlueLoading, BlueNavigationStyle, BlueText } from '../../BlueComponents';
import { AvailableLanguages } from '../../loc/languages';
import loc from '../../loc';
const styles = StyleSheet.create({
flex: {
flex: 1,
},
});
const Language = () => {
const [isLoading, setIsLoading] = useState(true);
const [language, setLanguage] = useState(loc.getLanguage());
useEffect(() => {
setIsLoading(false);
}, []);
const renderItem = useCallback(
({ item }) => {
return (
<BlueListItem
onPress={() => {
console.log('setLanguage', item.value);
loc.saveLanguage(item.value);
setLanguage(item.value);
}}
title={item.label}
{...(language === item.value
? {
rightIcon: { name: 'check', type: 'octaicon', color: '#0070FF' },
}
: { hideChevron: true })}
/>
);
},
[language],
);
return isLoading ? (
<BlueLoading />
) : (
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={styles.flex}>
<FlatList style={styles.flex} keyExtractor={(_item, index) => `${index}`} data={AvailableLanguages} renderItem={renderItem} />
<BlueCard>
<BlueText>{loc.settings.language_restart}</BlueText>
</BlueCard>
</SafeBlueArea>
);
};
Language.navigationOptions = () => ({
...BlueNavigationStyle(),
headerTitle: loc.settings.language,
});
export default Language;