Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a custom HeaderTitle in React Navigation Stacknavigator?

Everytime i try to set a custom header in stacknavigation the error appears: "cant find variable View". When i replace the component with just a text, it works.

Error appears everytime i use the class "LogoTitle" for the headerTitel

tryied to use a const insted of a class, but dosent worked

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}});};
like image 587
Olli Avatar asked Dec 01 '25 05:12

Olli


1 Answers

you need to use header instead of headerTitle to be able to use View

const SignedIn = createStackNavigator ({
  TabNavigation:{screen: TabNavigation,
    navigationOptions: ({navigation}) => ({
      header: <LogoTitle navigation= {navigation} />,
    })
  },
})
like image 157
displayname Avatar answered Dec 05 '25 08:12

displayname



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!