Router.js 12 KB

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