App.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* eslint-disable import/no-named-default */
  2. /* eslint-disable react/destructuring-assignment */
  3. /* eslint-disable react/jsx-props-no-spreading */
  4. import * as React from "react";
  5. import * as eva from "@eva-design/eva";
  6. import {
  7. ApplicationProvider,
  8. Layout,
  9. IconRegistry,
  10. } from "@ui-kitten/components";
  11. import { Provider } from "@ant-design/react-native";
  12. import { ThemeProvider } from "react-native-magnus";
  13. import { EvaIconsPack } from "@ui-kitten/eva-icons";
  14. import { SplashScreen } from "expo";
  15. import * as Font from "expo-font";
  16. import { Ionicons } from "@expo/vector-icons";
  17. import { NavigationContainer, CommonActions } from "@react-navigation/native";
  18. import {
  19. createStackNavigator,
  20. CardStyleInterpolators,
  21. } from "@react-navigation/stack";
  22. import { useModel } from "flooks";
  23. import { useUpdateEffect, useMount } from "@umijs/hooks";
  24. // import { enableScreens } from "react-native-screens";
  25. // eslint-disable-next-line no-unused-vars
  26. import * as model from "./models";
  27. import { default as theme } from "./theme.json"; // <-- Import app theme
  28. import { default as customMapping } from "./mapping.json"; // <-- Import app theme
  29. import Matheme from "./constants/Theme";
  30. import Dialog from "./components/Dialog";
  31. import BottomTabNavigator from "./navigation/BottomTabNavigator";
  32. import LoginStackNavigator from "./navigation/LoginStackNavigator";
  33. import GuideScreens from "./navigation/GuideStackNavigator";
  34. import BasicScreens from "./navigation/BasicNavigator";
  35. import { navigationRef } from "./navigation/RootNavigation";
  36. // enableScreens();
  37. const Stack = createStackNavigator();
  38. const fontFile = require("./assets/fonts/SpaceMono-Regular.ttf");
  39. export default function App(props) {
  40. const [isLoadingComplete, setLoadingComplete] = React.useState(false);
  41. const { getWords, local } = useModel("wordsModel");
  42. const { clearLoading } = useModel("loadingModel", true);
  43. const {
  44. mid,
  45. guideStep,
  46. getUserInfo,
  47. checkNowGuideStep,
  48. setinitRoute,
  49. } = useModel("userModel");
  50. useMount(() => {
  51. SplashScreen.preventAutoHide();
  52. Font.loadAsync({
  53. ...Ionicons.font,
  54. "space-mono": fontFile,
  55. })
  56. .then(() => {
  57. return Font.loadAsync(
  58. "antoutline",
  59. // eslint-disable-next-line
  60. require("@ant-design/icons-react-native/fonts/antoutline.ttf")
  61. );
  62. })
  63. .then(() => {
  64. return Font.loadAsync(
  65. "antfill",
  66. // eslint-disable-next-line
  67. require("@ant-design/icons-react-native/fonts/antfill.ttf")
  68. );
  69. })
  70. .then(() => {
  71. return getUserInfo();
  72. })
  73. .catch(e => {
  74. console.log(e);
  75. });
  76. // .finally(() => {
  77. // setLoadingComplete(true);
  78. // SplashScreen.hide();
  79. // });
  80. });
  81. React.useEffect(() => {
  82. getWords();
  83. }, [local]);
  84. const [initRouteName, setInit] = React.useState("");
  85. useUpdateEffect(() => {
  86. if (mid === 0) {
  87. // 未登录
  88. setinitRoute("Login");
  89. setInit("Login");
  90. }
  91. // else if (__DEV__) {
  92. // setInit("GoodsDetailMore");
  93. // }
  94. else if (mid !== 0) {
  95. checkNowGuideStep();
  96. }
  97. }, [mid]);
  98. useUpdateEffect(() => {
  99. console.log(guideStep);
  100. switch (guideStep) {
  101. case "finish":
  102. setInit("Root");
  103. break;
  104. case "ComeBack":
  105. setinitRoute("RegisterSe");
  106. setInit("Login");
  107. break;
  108. case "1":
  109. setInit("Guide1");
  110. break;
  111. case "2":
  112. setInit("Guide2");
  113. break;
  114. case "3":
  115. setInit("Guide3");
  116. break;
  117. case "4":
  118. setInit("Guide4");
  119. break;
  120. case "5":
  121. setInit("StoreAudit");
  122. break;
  123. default:
  124. setInit("Login");
  125. break;
  126. }
  127. }, [guideStep]);
  128. useUpdateEffect(() => {
  129. if (!isLoadingComplete) {
  130. setLoadingComplete(true);
  131. SplashScreen.hide();
  132. } else {
  133. navigationRef.current.dispatch(
  134. CommonActions.reset({
  135. index: 0,
  136. routes: [
  137. {
  138. name: initRouteName,
  139. },
  140. ],
  141. })
  142. );
  143. clearLoading();
  144. }
  145. }, [initRouteName]);
  146. if (!isLoadingComplete && !props.skipLoadingScreen && !initRouteName) {
  147. return null;
  148. }
  149. return (
  150. <>
  151. <IconRegistry icons={EvaIconsPack} />
  152. <ThemeProvider theme={Matheme}>
  153. <Provider>
  154. <ApplicationProvider
  155. {...eva}
  156. theme={{ ...eva.light, ...theme }}
  157. customMapping={customMapping}
  158. >
  159. <Dialog />
  160. <Layout style={{ flex: 1 }}>
  161. <NavigationContainer ref={navigationRef}>
  162. <Stack.Navigator
  163. headerMode="none"
  164. screenOptions={{
  165. gestureEnabled: true,
  166. cardStyleInterpolator:
  167. CardStyleInterpolators.forHorizontalIOS,
  168. }}
  169. initialRouteName={initRouteName}
  170. >
  171. {GuideScreens(Stack.Screen)}
  172. <Stack.Screen
  173. name="Root"
  174. component={BottomTabNavigator}
  175. options={{}}
  176. />
  177. <Stack.Screen name="Login" component={LoginStackNavigator} />
  178. {/* 基础功能页面 */}
  179. {BasicScreens(Stack.Screen)}
  180. </Stack.Navigator>
  181. </NavigationContainer>
  182. </Layout>
  183. </ApplicationProvider>
  184. </Provider>
  185. </ThemeProvider>
  186. </>
  187. );
  188. }