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>
-
)
-
}
参考链接:
https://reactnavigation.org/docs/native-stack-navigator
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhgfhgie
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
怎样阻止微信小程序自动打开
PHP中文网 06-13 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01