如何在React Navigation Stacknavigator中制作自定义HeaderTitle?

问题描述 投票:0回答:1

每次我尝试在stacknavigation中设置自定义标头时,都会出现错误:“无法找到变量View”。当我用一个文本替换组件时,它的工作原理。

每次我使用headerTitel类“LogoTitle”时出现错误

试图使用const而不是类,但剂量工作

const TabNavigation = createMaterialTopTabNavigator({

  AllChats: { screen: AllChatsScreen, 
      navigationOptions: {
      tabBarLabel: "Chats",}}});

class LogoTitle extends React.Component {
  render() {
return (
  <Image
    source={require('./spiro.jpg')}
    style={{ width: 30, height: 30 }}/>);}}

const SignedInn = createStackNavigator({
  TabNavigation: {
screen: TabNavigation,
  },},{
  navigationOptions: {
headerTitle: <LogoTitle/>}})

export const createRootNavigator = (signedIn = false) => {
  return createSwitchNavigator(
{
  SignedIn: {
    screen: SignedInn}});};
react-native react-navigation
1个回答
0
投票

您需要使用标头而不是headerTitle才能使用View

const SignedIn = createStackNavigator ({
  TabNavigation:{screen: TabNavigation,
    navigationOptions: ({navigation}) => ({
      header: <LogoTitle navigation= {navigation} />,
    })
  },
})
© www.soinside.com 2019 - 2024. All rights reserved.