react-native-screens icon indicating copy to clipboard operation
react-native-screens copied to clipboard

headerRight randomly position the component incorrectly

Open lnmunhoz opened this issue 4 years ago • 78 comments

I was testing the createNativeStackNavigation and ended up having this random issue where the component rendered by headerRight is being positioned incorrectly sometimes. There's nothing special in my code, I am just rendering a <Button> from react-native.

Here's the source code: https://github.com/lnmunhoz/react-native-experiments/blob/master/react-navigation-examples/examples/NativeNavigation.tsx.

Kapture 2020-03-21 at 20 56 50

Update

The issue also happens when the headerLargeTitle is false.

image

lnmunhoz avatar Mar 21 '20 13:03 lnmunhoz

I cannot repro your issue either on a simulator or physical device. Upgrade packages to the newest version. Is the issue still present then? If so, please try to write which steps to take for the issue to occur.

WoLewicki avatar Mar 25 '20 11:03 WoLewicki

Yes, I just tried again and the issue is still present. I did a fresh install and the issue persisted. Have you tried the repo I've sent?

The steps are simple:

  • Clone the repo
  • cd repo/react-navigation-examples
  • yarn && yarn start
  • And then open in iOS simulator

To create the stack I am using createNativeStackNavigator from react-native-screens/native-stack.

I created a snack to reproduce but also not being able to make it happen there:

  • https://snack.expo.io/@lnmunhoz/react-navigation-v5-native-screen-bug

The thing is, I am using a stack created by createNativeStackNavigator inside a stack from createStackNavigator.

I wanted to have parts of my app using the native stack for more simple screens where I don't need to manipulate the header too much, and others the js based stack so I can migrate incrementally.

Is that an issue or should work fine?

lnmunhoz avatar Mar 25 '20 11:03 lnmunhoz

I cloned your project and also made a bare react-native project. The issue exists only while opening it through Expo Client. This means that the version of RNScreens in the current Expo Client is having the bug since it has RNScreens in version 2.0.0-alpha.12. Can you repro it that way to prove if it is right?

WoLewicki avatar Mar 25 '20 13:03 WoLewicki

@lnmunhoz can I close it then? Is your issue solved?

WoLewicki avatar Mar 26 '20 13:03 WoLewicki

Let me try to reproduce one more time so we can figure out why it was happening.

I will update here in a couple hours.

lnmunhoz avatar Mar 26 '20 18:03 lnmunhoz

This is happens in bare RN project as well, so I doubt it has anything to do with Expo

Deepp0925 avatar Mar 26 '20 23:03 Deepp0925

@Deepp0925 does it happen with the newest RNScreens version: 2.4.0?

WoLewicki avatar Mar 27 '20 11:03 WoLewicki

Yes sir

Deepp0925 avatar Mar 27 '20 23:03 Deepp0925

I have a workaround if it's a blocker for anyone here https://github.com/react-navigation/react-navigation/issues/6746#issuecomment-583897436:

As a workaround I show the Icon after a few ms:

const [shouldRenderIcon, setShouldRenderIcon] = useState(false)

useEffect(() => {
const nbr = setTimeout(() => setShouldRenderIcon(true), 200)
return () => clearTimeout(nbr)
}, [])

return shouldRenderIcon ? <MyIcon /> : null

markmssd avatar Mar 28 '20 22:03 markmssd

I can also confirm that this bug still happens on [email protected] and [email protected].

lucasmotta avatar Apr 05 '20 11:04 lucasmotta

Hey @WoLewicki, do you want me to setup a sample project, showing this issue? Here's some screenshots demonstrating the problem:

This first one, is just adding a 44x44 Touchable button as the headerRight - you can see it's quite far to the left. Screenshot 2020-04-30 at 17 45 37

If I inspect the element, you can see it's 44x44: Screenshot 2020-04-30 at 17 51 30

If I add a marginRight: -20, it does "fix" the alignment, but not the issue itself. Screenshot 2020-04-30 at 17 46 22

Now if I inspect the element, you can see it's only 24px wide, so almost half of the button is cropped and not easy to tap. Screenshot 2020-04-30 at 17 46 44

