Skip to content
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

trigger="visible" behaviour is different on iOS than on Android when navigating screens using react-navigation #780

Open
Charles-Johnson opened this issue Jan 5, 2024 · 3 comments
Assignees

Comments

@Charles-Johnson
Copy link
Contributor

The VisibilityDetectingView component triggers actions when the screen that the hyperview component is in comes back into focus on an Android device but on iOS no actions are triggered when the screen comes back into focus.

After adding console.log(arguments); to the onMeasure method, when navigating away from the screen I had 5 views with trigger="visible",I observed the output on Android:

[0, 0, 360, 8, 0, 644.3333129882812]
[0, 0, 360, 288, 0, 781.6666870117188]
[0, 0, 312, 146.6666717529297, 24, 497.6666564941406]
[0, 0, 360, 1873.6666259765625, 0, 1069.6666259765625]
[0, 0, 360, 248, 0, 211.3333282470703]
[]
[]
[]
[]
[]

and on iOS:

[0, 37, 366, 127.66668701171875, 24, 462]
[0, 545.6666870117188, 414, 8, 0, 589.6666870117188]
[0, 638.6666870117188, 414, 288, 0, 682.6666870117188]
[0, 926.6666870117188, 414, 1869, 0, 970.6666870117188]
[0, 136, 414, 245, 0, 180]
[0, 37, 366, 127.66668701171875, 24, 462]
[0, 545.6666870117188, 414, 8, 0, 589.6666870117188]
[0, 638.6666870117188, 414, 288, 0, 682.6666870117188]
[0, 926.6666870117188, 414, 1869, 0, 970.6666870117188]
[0, 136, 414, 245, 0, 180]

So it looks like this.view.measure calls the callback (this.onMeasure) without any arguments on Android when views aren't in focus but does provide arguments for iOS regardless of whether the screen is in focus.

I'm not sure whether this is a bug in react-native or react-navigation or whether hyperview should handle this inconsistency.

I'm also not sure whether navigation actions should affect the visible trigger or whether a separate trigger should be implemented for navigation focus events.

In order to unblock my work, in my fork of this library, I'm going to try to add an event listener in the VisibilityDetectingView for focus events: https://reactnavigation.org/docs/function-after-focusing-screen/#triggering-an-action-with-a-focus-event-listener

@adamstep
Copy link
Contributor

adamstep commented Jan 5, 2024

@flochtililoch , any insights on desired behavior here or other approaches with the new navigation system (focus/blur events)?

@flochtililoch
Copy link
Collaborator

I would think the visible trigger should only trigger when the element is actually visible on screen. If an event causes an unfocused screen to reload, the elements that are in the unfocused view-pane should not trigger the visible behavior until their screen is focused again.
We can rely on the focus/blur event on the new navigation system, but we could probably amend the visible handler to behave correctly for unfocused screens.

@Charles-Johnson
Copy link
Contributor Author

I ended up not using the navigation focus event listener because it actually caused the hyperview screen to go blank if you navigate to a hyperview screen and immediately scroll down. I instead explicitly triggered events to update elements with trigger="on-event" and, in my fork, prevented the visibility action from being triggered when navigating screen on Android so that it is consistent with iOS

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

No branches or pull requests

3 participants