{"size": 2094, "ext": "js", "max_stars_repo_path": "Github_RN/js/pages/CustomLanguagePage.js", "max_stars_repo_name": "zdq1179169386/ReactNativeStudy", "max_stars_repo_stars_event_min_datetime": "2020-08-07T19:31:56.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-07T19:31:56.000Z", "max_issues_repo_path": "Github_RN/js/pages/CustomLanguagePage.js", "max_issues_repo_name": "zdq1179169386/ReactNativeStudy", "max_issues_repo_issues_event_min_datetime": "2020-09-04T20:50:17.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-10T16:57:00.000Z", "max_forks_repo_path": "Github_RN/js/pages/CustomLanguagePage.js", "max_forks_repo_name": "zdq1179169386/ReactNativeStudy", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 23, "max_forks_count": null, "avg_line_length": 32.71875, "max_line_length": 123, "alphanum_fraction": 0.5439350525}
import React, {Component} from 'react';
import {
    StyleSheet,
    Text,
    View,
    Button, AsyncStorage
} from 'react-native';
import NavigationBar from '../common/NavigationBar'
import {selectLanguage, getRefreshHandler, LANGUAGE_SELECT, LANGUAGE_SELECT_NAME} from '../util/ActionUtil'
import {Actions} from "react-native-router-flux";
import * as ActionUtil from '../util/ActionUtil'
import {changeLocale} from "../util/i18n";
import ViewUtil from "../util/ViewUtil";
import Ii8n from "../util/i18n";


export default class CustomLanguagePage extends Component<Props> {
    render() {
        const {theme} = this.props;
        let statusBar = {
            backgroundColor: theme.themeColor,
            barStyle: 'light-content',
        }
        let navigationBar = <NavigationBar title={Ii8n('customLanguage')} style={theme.styles.navBar} statusBar={statusBar}
                                           leftBtn={ViewUtil.getLeftBackBtn(() => {
                                               Actions.pop()

                                           })}/>
        return (
            <View style={styles.container}>
                {navigationBar}
                <View style={styles.subcontainer}>
                    <Button title={'中文'} onPress={() => {
                       this.changeLanuage('zh-CN')
                    }}/>
                    <Button title={'english'} onPress={() => {
                        this.changeLanuage('en')
                    }}/>
                </View>
            </View>
        );
    }
    changeLanuage(lan) {
        changeLocale(lan);
        AsyncStorage.setItem(ActionUtil.LANGUAGE_SELECT, lan);
        Actions.refresh();
        let handler = getRefreshHandler();
        handler.get(ActionUtil.REFRESH_LANGUAGE) && handler.get(ActionUtil.REFRESH_LANGUAGE)();
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#F5FCFF',
    },
    subcontainer: {
        flex: 1,
        backgroundColor: '#F5FCFF',
        justifyContent: 'center',
        alignItems: 'center'
    }
});
