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

Fix screen jump from Welcome screen to Demo screen #2744

Merged
merged 2 commits into from
Aug 15, 2024

Conversation

lindboe
Copy link
Contributor

@lindboe lindboe commented Aug 14, 2024

Please verify the following:

  • yarn test jest tests pass with new tests, if relevant
  • yarn lint eslint checks pass with new code, if relevant
  • yarn format:check prettier checks pass with new code, if relevant
  • README.md (or relevant documentation) has been updated with your changes

Describe your PR

To fix Android build issue, depends on #2745.

Android and iOS were both jumping when navigating from the Welcome screen to the Demo Showroom screen (although in different directions, and Android was less severe).

I found this issue was prevented when we use the StatusBar component on the WelcomeScreen as well as DemoShowroom, so converted WelcomeScreen to use the built-in Screen component, which includes StatusBar.

However, that raised another issue: when navigating from the Login screen to the Welcome screen, the "fixed" Screen component on Welcome screen would render the wrong height; it would be slightly too tall.

The useHeader hook was using useEffect, which means that header height wouldn't be set until the second render, so when the KeyboardAvoidingView on on Welcome screen tried to render, it had the wrong height information and rendered the wrong size.

By using useLayoutEffect, we make sure the header height is set before any of the screen components try to render, fixing the issue.

Platform Before After
Android
AndroidJumpBefore.mp4
AndroidJumpAfter.mp4
iOS
ScreenJumpIOSBefore.mp4
ScreenJumpiOSAfter.mp4

@lindboe lindboe changed the base branch from v10 to lindboe/fix-expo-template August 14, 2024 21:51
Base automatically changed from lindboe/fix-expo-template to v10 August 14, 2024 21:54
@lindboe lindboe marked this pull request as ready for review August 14, 2024 21:58
Android and iOS were both jumping when navigating from the Welcome
screen to the Demo Showroom screen (although in different directions,
and Android was less severe).

I found this issue was prevented when we use the `<StatusBar>` component
on the WelcomeScreen as well as DemoShowroom, so converted WelcomeScreen
to use the built-in `Screen` component, which includes `<StatusBar>`.

However, that raised another issue: when navigating from the Login
screen to the Welcome screen, the "fixed" `Screen` component on Welcome
screen would render the wrong height; it would be slightly too tall.
This didn't occur when changing presets and reloading the app via fast
refresh, which indicated to me that it was likely due to a state change
that was using the "old" screen dimensions from Login screen, but then
was incorrect after another state change took place on the Welcome
screen.

I found that was correct: the `useHeader` hook was using useEffect,
which means that header height wouldn't be set until the second render,
so when the KeyboardAvoidingView on on Welcome screen tried to render,
it had the wrong height information and rendered the wrong size.

By using `useLayoutEffect`, we make sure the header height is set before
any of the screen components try to render, fixing the issue.
causes a lint error in a generated project, so fixed
Copy link
Contributor

@frankcalise frankcalise left a comment

Choose a reason for hiding this comment

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

Great investigation! So much smoother

React.useEffect(() => {
// To avoid a visible header jump when navigating between screens, we use
// `useLayoutEffect`, which will apply the settings before the screen renders.
React.useLayoutEffect(() => {
Copy link
Member

Choose a reason for hiding this comment

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

YES!

@lindboe lindboe merged commit 02a5680 into v10 Aug 15, 2024
1 check passed
@lindboe lindboe deleted the lindboe/fix-screen-jump branch August 15, 2024 03:17
@infinitered-circleci
Copy link

🎉 This PR is included in version 10.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

4 participants