Skip to content
This repository has been archived by the owner on Jan 30, 2021. It is now read-only.

Use nativeEvent.layout in onLayout, instead of buggy measureInWindow #42

Closed

Conversation

JelteF
Copy link

@JelteF JelteF commented Sep 6, 2018

On Android with Expo (and its default translucent statusbar) the touchesTop
detection is incorrect. This is because measureInWindow has a bug that makes
its behaviour inconsistent with other platforms:
facebook/react-native#19497.

This PR replaces the usage of measureInWindow with the use of
nativeEvent.layout (which is the workaround provided in the issue linked
above). This makes touchesTop detection work for android correctly so
forceInset={{ top: 'always' }} doesn't have to be provided anymore.

@brentvatne brentvatne self-requested a review September 19, 2018 14:43
Copy link
Member

@brentvatne brentvatne left a comment

Choose a reason for hiding this comment

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

this approach will not work for the reason described in comments. if you can provide a repro case for the bug you're encountering it'll help us to examine other solutions!

if (!this.view) return;
if (!info || !info.nativeEvent) {
if (this.props.onLayout) {
this.props.onLayout(...args);
Copy link
Member

Choose a reason for hiding this comment

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

we need to pass the info var through here. i'd call it e or event instead, also. to see why it's necessary to pass it through have a look at https://snack.expo.io/@notbrent/thrilled-pizza - run it and then look at logs, you'll see this:

screen shot 2018-09-19 at 12 26 43 pm

}
let realY = winY;
let realX = winX;
let realY = layout.y;
Copy link
Member

Choose a reason for hiding this comment

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

this will give the x and y relative to the container, not the x and y relative to the entire window. we need to know the x/y relative to the window because that's the only way to know if the container overlaps with a safe area. again run https://snack.expo.io/@notbrent/thrilled-pizza and notice the logs for "nested" show x/y of 0,0 despite it not being in the top left of the screen.

@JelteF
Copy link
Author

JelteF commented Dec 10, 2018

Sorry for not responding to this earlier. The repro case is simply:

  • use an android device with Expo (create-react-native-app)
  • put anything at the top of the screen (for instance a element)
  • see that the status bar is on top of the text

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants