Router.js 13 KB

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