-
-
Notifications
You must be signed in to change notification settings - Fork 211
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
SafeAreaView flickers with incorrect initial insets on Android #364
Comments
Can you provide a minimal repro? |
@jacobp100 I discovered this issue in the expensify app in the PR Expensify/App#15778, will work on getting a minimal repro in the example app soon. |
Sorry I didn’t realise it was you 🤣 I’m not too familiar with the android side of things. Are the insets available when the view mounts? |
I think they are, but wrongly have a bottom value, which might be what causes the flicker. I noticed by logging initialWindowMetrics. Might be related to the flags the app window has initially. |
Oh interesting. I wonder if android does the same thing of reporting only the safe area that overlaps with the view itself |
It flickers both android ios, on production build, development build, and inside expo. I use react navigation and only few of my views utilize SafeAreaView. |
It may be connected with this issue - #186, which @jacobp100 by some reason closed without explanation on how it could be solved or workarounded. |
I closed it because there’s not enough information to reproduce it |
I'm seeing the same behavior with |
You need a full repo showing it because the config you put in your android manifest affects the behaviour of the library |
@jacobp100 Interesting! What exact parameters from the Android manifest file do affect the behavior of this lib? EDIT: what easy changes could I try before following your suggestion of providing a reproducer? |
I don't work on Android anymore - so I don't remember We have a ticket for this #349 - it would be really useful if someone is able to help out with this - because I won't be able to |
@janicduplessis did you manage to fix it? If yes, could you share how you did it? |
Hello guys!
Update:
In the <SafeAreaProvider>
<HomeScreen onLayout={hideSplashScreen} />
<StatusBar style="auto" translucent />
</SafeAreaProvider> The <SafeAreaView onLayout={onLayout} style={[styles.flexFit, theme.container]}>
<ScrollView
contentContainerStyle={[styles.container]}
showsVerticalScrollIndicator={false}
keyboardDismissMode="interactive"
>
...
</ScrollView>
</SafeAreaView> Screen_Recording_20240320_223732_Tip.Split.Calculator.mp4 |
In my case problem was with incorrect initialWindowMetrics from the lib.
Second rerender, after layout
SafeAreaProvider placed almost on the root. const Providers = ({ children }: PropsWithChildren) => (
<SafeArea.Provider>
<GestureHandlerRootView className="flex-1">
<CacheLibraryProvider>
<NavigationContainer
theme={NAVIGATION_THEME}
onStateChange={onNavigationStateChange}
ref={setNavigationContainerRef}
>
<BottomSheetModalProvider>
<ModalProvider>
<NoInternetToast.Provider shouldShow={$$(!$isOnline.value)}>
<LogoutProvider>{children}</LogoutProvider>
</NoInternetToast.Provider>
</ModalProvider>
</BottomSheetModalProvider>
<Toast />
</NavigationContainer>
</CacheLibraryProvider>
</GestureHandlerRootView>
<OrientationLocker orientation="PORTRAIT" />
</SafeArea.Provider>
);
const App = ({
isHeadless,
}: {
/**
* ios specific props from firebase messaging https://rnfirebase.io/messaging/usage#background-application-state
*/
isHeadless?: boolean;
}) => {
useEffect(() => {
Analytics.triggerEventByName('AppLaunched');
//TODO: Rewrite the code to avoid using this hack
void restartWatchIfStarted();
SplashScreen.hide();
}, []);
useAntifraudService();
if (isHeadless) {
return null;
}
return (
<Providers>
<StatusBar backgroundColor={'#151515'} />
<View className="absolute inset-0 bg-gray-700" />
<NoInternetToast.Ui />
<ConditionalRouting />
</Providers>
);
};
// eslint-disable-next-line import/no-default-export
export default withIAPContext(Sentry.wrap(App)); |
Anyone have any advice on how to solve this? Seeing this only on Android, Expo v50 / expo-router / react-navigation. |
Our workaround is to set initial metrics for the lib as a fullscreen |
Is there a solution for this issue? |
This happens on iOS for me too, not just Android. |
Here's my workaround. Please note that it works best if you have a translucent status bar but opaque navigation bar. I haven't tested this with other cases. import { Platform } from 'react-native'
import { initialWindowMetrics } from 'react-native-safe-area-context'
// Workaround for the issue causing `initialWindowMetrics` to have incorrect
// bottom inset value on some Android devices
const getInitialWindowMetrics = () => {
if (Platform.OS !== 'android' || initialWindowMetrics == null) {
return initialWindowMetrics
}
const { frame, insets } = initialWindowMetrics
return {
frame: { ...frame, height: frame.height + insets.top },
insets: { ...insets, bottom: 0 }
}
}
export const initialSafeAreaWindowMetrics = getInitialWindowMetrics() return (
<SafeAreaProvider initialMetrics={initialSafeAreaWindowMetrics}>
<StatusBar translucent backgroundColor="transparent" />
{/* ... */}
</SafeAreaProvider>
) |
Facing the same issue on Pixel 9 pro XL |
This doesn't seem to work for me. Copied the code, an using like this
And I still get flickering |
This seems to happen with translucent status bar, when it is initially rendered on app start.
The text was updated successfully, but these errors were encountered: