| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- /**
- * 路由配置文件
- * @邠心vbe on 2021/03/22
- */
- import React, { useEffect, useRef } from 'react';
- import { Pressable } from 'react-native';
- import { NavigationContainer } from '@react-navigation/native';
- import { createStackNavigator, TransitionPresets } from '@react-navigation/stack';
- import { enableScreens } from 'react-native-screens';
- import { Styles } from '../components/Toolbar';
- import app from '../../app.json';
- import About from './About';
- import Launcher from './Launch';
- import Login from './sign/Login';
- import Regist from './sign/RegisterV2';
- import RegisterV3 from './sign/RegisterV3';
- import RegisterV4 from './sign/RegisterV4';
- import RegisterPublic from './sign/RegisterPublic';
- import RegisterDriver from './sign/RegisterDriver';
- import Home from './home/Drawer';
- import Search from './search/SearchV2';
- import ChargeDetails from './charge/Details';
- import QRScan from './chargeV2/QRScan';
- import Feedback from './my/Feedback';
- import Privacy from './my/Privacy';
- import Profile from './my/ProfileV2';
- import Condition from './my/Condition';
- import Summary from './chargeV2/Summary';
- import Rating from './charge/Rating';
- import Wallet from './wallet/Wallet';
- import EditProfile from './my/EditProfile';
- import Referral from './my/Referral';
- import Topup from './wallet/Topup'; //not 2C2P
- import TopupV2 from './wallet/TopupV2'; //2C2P payment
- import TopupNew from './wallet/TopupNew';
- import AddCard from './wallet/AddCard';
- import FormCard from './payment/FormCard';
- import VehicleList from './my/VehicleList';
- import AddVehicle from './my/AddVehicle';
- import EditVehicle from './my/EditVehicle';
- import PayNow from './payment/PayNow';
- import CreditCard from './payment/CreditCard';
- import EditAddress from './my/EditAddress';
- import Notify from './home/Notify';
- import Test from './home/maps/Test';
- import ResetPassword from './sign/ResetPasswordV2';
- import PaymentMethod from './payment/PaymentMethod';
- import PayPerUse from './payment/PayPerUse';
- import PaymentWeb from './payment/PaymentWeb';
- import Settings from './Settings';
- import ChargeAdapter from './chargeV2/ChargeAdapter';
- export var PageList = {
- 'splash': {
- component: Launcher
- },
- 'home': {
- component: Home,
- options: TransitionPresets.FadeFromBottomAndroid
- },
- 'search': {
- title: 'Search',
- component: Search
- },
- 'login': {
- component: Login
- },
- 'register': {
- component: RegisterV4,
- title: 'Public Registration'
- },
- 'registerPublic': {
- component: RegisterPublic,
- title: 'Public Registration'
- },
- 'registerFleet': {
- component: RegisterDriver,
- title: 'Fleet / PHV Registration'
- },
- 'chargeDetail': {
- title: 'Charging Site',
- component: ChargeDetails
- },
- 'chargeDetailPage': {
- title: 'Charging Site',
- component: ChargeAdapter
- },
- 'scanqr': {
- title: 'QR Scan',
- component: QRScan
- },
- 'feedback': {
- title: 'Feedback',
- component: Feedback
- },
- 'about': {
- title: 'About',
- component: About
- },
- 'privacy': {
- title: 'Privacy Policy',
- component: Privacy
- },
- 'profile': {
- title: 'Profile Settings',
- component: Profile
- },
- 'condition': {
- title: 'Terms of Use',
- component: Condition
- },
- 'summary': {
- title: 'Summary',
- component: Summary
- },
- 'rating': {
- title: 'Your Rating',
- component: Rating
- },
- 'wallet': {
- title: 'Transactions',
- component: Wallet
- },
- 'editProfile': {
- title: 'My Profile',
- component: EditProfile
- },
- 'editAddress': {
- title: 'Edit Address',
- component: EditAddress
- },
- 'referral': {
- title: 'Referral',
- component: Referral
- },
- 'topup': {
- title: 'Top Up',
- component: Topup
- },
- 'topupV2': {
- title: 'Top Up',
- component: TopupV2
- },
- 'topupNew': {
- title: 'Purchase Credits',
- component: TopupNew
- },
- 'addCard': {
- title: 'Add Cards',
- component: AddCard
- },
- 'myVehicles': {
- title: 'My Vehicles',
- component: VehicleList,
- options: {
- headerRight: () => (
- <Pressable
- style={Styles.backIcon}
- android_ripple={rippleLessIcon}
- onPress={() => startPage(PageList.addVehicle)}>
- <MaterialCommunityIcons
- name='plus'
- color={pageTitleTint}
- size={24}
- style={Styles.iconOpacity}
- />
- </Pressable>
- )
- }
- },
- 'addVehicle': {
- title: 'Add Vehicle',
- component: AddVehicle
- },
- 'editVehicle': {
- title: 'Update Vehicle',
- component: EditVehicle
- },
- 'paynow': {
- title: 'PAYNOW',
- component: PayNow
- },
- 'paycard': {
- title: 'Top Up with Card',
- component: CreditCard
- },
- 'formCard': {
- title: 'Top Up with Card',
- component: FormCard
- },
- 'paymentMethod': {
- title: 'Payment Method',
- component: PaymentMethod
- },
- 'paymentWeb': {
- title: 'Make Payment',
- component: PaymentWeb
- },
- 'payPeruse': {
- title: 'Pay Per Use',
- component: PayPerUse
- },
- 'notify': {
- title: 'Notification Test',
- component: Notify
- },
- 'mapTest': {
- component: Test
- },
- 'forgotPassword': {
- title: 'Forgot Password',
- component: ResetPassword
- },
- 'changePassword': {
- title: 'Account Security',
- component: ResetPassword
- },
- 'settings': {
- title: 'Settings',
- component: Settings
- }
- }
- const Stack = createStackNavigator();
- enableScreens();
- /**
- * 配置APP主题色
- */
- const themeColor = {
- text: textPrimary,
- card: colorThemes,
- primary: colorPrimary,
- background: pageBackground,
- notification: colorDark
- }
- const noTitle = (opt = {}) => {
- return {
- title: isIOS ? 'Back' : app.displayName,
- headerShown: false,
- ...opt
- }
- }
- /**
- * 配置标题
- * @param {String} title 页面标题
- * @param {Object} opt 标题栏选项
- * @returns
- */
- const Title = (title, opt = {}) => {
- return {
- title: title,
- headerShown: true,
- headerStyle: {
- ...titleHeight(),
- elevation: 0,
- backgroundColor: colorLight //配置标题栏背景
- },
- headerTintColor: pageTitleTint, //配置标题栏文字和图标颜色
- headerBackTitle: ' ', //配置iOS返回按钮文字
- ...opt
- }
- }
- var bakPages = undefined;
- function getPages() {
- let pages = [], keys = {};
- if (bakPages == undefined) {
- bakPages = Object.assign({}, PageList);
- } else {
- PageList = bakPages;
- }
- for (const page in PageList) {
- var p = PageList[page]
- keys[page] = page;
- pages.push(
- <Stack.Screen
- key={page}
- name={page}
- component={p.component}
- options={p.title ? Title(p.title, p.options) : noTitle(p.options)}
- />
- );
- }
- PageList = keys;
- return pages;
- }
- const Router = () => {
- const navigation = useRef();
- useEffect(() => {
- //注入全局方法
- global.startPage = (name, params = {}) => {
- navigation.current.navigate(name, params);
- }
- global.dispatchPage = (params) => {
- navigation.current.dispatch(params);
- }
- global.goBack = () => {
- if (navigation.current.canGoBack()) {
- navigation.current.goBack();
- }
- }
- return (() => {
- global.startPage = null;
- global.goBack = null;
- });
- }, []);
- return (
- <NavigationContainer
- ref={navigation}
- theme={{
- dark: darkMode,
- colors: themeColor
- }}>
- <Stack.Navigator
- initialRouteName='splash'
- screenOptions={{animationEnabled: true, ...TransitionPresets.SlideFromRightIOS }}>
- {getPages()}
- </Stack.Navigator>
- </NavigationContainer>
- )
- }
- const titleHeight = () => {
- return isIOS ? {} : {height: toolbarSize};
- }
- export default Router;
|