Router.js 10 KB

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