gpt4 book ai didi

react-native - navigation.setOptions 不会改变

转载 作者:行者123 更新时间:2023-12-04 00:57:16 31 4
gpt4 key购买 nike

我正在使用 react-navigator 创建屏幕,但是当屏幕打开时我无法更改标题栏的选项

我的代码(App.js):

function App() {
return (
<NavigationContainer>
<Stack.Navigator screenOptions={{
headerTitleAlign: 'center',
headerTitle: props => <LogoTitle {...props} />,
headerRight: props => <HeaderRight {...props} />,
headerStyle: {
backgroundColor: '#F46A0D'
},
headerTintColor: '#fff',
}}>
<Stack.Screen name="Search" component={SearchScreen}/>
</Stack.Navigator>
</NavigationContainer>
);
}

export default App;

我的 SearchScreen.js:
import React from 'react'
import { Text, View } from 'react-native'
import { Button } from 'react-native-paper'

const SearchScreen = ({ navigation }) => {
navigation.setOptions = {
headerTitle: props => <TextInput {...props} placeholder="Search" placeholderTextColor="#FFFF" style={{
fontSize: 24
}}></TextInput>,
headerRight: props => <FontAwesome5 {...props} name={'search'} size={22} color="white" style={{ marginRight: 15 }}></FontAwesome5>
}
return (
<View>
</View>
)
}

export default SearchScreen;

在 navigation.setOptions 行中没有任何 react ,默认 screenOptions Stack.Navigator 继续

最佳答案

在路由文件上

<Stack.Screen
name="FuncName"
component={FuncName}
options={{
headerTitle:''
}}/>
在按下去 FuncName 屏幕
onPress={()=>{
props.navigation.navigate("FuncName",{title:"title"})
}}
然后通过 Prop 标题更改标题
const FuncName = (props) => {
useEffect(()=>{
props.navigation.setOptions({ headerTitle: props.route.params.title })
},[])
}

关于react-native - navigation.setOptions 不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61370729/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com