App.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. } else if (mid !== 0) {
  91. checkNowGuideStep();
  92. }
  93. }, [mid]);
  94. useUpdateEffect(() => {
  95. console.log(guideStep);
  96. switch (guideStep) {
  97. case "finish":
  98. setInit("Root");
  99. break;
  100. case "ComeBack":
  101. setinitRoute("RegisterSe");
  102. setInit("Login");
  103. break;
  104. case "1":
  105. setInit("Guide1");
  106. break;
  107. case "2":
  108. setInit("Guide2");
  109. break;
  110. case "3":
  111. setInit("Guide3");
  112. break;
  113. case "4":
  114. setInit("Guide4");
  115. break;
  116. case "5":
  117. setInit("StoreAudit");
  118. break;
  119. default:
  120. setInit("Login");
  121. break;
  122. }
  123. }, [guideStep]);
  124. useUpdateEffect(() => {
  125. if (!isLoadingComplete) {
  126. setLoadingComplete(true);
  127. SplashScreen.hide();
  128. } else {
  129. navigationRef.current.dispatch(
  130. CommonActions.reset({
  131. index: 0,
  132. routes: [
  133. {
  134. name: initRouteName,
  135. },
  136. ],
  137. })
  138. );
  139. clearLoading();
  140. }
  141. }, [initRouteName]);
  142. if (!isLoadingComplete && !props.skipLoadingScreen && !initRouteName) {
  143. return null;
  144. }
  145. return (
  146. <>
  147. <IconRegistry icons={EvaIconsPack} />
  148. <ThemeProvider theme={Matheme}>
  149. <Provider>
  150. <ApplicationProvider
  151. {...eva}
  152. theme={{ ...eva.light, ...theme }}
  153. customMapping={customMapping}
  154. >
  155. <Dialog />
  156. <Layout style={{ flex: 1 }}>
  157. <NavigationContainer ref={navigationRef}>
  158. <Stack.Navigator
  159. headerMode="none"
  160. screenOptions={{
  161. gestureEnabled: true,
  162. cardStyleInterpolator:
  163. CardStyleInterpolators.forHorizontalIOS,
  164. }}
  165. initialRouteName={initRouteName}
  166. >
  167. {GuideScreens(Stack.Screen)}
  168. <Stack.Screen
  169. name="Root"
  170. component={BottomTabNavigator}
  171. options={{}}
  172. />
  173. <Stack.Screen name="Login" component={LoginStackNavigator} />
  174. {/* 基础功能页面 */}
  175. {BasicScreens(Stack.Screen)}
  176. </Stack.Navigator>
  177. </NavigationContainer>
  178. </Layout>
  179. </ApplicationProvider>
  180. </Provider>
  181. </ThemeProvider>
  182. </>
  183. );
  184. }