kia-ml
Version:
Kia
115 lines (106 loc) • 4.42 kB
JavaScript
// import * as React from 'react';
// import { NavigationContainer } from '@react-navigation/native';
// import { createStackNavigator } from '@react-navigation/stack';
// import AsyncStorage from '@react-native-async-storage/async-storage';
// import HomeScreen from "./Containers/HomeScreen";
// import LibraryScreen from "./Containers/LibraryScreen";
// import type KiaAppProps from "./Config/KiaApp.props";
// import { asApiConfig } from "./Config/StorageKeys";
// import type ApiKeyType from './Api/ApiKeyType';
// const Stack = createStackNavigator();
// const linking = {
// prefixes: [],
// config: {
// screens: {
// Home: '',
// Library: 'library'
// }
// },
// };
// function KiaApp(props: KiaAppProps) {
// //to-do: check for platform before adding linking prop
// const { config } = props;
// console.log(config);
// const storeConfig = async (config: ApiKeyType) => {
// try {
// await AsyncStorage.setItem(asApiConfig, JSON.stringify(config));
// } catch (e) {
// // saving error
// }
// }
// storeConfig(config);
// return (
// <NavigationContainer linking={linking}>
// <Stack.Navigator initialRouteName="Home">
// <Stack.Screen name="Home" component={HomeScreen} />
// <Stack.Screen name="Library" component={LibraryScreen} />
// </Stack.Navigator>
// </NavigationContainer>
// );
// }
// export default KiaApp;
// // export default {
// // multiply(a: number, b: number) {
// // return Promise.resolve(a * b);
// // },
// // };
/**
* Welcome to the main entry point of the app. In this file, we'll
* be kicking off our app.
*
* Most of this file is boilerplate and you shouldn't need to modify
* it very often. But take some time to look through and understand
* what is going on here.
*
* The app navigation resides in ./app/navigators, so head over there
* if you're interested in adding screens and navigators.
*/
import React, { useState, useEffect, useRef } from 'react';
import { SafeAreaProvider, initialWindowMetrics } from 'react-native-safe-area-context';
import { initFonts } from './theme/fonts'; // expo
import * as storage from './utils/storage';
import { useBackButtonHandler, RootNavigator, canExit, setRootNavigation, useNavigationPersistence } from './navigators';
import { RootStoreProvider, setupRootStore } from './models'; // This puts screens in a native ViewController or Activity. If you want fully native
// stack navigation, use `createNativeStackNavigator` in place of `createStackNavigator`:
// https://github.com/kmagiera/react-native-screens#using-native-stack-navigator
import { enableScreens } from 'react-native-screens';
import { loadString, saveString } from './utils/storage';
import { asApiConfig } from './config/storage-keys';
enableScreens();
export const NAVIGATION_PERSISTENCE_KEY = 'NAVIGATION_STATE';
/**
* This is the root component of our app.
*/
function KiaApp(props) {
const navigationRef = useRef(null);
const [rootStore, setRootStore] = useState(undefined);
setRootNavigation(navigationRef);
useBackButtonHandler(navigationRef, canExit);
const {
initialNavigationState,
onNavigationStateChange
} = useNavigationPersistence(storage, NAVIGATION_PERSISTENCE_KEY); // Kick off initial async loading actions, like loading fonts and RootStore
useEffect(() => {
(async () => {
await initFonts(); // expo
if (props.config) await saveString(asApiConfig, JSON.stringify(props.config));
let apiConfig = await loadString(asApiConfig);
if (apiConfig) setupRootStore(JSON.parse(apiConfig)).then(setRootStore);
})();
}, []); // Before we show the app, we have to wait for our state to be ready.
// In the meantime, don't render anything. This will be the background
// color set in native by rootView's background color. You can replace
// with your own loading component if you wish.
if (!rootStore) return null; // otherwise, we're ready to render the app
return /*#__PURE__*/React.createElement(RootStoreProvider, {
value: rootStore
}, /*#__PURE__*/React.createElement(SafeAreaProvider, {
initialMetrics: initialWindowMetrics
}, /*#__PURE__*/React.createElement(RootNavigator, {
ref: navigationRef,
initialState: initialNavigationState,
onStateChange: onNavigationStateChange
})));
}
export default KiaApp;
//# sourceMappingURL=index.js.map