It feels like this extra 20px on the right side added by the native wrapper is causing the problem - if that space would be removed entirely the problem would be solved. The back button works this way if you inspect it:

Screenshot 2020-04-30 at 17 54 17

lucasmotta avatar Apr 30 '20 16:04 lucasmotta

Using a custom compontent in headerCenter is affected by the same bug/problem...

sbeigel avatar May 02 '20 09:05 sbeigel

@osdnk

WoLewicki avatar May 08 '20 11:05 WoLewicki

same for me

FrankFundel avatar May 25 '20 17:05 FrankFundel

This happens almost everytime I start the app, this really should be fixed.

FrankFundel avatar May 27 '20 13:05 FrankFundel

I believe it is the same issue as #322. Can you try the workaround submitted there and see if it works correctly?

WoLewicki avatar May 28 '20 12:05 WoLewicki

same for me

AlexSmirnov9107 avatar Jun 03 '20 15:06 AlexSmirnov9107

same for me too

SmirnovM91 avatar Jun 03 '20 16:06 SmirnovM91

This is happening to me also with headerCenter and headerRight only in iOS, my custom component is wrongly positioned. It only displays correctly when the default back button is present.

immortalx avatar Jun 16 '20 09:06 immortalx

Same problem Im having

const Stack = createNativeStackNavigator(); const AccountsScreen = () => { return <Stack.Navigator screenOptions={(props) => ({ headerRight: () => <HeaderRight {...props} />,
})}> <Stack.Screen name="Balances" component={Balances} /> ...

interface Props { navigation?: NavigationContainerRef; } export const HeaderRight = (props: Props) => { const dispatch = useDispatch(); const {navigation} = props; return <TouchableOpacity onPress={() => dispatch(lock())}> <Text style={{color: 'red'}}>test</Text> </TouchableOpacity> }

Sometimes the Text gets pushed off screen in ios, RN .62 with latest React Navigation. Screen Shot 2020-06-25 at 4 44 38 PM

Screen Shot 2020-06-25 at 4 43 40 PM

zyofeng avatar Jun 25 '20 04:06 zyofeng

Same here using Expo SDK v38, which relies on ~2.9.0.

ortigozamatias avatar Jun 29 '20 21:06 ortigozamatias

+1

FrankFundel avatar Jul 17 '20 10:07 FrankFundel

Closed https://github.com/software-mansion/react-native-screens/issues/571 for this as seems to be related. I shouldn't be the one to dictate priority but this seems really important, it's really not ideal to have production apps experience this.

Also I have a feeling mentioning expo is not relevant, I experience this consistently without.

kyle-ssg avatar Aug 06 '20 13:08 kyle-ssg

Can you check if #600 resolves the issue and if it does not introduce other unwanted behaviors?

WoLewicki avatar Aug 12 '20 12:08 WoLewicki

#600 should be ready now. Can you check if it does not destroy any of your behavior? @kyle-ssg @lnmunhoz

WoLewicki avatar Aug 17 '20 14:08 WoLewicki

@WoLewicki I've been testing #600 in my app (where I could occasionally reproduce the issue) and haven't seen it since I installed your PR. Haven't seen any sort of regression either.

So, from my perspective, it looks good!

spencercarli avatar Aug 17 '20 18:08 spencercarli

@FrankFundel can you check if #613 resolves your problem introduced in #600? Also, @spencercarli can you check if it does not destroy the good behavior of #600? @kyle-ssg @lnmunhoz @matt-oakes can you check if #600 + #613 resolve the bugs you discovered?

WoLewicki avatar Aug 25 '20 09:08 WoLewicki

This has been on my todo for a few days, I'll prioritise testing this in the evening @WoLewicki, thanks for letting me know again.

kyle-ssg avatar Aug 25 '20 09:08 kyle-ssg

@WoLewicki this does not fix my problem :(

FrankFundel avatar Aug 25 '20 11:08 FrankFundel

@FrankFundel can you provide a repo/snack that shows the problem then?

WoLewicki avatar Aug 25 '20 12:08 WoLewicki