0

I am upgrading my code from React Navigation 4 to 5. For a stackNavigator I had the following configuration before.

const whiteNavOptions = {
  headerStyle: {
    backgroundColor: "white"
  }
}

const transNavOptions = {
  headerTransparent: true,
  headerTintColor: "white",
}

const VenuesNavigator = createStackNavigator(
  {
    Venuefy: VenuefyScreen,
    VenueDetail: {
      screen: VenueDetailScreen,
      navigationOptions: transNavOptions,
    },
    Sorting: SortingScreen,
  }, {
  defaultNavigationOptions: whiteNavOptions
}
);

So now I am trying to map it like this in React Navigation 5

const VenuesStackNavigator = createStackNavigator();
const VenuesNavigator = () => {
  return <VenuesStackNavigator.Navigator screenOptions={whiteNavOptions}>
    <VenuesStackNavigator.Screen name="Venuefy" component={VenuefyScreen} options={VenuesScreenOptions} />
    <VenuesStackNavigator.Screen name="VenueDetail" component={VenueDetailScreen} options={VenueDetailScreenOptions}/>
    <VenuesStackNavigator.Screen name="Sorting" component={SortingScreen} />
  </VenuesStackNavigator.Navigator>
}

I have set default screenOptions to whiteNavOptions. Now I want to set the transNavOptions to the VenueDetailScreen only. Maybe something like this:

<VenuesStackNavigator.Screen name="VenueDetail" component={VenueDetailScreen} options={VenueDetailScreenOptions} screenOptions={transNavOptions}/>

It's is not clear from the documentation, how can I do that? I know I must be missing something obvious but any pointer to that obvious would be much appreciated x)

1 Answers1

1

documentation has this example

function StackScreen() {
  return (
    <Stack.Navigator>
      <Stack.Screen
        name="Home"
        component={HomeScreen}
        options={{
          title: 'My home',
          headerStyle: {
            backgroundColor: '#f4511e',
          },
          headerTintColor: '#fff',
          headerTitleStyle: {
            fontWeight: 'bold',
          },
        }}
      />
    </Stack.Navigator>
  );
}

which means headerStyle is basically accepting styleProps so in backgroundColor pass in some opacity like described here

or i think you should be able to do something like this

declare style obj
const transparentStyles = {
    backgroundColor: 'white',
    opacity: 0.5,
}

and pass it to screen options like

...
function StackScreen() {
  return (
    <Stack.Navigator>
      <Stack.Screen
        name="Home"
        component={HomeScreen}
        options={{
          title: 'My home',
          headerStyle: transparentStyles,
          headerTintColor: '#fff',
          headerTitleStyle: {
            fontWeight: 'bold',
          },
        }}
      />
    </Stack.Navigator>
  );
}

But if i were you i would be simply creating custom header JSX component so i have full controll of everything

Andris Laduzans
  • 408
  • 4
  • 14