Router.js 9.4 KB

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