Skip to content

If view extends beyond window boundaries, do not add that difference to the insets#177

Merged
janicduplessis merged 1 commit intoAppAndFlow:masterfrom
TheAlmightyBob:FixAndroidRotation
Mar 7, 2021
Merged

If view extends beyond window boundaries, do not add that difference to the insets#177
janicduplessis merged 1 commit intoAppAndFlow:masterfrom
TheAlmightyBob:FixAndroidRotation

Conversation

@TheAlmightyBob
Copy link
Copy Markdown
Contributor

Fixes #176

This may not be the ideal fix... I'm open to other options. Perhaps it should consider the scenario of the view extending beyond the window boundaries to simply be "invalid" and return null?? Perhaps there's something I'm missing in the intended behavior here?

Summary

The problem is described in detail in #176. The short version is that, during rotation on Android there's a transitional phase where the window's dimensions have been updated according to the rotation but the view's have not, so the view might extend beyond the height or width of the window. The current calculations in getSafeAreaInsets were adding this difference in dimensions to the normal insets and returning extremely large insets.

Test Plan

I have not tested with a device/app that actually renders under a cutaway or home/back buttons and uses the safe area insets to lay out elements accordingly. This change seems pretty simple/safe in that regard to me, but I'm trusting reviewers/maintainers to say if it looks risky to them. (the status of the "example" app is unclear to me... it doesn't look like it actually uses react-native-safe-area-context??)

I have tested with a "normal" device/app, and verified that rotating the device no longer produces super-large insets.

(this code could probably use a comment, but I wasn't sure if I understood it well enough to write a useful one...)

Copy link
Copy Markdown
Collaborator

@janicduplessis janicduplessis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine, I think the insets should never be bigger than the element it is insetting. This seems consistent with the behavior I've observed on iOS too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Large incorrect insets during rotation on Android

2 participants