1
0
mirror of synced 2024-11-24 07:10:15 +01:00
eAMEMu_RN/App.js

77 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-02-11 15:44:17 +01:00
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
*/
import React from 'react';
2023-02-04 12:41:11 +01:00
import {createAppContainer} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
2020-05-27 18:37:15 +02:00
2020-02-11 15:44:17 +01:00
import MainScreen from './src/screen/MainScreen';
import CardEditScreen from './src/screen/CardEditScreen';
2020-05-27 18:37:15 +02:00
import * as RNLocalize from 'react-native-localize';
import i18n from 'i18n-js';
import en from './src/locales/en';
import ko from './src/locales/ko';
2023-02-04 12:41:11 +01:00
const MainNavigator = createStackNavigator(
{
Home: {
screen: MainScreen,
navigationOptions: {headerShown: false},
},
CardEditScreen: {
screen: CardEditScreen,
navigationOptions: {headerShown: false},
},
2020-02-11 15:44:17 +01:00
},
2023-02-04 12:41:11 +01:00
{
initialRouteName: 'Home',
2020-02-11 15:44:17 +01:00
},
2020-05-27 18:37:15 +02:00
);
2020-02-11 15:44:17 +01:00
const AppContainer = createAppContainer(MainNavigator);
2020-05-27 18:37:15 +02:00
const setI18nConfig = () => {
2023-02-04 12:41:11 +01:00
const fallback = {languageTag: 'en'};
const {languageTag} =
RNLocalize.findBestAvailableLanguage(['en', 'ko']) || fallback;
2020-05-27 18:37:15 +02:00
i18n.translations = {
2023-02-04 12:41:11 +01:00
en,
ko,
2020-05-27 18:37:15 +02:00
};
i18n.locale = languageTag;
2020-02-11 15:44:17 +01:00
};
2023-02-04 12:41:11 +01:00
export default class App extends React.Component {
constructor(props) {
super(props);
setI18nConfig();
}
2020-05-27 18:37:15 +02:00
2023-02-04 12:41:11 +01:00
componentDidMount() {
RNLocalize.addEventListener('change', this.handleLocalizationChange);
}
2020-05-27 18:37:15 +02:00
2023-02-04 12:41:11 +01:00
componentWillUnmount() {
RNLocalize.removeEventListener('change', this.handleLocalizationChange);
}
2020-05-27 18:37:15 +02:00
2023-02-04 12:41:11 +01:00
handleLocalizationChange = () => {
setI18nConfig();
this.forceUpdate();
};
2020-05-27 18:37:15 +02:00
2023-02-04 12:41:11 +01:00
render() {
return (
<>
<AppContainer />
</>
);
}
}