Router.js 13 KB

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