Router.js 11 KB

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