Router.js 7.5 KB

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