App.js 5.1 KB

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