fix(android): prevent double status bar offset in legacy non edge-to-edge mode#3970
Open
gusgushz wants to merge 1 commit intosoftware-mansion:mainfrom
Open
fix(android): prevent double status bar offset in legacy non edge-to-edge mode#3970gusgushz wants to merge 1 commit intosoftware-mansion:mainfrom
gusgushz wants to merge 1 commit intosoftware-mansion:mainfrom
Conversation
…edge mode In legacy mode (edgeToEdgeEnabled=false), applyDecorViewTopInsetIfNeeded was applying topInset as paddingTop to the toolbar even though the system already positions the toolbar below the status bar. This caused the toolbar height to be inflated, resulting in unexpected bottom padding when headerShown=true. Fix detects legacy mode by comparing toolbar's Y position on screen with the status bar inset. In edge-to-edge the toolbar starts at y=0, in legacy it starts at y=statusBarInset, so paddingTop is only applied in edge-to-edge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
While investigating an unexpected bottom padding issue when using
headerShown=truewith
edgeToEdgeEnabled=false, I found that it had already been fixed in the4.25.0-beta.1release (thecorrectedHeight/correctedOffsetYlogic was removedfrom
Screen.onLayout).After upgrading to the beta to confirm the fix, I encountered a new issue: the toolbar
height was being inflated by the status bar height when running in legacy non
edge-to-edge mode (
edgeToEdgeEnabled=false), causing the header to render visuallylarger than expected when
headerShown=true.The root cause was in
applyDecorViewTopInsetIfNeededinsideCustomToolbar. Inlegacy mode,
onApplyWindowInsetsis never triggered by the system, so this fallbackruns on
onAttachedToWindow. It was applyingtopInsetaspaddingTopto the toolbarunconditionally, even though in legacy mode the system already positions the toolbar
below the status bar, making that padding redundant and causing double offset.
Changes
Modified
applyDecorViewTopInsetIfNeededinCustomToolbar.ktto detect whetherthe app is running in edge-to-edge mode before applying
paddingTopto the toolbar.The detection compares the toolbar's Y position on screen with the status bar inset:
y=0→toolbarTopOnScreen < statusBarInset→ padding is applied ✅y=statusBarInset→ condition is false → padding is skipped ✅Before & after - visual documentation:
Test plan:
Reproduced and fixed with:
react-native: 0.84.1react-native-screens: 4.25.0-beta.1@react-navigation/native-stack: ^7.12.0Steps to reproduce:
edgeToEdgeEnabled=falseingradle.propertiesreact-native-screens: 4.25.0-beta.1headerShown=trueTested scenarios after fix:
edgeToEdgeEnabled=false+ NavBar buttons +headerShown=true/false✅edgeToEdgeEnabled=false+ Gesture navigation +headerShown=true/false✅edgeToEdgeEnabled=true+ NavBar buttons +headerShown=true/false✅edgeToEdgeEnabled=true+ Gesture navigation +headerShown=true/false✅Here is my repository with the app in which i tested the change:
https://github.com/gusgushz/rn_screens_test
This fix was authored by @gusgushz with assistance from Claude
(Anthropic) for root cause analysis and debugging.
Related
react-native: 0.85.2,react-native-screens: 4.25.0-beta.1@react-navigation/native-stack: ^7.14.12And finally im still learning, so i did´t make more tests on different devices (with newer versions of Android or different screen sizes) but i hope this helps.
Greetings to all the mantainers and contributors