Router.js 14 KB

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