Search code examples
headerreact-nativereact-navigation

ReactNative: navigationOptions not working


Not able to change the headertitle or headerstyle using the navigationOptions function. Also used defaultNavigationOptions instead but still not working.

    const CategoriesScreen = props => {
  const renderGridItem = itemData => {
    return (
      <TouchableOpacity
        style={styles.gridItem}
        onPress={() => {
          props.navigation.navigate({ routeName: 'CategoryMeals' });
        }}
      >
        <View>
          <Text>{itemData.item.title}</Text>
        </View>
      </TouchableOpacity>
    );
  };

  return (
    <FlatList
      keyExtractor={(item, index) => item.id}
      data={CATEGORIES}
      renderItem={renderGridItem}
      numColumns={2}
    />
  );
};

CategoriesScreen.navigationOptions = {
  headerTitle: 'Meal Categories',
  headerStyle: {
    backgroundColor: Platform.OS === 'android' ? Colors.primaryColor : ''
  },
  headerTintColor: Platform.OS === 'android' ? 'white' : Colors.primaryColor
};

Any help would be appreciated. Thanks


Solution

  • You are going wrong as you should use the title instead of headerTitle like

      title: 'Meal Categories',
    

    instead of

      headerTitle: 'Meal Categories',