-
-
Notifications
You must be signed in to change notification settings - Fork 492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
headerRight randomly position the component incorrectly #432
Comments
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. |
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:
To create the stack I am using I created a snack to reproduce but also not being able to make it happen there: The thing is, I am using a stack created by 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? |
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? |
@lnmunhoz can I close it then? Is your issue solved? |
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. |
This is happens in bare RN project as well, so I doubt it has anything to do with Expo |
@Deepp0925 does it happen with the newest RNScreens version: 2.4.0? |
Yes sir |
I have a workaround if it's a blocker for anyone here react-navigation/react-navigation#6746 (comment):
|
I can also confirm that this bug still happens on |
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 If I inspect the element, you can see it's 44x44: If I add a Now if I inspect the element, you can see it's only It feels like this extra |
Using a custom compontent in headerCenter is affected by the same bug/problem... |
same for me |
This happens almost everytime I start the app, this really should be fixed. |
I believe it is the same issue as #322. Can you try the workaround submitted there and see if it works correctly? |
same for me |
same for me too |
This is happening to me also with headerCenter and headerRight only in iOS, my custom component is wrongly positioned. |
Same here using |
+1 |
this work for me:
|
I know this is not the best solution but it worked for me.
|
It's been years and this still hasn't been resolved... I found this issue after having trouble with the Here's the workaround: const [loaded, setLoaded] = useState(false)
useLayoutEffect(() => {
setLoaded(true)
}, [])
...
headerRight: loaded ? <CustomComponent /> : undefined |
@elliotfleming no need to do that, just put navigation.setOptions inside uselayouteffect |
@fukemy @elliotfleming Im facing the same issue. The above solution that you guys shared unfortunately not worked |
@jvfalco1 post your code here and images to see the problem |
The following doesn't work. As well as
Screenshare.-.2023-10-28.5_18_09.PM.mp4 |
use settimeout 100 then its will work |
indeed, the following seems to be working:
|
Still happening on |
I just created a POC app I noticed this as well with the release app and it only occurs on first render of a modal but fixes itself after I close and reopen the modal
|
One thing I tested which appears to work is that you can use
Example usage
|
Same thing for us, the issue was happening here because we were changing the button size to add more information whenever user filtered something, keeping the same size that it was first rendered seems to solve the problem. |
Hi guys! I'm sorry this still happens to you, even after so many years this issue has been created 😕 |
(cc @sn-will @trajano @thomasttvo @13Ksii @fukemy @jvfalco1 @elliotfleming @DavidManookyan @nicastelo @FrancescoBonizzi @Johan-dutoit @jadar - bumping everyone that has posted here since 2022) |
Hi @tboba! Unfortunately I couldn't reproduce it in a deterministic way, and I ended up by making a custom header component, that way I never noticed the issue again! |
@FrancescoBonizzi I understand, thanks! Even if that bug happened for you not in a deterministic way and it was still occurring quite often in the repro, could you show it? |
@tboba This is a simple two page navigator that will display the settings screen on button press. I am able to reproduce the problem in Expo Go. https://github.com/trajano/nav-mvce import { StatusBar } from 'expo-status-bar';
import { Pressable, View } from 'react-native';
import { NavigationContainer, useNavigation } from '@react-navigation/native';
import { NativeStackScreenProps, createNativeStackNavigator } from "@react-navigation/native-stack";
import { Button, Icon, Text } from '@rneui/themed';
import { useCallback } from 'react';
type RootStackParamList = {
Home: undefined;
Settings: undefined;
};
type RootStackScreenProps<T extends keyof RootStackParamList> =
NativeStackScreenProps<RootStackParamList, T>;
const HomeScreen = ({ navigation }: RootStackScreenProps<"Home">) => {
const showSettings = useCallback(() => { navigation.navigate("Settings") }, [navigation]);
return <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}><Button onPress={showSettings}>show settings</Button></View>
}
const SettingsScreen = ({ navigation }: RootStackScreenProps<"Settings">) => {
return <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}><Text>Settings</Text></View>
}
const RootStack = createNativeStackNavigator<RootStackParamList>();
const RootNavigator = () => {
const navigation = useNavigation();
const headerRight = useCallback(() => (<Pressable onPress={() => { navigation.goBack() }}><Icon name="close" /></Pressable >), [navigation]);
return (<RootStack.Navigator screenOptions={{ headerShown: false }}>
<RootStack.Screen name="Home" component={HomeScreen} />
<RootStack.Screen name="Settings" component={SettingsScreen}
options={{
presentation: "modal",
animation: "slide_from_bottom",
headerShown: true,
headerRight: headerRight
}} />
</RootStack.Navigator>)
}
export default function App() {
return (
<NavigationContainer>
<RootNavigator />
<StatusBar style='auto' />
</NavigationContainer>
);
} npx expo install @react-navigation/native @react-navigation/native-stack @rneui/themed@4.0.0-rc.8 @rneui/base@4.0.0-rc.7 @react-navigation/stack |
Is that sufficient for a reproducer @tboba |
@trajano this should do the thing 👍 thanks! |
I am using |
This does not appear to work for me. I also tried setting a fixed height. In this one https://github.com/trajano/nav-mvce/pull/1/files I tried to implement your change @trevorpfiz (one thing of note, I am not fully sure yet, but it seems you need to put the view style OUTSIDE the class. Also I don't use But one of the things I noticed was the X gets rendered a few milliseconds after the navigation completes showing the card but only on the first one. I suspect it is around that time where things break, also ideally the Also @tboba shouldn't the issue be re-opened since there's a test for it now. |
pretty sure that this solution works after I implement it correctly. |
Turns out a fixed width doesn’t fix the issue if the header title is not static. |
@trajano Yeah, I've tested your workaround and I have some comments regarding it:
I'll reopen this issue since this bug still occurs, but please answer the questions I've asked above 😄 |
Getting the same using Expo Router (SDK 50), none of the above work arounds fix it for me. |
@tboba I get it on the |
I'm also getting this issue on Expo Router ~3.4.7 (SDK 50.0.0). It went away for me when moving more logic about the header into the layout instead of setting it on mount in the useEffect hook. Like this:
Might work for some of you! |
I was testing the
createNativeStackNavigation
and ended up having this random issue where the component rendered byheaderRight
is being positioned incorrectly sometimes. There's nothing special in my code, I am just rendering a<Button>
fromreact-native
.Here's the source code: https://github.com/lnmunhoz/react-native-experiments/blob/master/react-navigation-examples/examples/NativeNavigation.tsx.
Update
The issue also happens when the
headerLargeTitle
isfalse
.The text was updated successfully, but these errors were encountered: