当前位置 : 主页 > 手机开发 > harmonyos >

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

来源:互联网 收集:自由互联 发布时间:2023-08-28
router/config.js: import Login from '../views/light/login/Login'import Register from '../views/light/register/Index'import ForgetPassword from '../views/light/forgetPassword/Index'import Web from '../views/light/web/Index'import Index from


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

 router/config.js:

import Login from '../views/light/login/Login'
import Register from '../views/light/register/Index'
import ForgetPassword from '../views/light/forgetPassword/Index'
import Web from '../views/light/web/Index'
import Index from '../views/light/index/Index'
import MeTabs from '../views/light/index/me/tabs/Index'
import IndexForTab from '../views/light/test/tab1/IndexForTab'
import { View, Text } from 'react-native'
import { createNativeStackNavigator } from '@react-navigation/native-stack'
import { Back } from '../component/light'
const Stack = createNativeStackNavigator()

const routerOptions = {
  headerTitleAlign: 'center',
  headerStyle: { backgroundColor: '#f6f6f6' },
  headerBackVisible: false,
}

const getRouter = () => {
  const routerList = [
    {
      name: 'Login',
      component: Login,
      options: {
        ...routerOptions,
        title: '登录',
      },
    },
    {
      name: 'Register',
      component: Register,
      options: {
        ...routerOptions,
        title: '注册',
      },
    },
    {
      name: 'ForgetPassword',
      component: ForgetPassword,
      options: {
        ...routerOptions,
        title: '忘记密码',
      },
    },
    {
      name: 'Web',
      component: Web,
      options: {
        headerShown: false,
      },
    },
    {
      name: 'Index',
      component: Index,
      options: {
        headerShown: false,
      },
    },
    {
      name: 'MeTabs',
      component: MeTabs,
      options: {
        ...routerOptions,
        headerBackVisible: false,
        title: '',
        headerLeft: () => (<Back></Back>)
      },
    },
    {
      name: 'IndexForTab',
      component: IndexForTab,
      options: {
        headerShown: false,
      },
    },
  ]
  return routerList.map((item) => (
    <Stack.Screen
      name={item.name}
      component={item.component}
      options={item.options}
      key={item.name}
    ></Stack.Screen>
  ))
}

export { getRouter }

 back/Index.js:

import React, { useState } from 'react'
import { View, Text, TouchableWithoutFeedback } from 'react-native'
import { useNavigation } from '@react-navigation/native'
import Icon from '../icon/Index'
import styles from './styles'

export default function Index(props) {
  const navigation = useNavigation()

  const handleBack = () => {
    console.log(1)
    navigation.goBack()
  }
  return (
    <TouchableWithoutFeedback onPress={handleBack}>
      <View style={styles.mBackWrap}>
        <Icon name="arrow" style={styles.mBackIcon}></Icon>
        <Text style={styles.mBackText}>返回</Text>
      </View>
    </TouchableWithoutFeedback>
  )
}

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

 

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

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

 

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


 

参考链接:

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

https://chat.xutongbao.top/


上一篇:DC电源模块关于多路输出的问题
下一篇:没有了
网友评论