Router.js 12 KB

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