Router.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /**
  2. * 路由配置文件
  3. * @邠心vbe on 2021/03/22
  4. */
  5. import React, { useEffect, useRef } from 'react';
  6. import { Pressable } from 'react-native';
  7. import { NavigationContainer } from '@react-navigation/native';
  8. import { createStackNavigator, TransitionPresets } from '@react-navigation/stack';
  9. import { enableScreens } from 'react-native-screens';
  10. import { Styles } from '../components/Toolbar';
  11. import app from '../../app.json';
  12. import About from './About';
  13. import Launcher from './Launch';
  14. import Login from './sign/Login';
  15. import Regist from './sign/RegisterV2';
  16. import RegisterV3 from './sign/RegisterV3';
  17. import RegisterV4 from './sign/RegisterV4';
  18. import RegisterPublic from './sign/RegisterPublic';
  19. import RegisterDriver from './sign/RegisterDriver';
  20. import Home from './home/Drawer';
  21. import Search from './search/SearchV2';
  22. import ChargeDetails from './charge/Details';
  23. import QRScan from './chargeV2/QRScan';
  24. import Feedback from './my/Feedback';
  25. import Privacy from './my/Privacy';
  26. import Profile from './my/ProfileV2';
  27. import Condition from './my/Condition';
  28. import Summary from './chargeV2/Summary';
  29. import Rating from './charge/Rating';
  30. import Wallet from './wallet/Wallet';
  31. import EditProfile from './my/EditProfile';
  32. import Referral from './my/Referral';
  33. import Topup from './wallet/Topup'; //not 2C2P
  34. import TopupV2 from './wallet/TopupV2'; //2C2P payment
  35. import TopupNew from './wallet/TopupNew';
  36. import AddCard from './wallet/AddCard';
  37. import FormCard from './payment/FormCard';
  38. import VehicleList from './my/VehicleList';
  39. import AddVehicle from './my/AddVehicle';
  40. import EditVehicle from './my/EditVehicle';
  41. import PayNow from './payment/PayNow';
  42. import CreditCard from './payment/CreditCard';
  43. import EditAddress from './my/EditAddress';
  44. import Notify from './home/Notify';
  45. import Test from './home/maps/Test';
  46. import ResetPassword from './sign/ResetPasswordV2';
  47. import PaymentMethod from './payment/PaymentMethod';
  48. import PayPerUse from './payment/PayPerUse';
  49. import PaymentWeb from './payment/PaymentWeb';
  50. import Settings from './Settings';
  51. import ChargeAdapter from './chargeV2/ChargeAdapter';
  52. import { BridgePage } from '../utils/routeUtil';
  53. export var PageList = {
  54. 'splash': {
  55. component: Launcher
  56. },
  57. 'home': {
  58. component: Home,
  59. options: TransitionPresets.FadeFromBottomAndroid
  60. },
  61. 'bridge': {
  62. component: BridgePage
  63. },
  64. 'search': {
  65. title: 'Search',
  66. component: Search
  67. },
  68. 'login': {
  69. component: Login
  70. },
  71. 'register': {
  72. component: RegisterV4,
  73. title: 'Public Registration'
  74. },
  75. 'registerPublic': {
  76. component: RegisterPublic,
  77. title: 'Public Registration'
  78. },
  79. 'registerFleet': {
  80. component: RegisterDriver,
  81. title: 'Fleet / PHV Registration'
  82. },
  83. 'chargeDetail': {
  84. title: 'Charging Site',
  85. component: ChargeDetails
  86. },
  87. 'chargeDetailPage': {
  88. title: 'Charging Site',
  89. component: ChargeAdapter
  90. },
  91. 'scanqr': {
  92. title: 'QR Scan',
  93. component: QRScan
  94. },
  95. 'feedback': {
  96. title: 'Feedback',
  97. component: Feedback
  98. },
  99. 'about': {
  100. title: 'About',
  101. component: About
  102. },
  103. 'privacy': {
  104. title: 'Privacy Policy',
  105. component: Privacy
  106. },
  107. 'profile': {
  108. title: 'Profile Settings',
  109. component: Profile
  110. },
  111. 'condition': {
  112. title: 'Terms of Use',
  113. component: Condition
  114. },
  115. 'summary': {
  116. title: 'Summary',
  117. component: Summary
  118. },
  119. 'rating': {
  120. title: 'Your Rating',
  121. component: Rating
  122. },
  123. 'wallet': {
  124. title: 'Transactions',
  125. component: Wallet
  126. },
  127. 'editProfile': {
  128. title: 'My Profile',
  129. component: EditProfile
  130. },
  131. 'editAddress': {
  132. title: 'Edit Address',
  133. component: EditAddress
  134. },
  135. 'referral': {
  136. title: 'Referral',
  137. component: Referral
  138. },
  139. 'topup': {
  140. title: 'Top Up',
  141. component: Topup
  142. },
  143. 'topupV2': {
  144. title: 'Top Up',
  145. component: TopupV2
  146. },
  147. 'topupNew': {
  148. title: 'Purchase Credits',
  149. component: TopupNew
  150. },
  151. 'addCard': {
  152. title: 'Add Cards',
  153. component: AddCard
  154. },
  155. 'myVehicles': {
  156. title: 'My Vehicles',
  157. component: VehicleList,
  158. options: {
  159. headerRight: () => (
  160. <Pressable
  161. style={Styles.backIcon}
  162. android_ripple={rippleLessIcon}
  163. onPress={() => startPage(PageList.addVehicle)}>
  164. <MaterialCommunityIcons
  165. name='plus'
  166. color={pageTitleTint}
  167. size={24}
  168. style={Styles.iconOpacity}
  169. />
  170. </Pressable>
  171. )
  172. }
  173. },
  174. 'addVehicle': {
  175. title: 'Add Vehicle',
  176. component: AddVehicle
  177. },
  178. 'editVehicle': {
  179. title: 'Update Vehicle',
  180. component: EditVehicle
  181. },
  182. 'paynow': {
  183. title: 'PAYNOW',
  184. component: PayNow
  185. },
  186. 'paycard': {
  187. title: 'Top Up with Card',
  188. component: CreditCard
  189. },
  190. 'formCard': {
  191. title: 'Top Up with Card',
  192. component: FormCard
  193. },
  194. 'paymentMethod': {
  195. title: 'Payment Method',
  196. component: PaymentMethod
  197. },
  198. 'paymentWeb': {
  199. title: 'Make Payment',
  200. component: PaymentWeb
  201. },
  202. 'payPeruse': {
  203. title: 'Pay Per Use',
  204. component: PayPerUse
  205. },
  206. 'notify': {
  207. title: 'Notification Test',
  208. component: Notify
  209. },
  210. 'mapTest': {
  211. component: Test
  212. },
  213. 'forgotPassword': {
  214. title: 'Forgot Password',
  215. component: ResetPassword
  216. },
  217. 'changePassword': {
  218. title: 'Account Security',
  219. component: ResetPassword
  220. },
  221. 'settings': {
  222. title: 'Settings',
  223. component: Settings
  224. }
  225. }
  226. const Stack = createStackNavigator();
  227. enableScreens();
  228. /**
  229. * 配置APP主题色
  230. */
  231. const themeColor = {
  232. text: textPrimary,
  233. card: colorThemes,
  234. primary: colorPrimary,
  235. background: pageBackground,
  236. notification: colorDark
  237. }
  238. const noTitle = (opt = {}) => {
  239. return {
  240. title: isIOS ? 'Back' : app.displayName,
  241. headerShown: false,
  242. ...opt
  243. }
  244. }
  245. /**
  246. * 配置标题
  247. * @param {String} title 页面标题
  248. * @param {Object} opt 标题栏选项
  249. * @returns
  250. */
  251. const Title = (title, opt = {}) => {
  252. return {
  253. title: title,
  254. headerShown: true,
  255. headerStyle: {
  256. ...titleHeight(),
  257. elevation: 0,
  258. backgroundColor: colorLight //配置标题栏背景
  259. },
  260. headerTintColor: pageTitleTint, //配置标题栏文字和图标颜色
  261. headerBackTitle: ' ', //配置iOS返回按钮文字
  262. ...opt
  263. }
  264. }
  265. var bakPages = undefined;
  266. function getPages() {
  267. let pages = [], keys = {};
  268. if (bakPages == undefined) {
  269. bakPages = Object.assign({}, PageList);
  270. } else {
  271. PageList = bakPages;
  272. }
  273. for (const page in PageList) {
  274. var p = PageList[page]
  275. keys[page] = page;
  276. pages.push(
  277. <Stack.Screen
  278. key={page}
  279. name={page}
  280. component={p.component}
  281. options={p.title ? Title(p.title, p.options) : noTitle(p.options)}
  282. />
  283. );
  284. }
  285. PageList = keys;
  286. return pages;
  287. }
  288. const Router = () => {
  289. const navigation = useRef();
  290. useEffect(() => {
  291. //注入全局方法
  292. global.startPage = (name, params = {}) => {
  293. navigation.current.navigate(name, params);
  294. }
  295. global.dispatchPage = (params) => {
  296. navigation.current.dispatch(params);
  297. }
  298. global.goBack = () => {
  299. if (navigation.current.canGoBack()) {
  300. navigation.current.goBack();
  301. } else {
  302. startPage(PageList.home);
  303. }
  304. }
  305. return (() => {
  306. global.startPage = null;
  307. global.goBack = null;
  308. });
  309. }, []);
  310. return (
  311. <NavigationContainer
  312. ref={navigation}
  313. theme={{
  314. dark: darkMode,
  315. colors: themeColor
  316. }}>
  317. <Stack.Navigator
  318. initialRouteName='splash'
  319. screenOptions={{animationEnabled: true, ...TransitionPresets.SlideFromRightIOS }}>
  320. {getPages()}
  321. </Stack.Navigator>
  322. </NavigationContainer>
  323. )
  324. }
  325. const titleHeight = () => {
  326. return isIOS ? {} : {height: toolbarSize};
  327. }
  328. export default Router;