Rahul
Rahul

Reputation: 21

onPress event on headerLeft under navigation.setOptions is not working

onPress event on headerLeft under navigation.options is not working it is still performing default functionality not overriding my onPress functionality for this. When I am clicking on back button it is moving to some random page not the previous page from which I am coming, so that's why I am trying to modify default functionality but it is not picking my onPress function.

  useLayoutEffect(() => {
    navigation.setOptions({
      headerLeft: () => <Text onPress={()=>{console.log('back');}}>Back</Text>,
      headerRight: () => <DetailsHeader isFavorite={detail.FVT_YN === "Y"} onSharePress={() => _onSharePress(detail)} onFavoritePress={() => _onFavoritePress(detail)} />,
    });
  }, [navigation, detail]);

In my app there are multiple bottom navigation tabs are there, so if I remove all other tabs and only keep one home tab then it is working fine, but when multiple tabs are there then back button move to any other tab page. I have tried several ways but none of them working, so please help me find out the solution of this.

Upvotes: 0

Views: 426

Answers (1)

Saul Lee
Saul Lee

Reputation: 149

Try this:

  useLayoutEffect(() => {
    navigation.setOptions({
      headerLeft: () => <Pressable onPress={()=>{console.log('back');}}><Text>Back</Text></Pressable>,
      headerRight: () => <DetailsHeader isFavorite={detail.FVT_YN === "Y"} onSharePress={() => _onSharePress(detail)} onFavoritePress={() => _onFavoritePress(detail)} />,
    });
  }, [navigation, detail]);

Upvotes: 0

Related Questions