• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

React Navigation顶部导航自定义左侧返回按钮图标和文案

武飞扬头像
徐同保
帮助1

学新通

 router/config.js:

  1.  
    import Login from '../views/light/login/Login'
  2.  
    import Register from '../views/light/register/Index'
  3.  
    import ForgetPassword from '../views/light/forgetPassword/Index'
  4.  
    import Web from '../views/light/web/Index'
  5.  
    import Index from '../views/light/index/Index'
  6.  
    import MeTabs from '../views/light/index/me/tabs/Index'
  7.  
    import IndexForTab from '../views/light/test/tab1/IndexForTab'
  8.  
    import { View, Text } from 'react-native'
  9.  
    import { createNativeStackNavigator } from '@react-navigation/native-stack'
  10.  
    import { Back } from '../component/light'
  11.  
    const Stack = createNativeStackNavigator()
  12.  
     
  13.  
    const routerOptions = {
  14.  
    headerTitleAlign: 'center',
  15.  
    headerStyle: { backgroundColor: '#f6f6f6' },
  16.  
    headerBackVisible: false,
  17.  
    }
  18.  
     
  19.  
    const getRouter = () => {
  20.  
    const routerList = [
  21.  
    {
  22.  
    name: 'Login',
  23.  
    component: Login,
  24.  
    options: {
  25.  
    ...routerOptions,
  26.  
    title: '登录',
  27.  
    },
  28.  
    },
  29.  
    {
  30.  
    name: 'Register',
  31.  
    component: Register,
  32.  
    options: {
  33.  
    ...routerOptions,
  34.  
    title: '注册',
  35.  
    },
  36.  
    },
  37.  
    {
  38.  
    name: 'ForgetPassword',
  39.  
    component: ForgetPassword,
  40.  
    options: {
  41.  
    ...routerOptions,
  42.  
    title: '忘记密码',
  43.  
    },
  44.  
    },
  45.  
    {
  46.  
    name: 'Web',
  47.  
    component: Web,
  48.  
    options: {
  49.  
    headerShown: false,
  50.  
    },
  51.  
    },
  52.  
    {
  53.  
    name: 'Index',
  54.  
    component: Index,
  55.  
    options: {
  56.  
    headerShown: false,
  57.  
    },
  58.  
    },
  59.  
    {
  60.  
    name: 'MeTabs',
  61.  
    component: MeTabs,
  62.  
    options: {
  63.  
    ...routerOptions,
  64.  
    headerBackVisible: false,
  65.  
    title: '',
  66.  
    headerLeft: () => (<Back></Back>)
  67.  
    },
  68.  
    },
  69.  
    {
  70.  
    name: 'IndexForTab',
  71.  
    component: IndexForTab,
  72.  
    options: {
  73.  
    headerShown: false,
  74.  
    },
  75.  
    },
  76.  
    ]
  77.  
    return routerList.map((item) => (
  78.  
    <Stack.Screen
  79.  
    name={item.name}
  80.  
    component={item.component}
  81.  
    options={item.options}
  82.  
    key={item.name}
  83.  
    ></Stack.Screen>
  84.  
    ))
  85.  
    }
  86.  
     
  87.  
    export { getRouter }
学新通

 back/Index.js:

  1.  
    import React, { useState } from 'react'
  2.  
    import { View, Text, TouchableWithoutFeedback } from 'react-native'
  3.  
    import { useNavigation } from '@react-navigation/native'
  4.  
    import Icon from '../icon/Index'
  5.  
    import styles from './styles'
  6.  
     
  7.  
    export default function Index(props) {
  8.  
    const navigation = useNavigation()
  9.  
     
  10.  
    const handleBack = () => {
  11.  
    console.log(1)
  12.  
    navigation.goBack()
  13.  
    }
  14.  
    return (
  15.  
    <TouchableWithoutFeedback onPress={handleBack}>
  16.  
    <View style={styles.mBackWrap}>
  17.  
    <Icon name="arrow" style={styles.mBackIcon}></Icon>
  18.  
    <Text style={styles.mBackText}>返回</Text>
  19.  
    </View>
  20.  
    </TouchableWithoutFeedback>
  21.  
    )
  22.  
    }
学新通

学新通

 学新通

学新通

 学新通

学新通

参考链接:

https://reactnavigation.org/docs/native-stack-navigator

https://chat.xutongbao.top/

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgfhgie
系列文章
更多 icon
同类精品
更多 icon
继续加载