Router.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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 { BackButton, Styles } from '../components/Toolbar';
  11. import app from '../../app.json';
  12. import About from './about/AboutV2';
  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/Index';
  21. import Search from './search/SearchV2';
  22. import ChargeDetails from './charge/Details';
  23. import QRScan from './charge/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/SummaryV2';
  29. import SummaryV3 from './chargeV2/SummaryV3';
  30. import Rating from './charge/Rating';
  31. import Wallet from './wallet/Wallet';
  32. import EditProfile from './my/EditProfile';
  33. import Referral from './my/Referral';
  34. import Topup from './wallet/Topup'; //not 2C2P
  35. import TopupV2 from './wallet/TopupV2'; //2C2P payment
  36. import TopupNew from './wallet/TopupNew';
  37. import AddCard from './wallet/AddCard';
  38. import FormCard from './payment/FormCard';
  39. import VehicleList from './vehicles/VehicleList';
  40. import AddVehicle from './vehicles/AddVehicle';
  41. import EditVehicle from './vehicles/EditVehicle';
  42. import VehicleDetail from './vehicles/VehicleDetail';
  43. import PayNow from './payment/PayNow';
  44. import CreditCard from './payment/CreditCard';
  45. import EditAddress from './my/EditAddress';
  46. import Notify from './home/Notify';
  47. import Test from './home/maps/Test';
  48. import ResetPassword from './sign/ResetPasswordV2';
  49. import PaymentMethod from './payment/PaymentMethod';
  50. import PayPerUse from './payment/PayPerUse';
  51. import PaymentWeb from './payment/PaymentWeb';
  52. import Settings from './Settings';
  53. import ChargeAdapter from './chargeV2/ChargeAdapter';
  54. import ChargingPage from './chargingV2/ChargingPage';
  55. import { BridgePage } from '../utils/routeUtil';
  56. import HeaderTitle from '../components/HeaderTitle';
  57. import Bookmarks from './bookmark/Bookmarks';
  58. import MembersList from './member/MembersList';
  59. import ApplyMember from './member/ApplyMember';
  60. import Contact from './about/Contact';
  61. import Notification from './alert/Notification';
  62. import ViewAlerts from './alert/ViewAlerts';
  63. import ViewCampaign from './alert/ViewCampaign';
  64. import RefundPolicy from './payment/RefundPolicy';
  65. import ViewArticle from './alert/ViewArticle';
  66. import VehicleListV2 from './vehicles/VehicleListV2';
  67. import HistoryList from './wallet/HistoryList';
  68. import VoucherPage from './vouchers/VoucherPage';
  69. export var PageList = {
  70. 'splash': {
  71. component: Launcher
  72. },
  73. 'home': {
  74. component: Home,
  75. options: TransitionPresets.FadeFromBottomAndroid
  76. },
  77. 'bridge': {
  78. component: BridgePage
  79. },
  80. 'search': {
  81. title: 'Search',
  82. titleScope: 'route.search',
  83. component: Search
  84. },
  85. 'login': {
  86. component: Login
  87. },
  88. 'register': {
  89. component: RegisterV4,
  90. title: 'Public Registration',
  91. titleScope: 'route.publicRegister'
  92. },
  93. 'registerPublic': {
  94. component: RegisterPublic,
  95. title: 'Public Registration',
  96. titleScope: 'route.publicRegister'
  97. },
  98. 'registerFleet': {
  99. component: RegisterDriver,
  100. title: 'Fleet / PHV Registration',
  101. titleScope: 'route.driverRegister'
  102. },
  103. 'chargeDetail': {
  104. title: 'Charging Site',
  105. titleScope: 'route.chargingSite',
  106. component: ChargeDetails
  107. },
  108. 'chargeDetailPage': {
  109. title: 'Charging Site',
  110. titleScope: 'route.chargingSite',
  111. component: ChargeAdapter
  112. },
  113. 'chargingPage': {
  114. title: 'Charging',
  115. titleScope: 'route.charging',
  116. component: ChargingPage
  117. },
  118. 'scanqr': {
  119. title: 'QR Scan',
  120. titleScope: 'route.qrScan',
  121. component: QRScan
  122. },
  123. 'feedback': {
  124. title: 'Feedback',
  125. titleScope: 'route.feedback',
  126. component: Feedback
  127. },
  128. 'about': {
  129. title: 'About',
  130. titleScope: 'route.about',
  131. component: About
  132. },
  133. 'supportContact': {
  134. title: 'Support Hotline',
  135. titleScope: 'support.supportHotline',
  136. component: Contact
  137. },
  138. 'privacy': {
  139. title: 'Privacy Policy',
  140. titleScope: 'route.privacyPolicy',
  141. component: Privacy
  142. },
  143. 'condition': {
  144. title: 'Terms of Use',
  145. titleScope: 'route.termsOfUse',
  146. component: Condition
  147. },
  148. 'profile': {
  149. title: 'Profile Settings',
  150. titleScope: 'route.profileSettings',
  151. component: Profile
  152. },
  153. 'summary': {
  154. title: 'Summary',
  155. titleScope: 'receipt.receipt',
  156. component: app.v3.summary ? SummaryV3 : Summary
  157. },
  158. 'rating': {
  159. title: 'Your Rating',
  160. titleScope: 'route.rating',
  161. component: Rating
  162. },
  163. 'wallet': {
  164. title: 'Transactions',
  165. titleScope: 'route.wallet',
  166. component: Wallet
  167. },
  168. 'history': {
  169. title: 'History',
  170. titleScope: 'route.history',
  171. component: HistoryList
  172. },
  173. 'editProfile': {
  174. title: 'My Profile',
  175. titleScope: 'route.editProfile',
  176. component: EditProfile
  177. },
  178. 'editAddress': {
  179. title: 'Edit Address',
  180. titleScope: 'route.editAddress',
  181. component: EditAddress
  182. },
  183. 'referral': {
  184. title: 'Referral',
  185. titleScope: 'route.referral',
  186. component: Referral
  187. },
  188. 'topup': {
  189. title: 'Top Up',
  190. titleScope: 'route.topUp',
  191. component: Topup
  192. },
  193. 'topupV2': {
  194. title: 'Top Up',
  195. titleScope: 'route.topUp',
  196. component: TopupV2
  197. },
  198. 'topupNew': {
  199. title: 'Top Up',
  200. titleScope: 'route.topUp',
  201. component: TopupNew
  202. },
  203. 'addCard': {
  204. title: 'Add Cards',
  205. titleScope: 'route.addCards',
  206. component: AddCard
  207. },
  208. 'myVehicles': {
  209. title: 'My Vehicles',
  210. titleScope: 'route.myVehicles',
  211. component: VehicleList,
  212. options: {
  213. headerRight: () => (
  214. <Pressable
  215. style={Styles.backIcon}
  216. android_ripple={rippleLessIcon}
  217. onPress={() => startPage(PageList.addVehicle)}>
  218. <MaterialCommunityIcons
  219. name='plus'
  220. color={pageTitleTint}
  221. size={24}
  222. style={Styles.iconOpacity}
  223. />
  224. </Pressable>
  225. )
  226. }
  227. },
  228. 'vehiclesListV2': {
  229. title: 'My Vehicles',
  230. titleScope: 'route.myVehicles',
  231. component: VehicleListV2
  232. },
  233. 'addVehicle': {
  234. title: 'Add Vehicle',
  235. titleScope: 'route.addVehicle',
  236. component: AddVehicle
  237. },
  238. 'editVehicle': {
  239. title: 'Update Vehicle',
  240. titleScope: 'route.editVehicle',
  241. component: EditVehicle
  242. },
  243. 'addVehicleV2': {
  244. title: 'Add Vehicle',
  245. titleScope: 'route.addVehicle',
  246. component: VehicleDetail
  247. },
  248. 'editVehicleV2': {
  249. title: 'Update Detail',
  250. titleScope: 'route.editVehicle',
  251. component: VehicleDetail
  252. },
  253. 'paynow': {
  254. title: 'PAYNOW',
  255. titleScope: 'route.paynow',
  256. component: PayNow
  257. },
  258. 'paycard': {
  259. title: 'Top Up with Card',
  260. titleScope: 'route.topUpWithCard',
  261. component: CreditCard
  262. },
  263. 'formCard': {
  264. title: 'Top Up with Card',
  265. titleScope: 'route.topUpWithCard',
  266. component: FormCard
  267. },
  268. 'paymentMethod': {
  269. title: 'Payment Method',
  270. titleScope: 'route.paymentMethod',
  271. component: PaymentMethod
  272. },
  273. 'paymentWeb': {
  274. title: 'Make Payment',
  275. titleScope: 'route.makePayment',
  276. component: PaymentWeb
  277. },
  278. 'payPeruse': {
  279. title: 'Pay Per Use',
  280. titleScope: 'route.payPerUse',
  281. component: PayPerUse
  282. },
  283. 'notification': {
  284. title: 'Notification',
  285. titleScope: 'route.notifications',
  286. component: Notification
  287. },
  288. 'viewMessage': {
  289. title: 'View Message',
  290. titleScope: 'notification.viewMessage',
  291. component: ViewAlerts
  292. },
  293. 'viewArticle': {
  294. title: 'View Article',
  295. titleScope: 'notification.viewMessage',
  296. component: ViewArticle
  297. },
  298. 'viewCampaign': {
  299. title: 'View Campaign',
  300. titleScope: 'notification.viewMessage',
  301. component: ViewCampaign
  302. },
  303. 'notify': {
  304. title: 'Notification Test',
  305. titleScope: 'route.notificationTest',
  306. component: Notify
  307. },
  308. 'mapTest': {
  309. component: Test
  310. },
  311. 'forgotPassword': {
  312. title: 'Forgot Password',
  313. titleScope: 'route.forgotPassword',
  314. component: ResetPassword
  315. },
  316. 'changePassword': {
  317. title: 'Account Security',
  318. titleScope: 'route.changePassword',
  319. component: ResetPassword
  320. },
  321. 'bookmarks': {
  322. title: "Bookmarks",
  323. titleScope: 'route.bookmarks',
  324. component: Bookmarks
  325. },
  326. 'membersList': {
  327. title: "Your Membership",
  328. titleScope: 'route.yourMembers',
  329. component: MembersList,
  330. options: {
  331. headerRight: () => (
  332. <Pressable
  333. style={Styles.backIcon}
  334. android_ripple={rippleLessIcon}
  335. onPress={() => startPage(PageList.applyMember)}>
  336. <MaterialCommunityIcons
  337. name='plus'
  338. color={pageTitleTint}
  339. size={24}
  340. style={Styles.iconOpacity}
  341. />
  342. </Pressable>
  343. )
  344. }
  345. },
  346. 'applyMember': {
  347. title: "Apply Membership",
  348. titleScope: 'route.applyMember',
  349. component: ApplyMember
  350. },
  351. 'refundPolicy': {
  352. title: "Refund Policy",
  353. titleScope: 'route.refundPolicy',
  354. component: RefundPolicy
  355. },
  356. 'myVoucher': {
  357. title: "Vouchers",
  358. titleScope: 'route.vouchers',
  359. component: VoucherPage
  360. },
  361. 'settings': {
  362. title: 'Settings',
  363. titleScope: 'route.settings',
  364. component: Settings
  365. }
  366. }
  367. const Stack = createStackNavigator();
  368. enableScreens();
  369. /**
  370. * 配置APP主题色
  371. */
  372. const themeColor = {
  373. text: textPrimary,
  374. card: colorThemes,
  375. primary: colorPrimary,
  376. background: pageBackground,
  377. notification: colorDark
  378. }
  379. const noTitle = (opt = {}) => {
  380. return {
  381. title: isIOS ? 'Back' : app.displayName,
  382. headerShown: false,
  383. ...opt
  384. }
  385. }
  386. /**
  387. * 配置标题
  388. * @param {String} title 页面标题
  389. * @param {Object} opt 标题栏选项
  390. * @returns
  391. */
  392. const Title = (title, opt = {}, titleScope) => {
  393. const options = {
  394. headerShown: true,
  395. headerStyle: {
  396. ...titleHeight(),
  397. elevation: 0,
  398. shadowOpacity: 0,
  399. borderBottomWidth: 0,
  400. backgroundColor: app.isWhitelabel ? colorLight : colorPrimary //配置标题栏背景
  401. },
  402. headerTintColor: pageTitleTint, //配置标题栏文字和图标颜色
  403. headerBackTitle: ' ', //配置iOS返回按钮文字
  404. headerBackTitleVisible: false,
  405. ...opt
  406. }
  407. if (titleScope && $t) {
  408. options.headerTitle = () => <HeaderTitle scope={titleScope}/>
  409. } else {
  410. options.title = title
  411. }
  412. options.headerLeft = () => <BackButton/>
  413. return options;
  414. }
  415. var bakPages = undefined;
  416. function getPages() {
  417. let pages = [], keys = {};
  418. if (bakPages == undefined) {
  419. bakPages = Object.assign({}, PageList);
  420. } else {
  421. PageList = bakPages;
  422. }
  423. for (const page in bakPages) {
  424. var p = bakPages[page]
  425. keys[page] = page;
  426. pages.push(
  427. <Stack.Screen
  428. key={page}
  429. name={page}
  430. component={p.component}
  431. options={p.title ? Title(p.title, p.options, p.titleScope) : noTitle(p.options)}
  432. />
  433. );
  434. }
  435. PageList = keys;
  436. return pages;
  437. }
  438. const Router = () => {
  439. const navigation = useRef();
  440. useEffect(() => {
  441. //注入全局方法
  442. global.startPage = (name, params = {}) => {
  443. navigation.current?.navigate(name, params);
  444. }
  445. global.dispatchPage = (params) => {
  446. navigation.current?.dispatch(params);
  447. }
  448. global.goBack = () => {
  449. if (global.pageBackFallback && global.pageBackFallback.names) {
  450. //console.log("覆盖返回", navigation.current.getCurrentRoute()?.name);
  451. if (global.pageBackFallback.names.indexOf(navigation.current.getCurrentRoute()?.name) >= 0) {
  452. global.pageBackFallback?.callback();
  453. global.pageBackFallback = undefined;
  454. return;
  455. }
  456. }
  457. if (navigation.current?.canGoBack()) {
  458. navigation.current?.goBack();
  459. } else {
  460. startPage(PageList.home);
  461. }
  462. }
  463. return (() => {
  464. global.startPage = null;
  465. global.goBack = null;
  466. });
  467. }, []);
  468. return (
  469. <NavigationContainer
  470. ref={navigation}
  471. theme={{
  472. dark: darkMode,
  473. colors: themeColor
  474. }}>
  475. <Stack.Navigator
  476. initialRouteName='splash'
  477. screenOptions={{animationEnabled: true, ...TransitionPresets.SlideFromRightIOS }}>
  478. {getPages()}
  479. </Stack.Navigator>
  480. </NavigationContainer>
  481. )
  482. }
  483. const titleHeight = () => {
  484. return isIOS ? {} : {height: toolbarSize};
  485. }
  486. export default Router;