From bfb93bc0a133a6a1ce01bd335330b88bd9c9e489 Mon Sep 17 00:00:00 2001 From: Juchan Roh Date: Sun, 5 Feb 2023 01:29:06 +0900 Subject: [PATCH] refactor: rewriting app.js with typescript --- App.js | 76 --------------------------------------------------------- App.tsx | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 76 deletions(-) delete mode 100644 App.js create mode 100644 App.tsx diff --git a/App.js b/App.js deleted file mode 100644 index ce2b378..0000000 --- a/App.js +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Sample React Native App - * https://github.com/facebook/react-native - * - * @format - */ - -import React from 'react'; -import {createAppContainer} from 'react-navigation'; -import {createStackNavigator} from 'react-navigation-stack'; - -import MainScreen from './src/screen/MainScreen'; -import CardEditScreen from './src/screen/CardEditScreen'; - -import * as RNLocalize from 'react-native-localize'; -import i18n from 'i18n-js'; -import en from './src/locales/en'; -import ko from './src/locales/ko'; - -const MainNavigator = createStackNavigator( - { - Home: { - screen: MainScreen, - navigationOptions: {headerShown: false}, - }, - CardEditScreen: { - screen: CardEditScreen, - navigationOptions: {headerShown: false}, - }, - }, - { - initialRouteName: 'Home', - }, -); - -const AppContainer = createAppContainer(MainNavigator); - -const setI18nConfig = () => { - const fallback = {languageTag: 'en'}; - const {languageTag} = - RNLocalize.findBestAvailableLanguage(['en', 'ko']) || fallback; - - i18n.translations = { - en, - ko, - }; - i18n.locale = languageTag; -}; - -export default class App extends React.Component { - constructor(props) { - super(props); - setI18nConfig(); - } - - componentDidMount() { - RNLocalize.addEventListener('change', this.handleLocalizationChange); - } - - componentWillUnmount() { - RNLocalize.removeEventListener('change', this.handleLocalizationChange); - } - - handleLocalizationChange = () => { - setI18nConfig(); - this.forceUpdate(); - }; - - render() { - return ( - <> - - - ); - } -} diff --git a/App.tsx b/App.tsx new file mode 100644 index 0000000..1ada318 --- /dev/null +++ b/App.tsx @@ -0,0 +1,72 @@ +/** + * Sample React Native App + * https://github.com/facebook/react-native + * + * @format + */ + +import React from 'react'; + +import MainScreen from './src/screens/MainScreen'; +// import CardEditScreen from './src/screens/CardEditScreen'; + +import { NavigationContainer } from '@react-navigation/native'; +import { createNativeStackNavigator } from '@react-navigation/native-stack'; + +const Stack = createNativeStackNavigator(); + +const App = () => { + return ( + + + + {/**/} + + + ); +}; + +export default App; + +/* +export default class App extends React.Component { + constructor(props) { + super(props); + setI18nConfig(); + } + + componentDidMount() { + RNLocalize.addEventListener('change', this.handleLocalizationChange); + } + + componentWillUnmount() { + RNLocalize.removeEventListener('change', this.handleLocalizationChange); + } + + handleLocalizationChange = () => { + setI18nConfig(); + this.forceUpdate(); + }; + + render() { + return ( + <> + + + ); + } +} +*/