1

I had a Header component that I used as a static appbar in React Native. Now I'm trying to include a StackNavigator to be easier to manage the transitions between screens.

My problem is that I can't include my Header component in the StackNavigator header. My current code and result are shown below:

const APPBAR_HEIGHT = Platform.OS === 'ios' ? 44 : 56;

const GiftNavigator = StackNavigator(
{
  All: {
    screen: GiftListSection,
    navigationOptions: {
      tabBarLabel: 'All',
    }
  },
  Reclaim: {
    screen: GiftReclaimSection,
    navigationOptions: {
      tabBarLabel: 'Reclaim',
    }
  }
}, {
  headerMode: 'float',
    header: (
        <View style={{ height: APPBAR_HEIGHT }}>
            <Header />
        </View>
    )
});

Screenshot from the Header loaded

Note that the Header is not loaded. It is just a blank space. How can I load my Header component to the StackNavigator header? If I load my own Header, will it contain the back button from the default Navigator header?

2 Answers 2

5

You can try like this:

export default class YourScreen extends Component {

  static navigationOptions = {
    header: <YourHeader/>,
  };
  ...
}

or:

const GiftNavigator = StackNavigator(
{
  All: {
    screen: GiftListSection,
    navigationOptions: {
      tabBarLabel: 'All',
      header: <YourHeader/>,
    }
  },
  Reclaim: {
    screen: GiftReclaimSection,
    navigationOptions: {
      tabBarLabel: 'Reclaim',
      header: <YourHeader/>,
    }
  }
}

Hope this can help you!

Sign up to request clarification or add additional context in comments.

Comments

3

You can hide the default react navigation header entirely by using the headerMode: 'none' option and handle header on your own for each component.

Or you could use the header property and load your own custom header component:

navigationOptions: {
  header: props => <CustomHeader {...props} />,
},

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.