Router.js 11 KB

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