-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix: Book travel - Book travel animation becomes blank while RHP is dismissed #50199
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ import {NavigationContainerRefContext, NavigationContext} from '@react-navigatio | |
| import type {AnimationObject, LottieViewProps} from 'lottie-react-native'; | ||
| import LottieView from 'lottie-react-native'; | ||
| import type {ForwardedRef} from 'react'; | ||
| import React, {forwardRef, useContext, useEffect, useState} from 'react'; | ||
| import React, {forwardRef, useContext, useEffect, useRef, useState} from 'react'; | ||
| import {InteractionManager, View} from 'react-native'; | ||
| import type DotLottieAnimation from '@components/LottieAnimations/types'; | ||
| import useAppState from '@hooks/useAppState'; | ||
|
|
@@ -18,7 +18,8 @@ type Props = { | |
| shouldLoadAfterInteractions?: boolean; | ||
| } & Omit<LottieViewProps, 'source'>; | ||
|
|
||
| function Lottie({source, webStyle, shouldLoadAfterInteractions, ...props}: Props, ref: ForwardedRef<LottieView>) { | ||
| function Lottie({source, webStyle, shouldLoadAfterInteractions, ...props}: Props, forwardedRef: ForwardedRef<LottieView>) { | ||
| const animationRef = useRef<LottieView | null>(null); | ||
| const appState = useAppState(); | ||
| const {splashScreenState} = useSplashScreenStateContext(); | ||
| const styles = useThemeStyles(); | ||
|
|
@@ -79,19 +80,20 @@ function Lottie({source, webStyle, shouldLoadAfterInteractions, ...props}: Props | |
| return unsubscribeNavigationBlur; | ||
| }, [browser, navigationContainerRef, navigator]); | ||
|
|
||
| // If user is being navigated away, let pause the animation to prevent memory leak. | ||
| // see issue: https://github.com/Expensify/App/issues/36645 | ||
| useEffect(() => { | ||
| if (!animationRef.current || !hasNavigatedAway) { | ||
| return; | ||
| } | ||
| animationRef?.current?.pause(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the browser |
||
| }, [hasNavigatedAway]); | ||
|
|
||
| // If the page navigates to another screen, the image fails to load, app is in background state, animation file isn't ready, or the splash screen isn't hidden yet, | ||
| // we'll just render an empty view as the fallback to prevent | ||
| // 1. memory leak, see issue: https://github.com/Expensify/App/issues/36645 | ||
| // 2. heavy rendering, see issues: https://github.com/Expensify/App/issues/34696 and https://github.com/Expensify/App/issues/47273 | ||
| // 3. lag on react navigation transitions, see issue: https://github.com/Expensify/App/issues/44812 | ||
| if ( | ||
| hasNavigatedAway || | ||
| isError || | ||
| appState.isBackground || | ||
| !animationFile || | ||
| splashScreenState !== CONST.BOOT_SPLASH_STATE.HIDDEN || | ||
| (!isInteractionComplete && shouldLoadAfterInteractions) | ||
| ) { | ||
| // 1. heavy rendering, see issues: https://github.com/Expensify/App/issues/34696 and https://github.com/Expensify/App/issues/47273 | ||
| // 2. lag on react navigation transitions, see issue: https://github.com/Expensify/App/issues/44812 | ||
| if (isError || appState.isBackground || !animationFile || splashScreenState !== CONST.BOOT_SPLASH_STATE.HIDDEN || (!isInteractionComplete && shouldLoadAfterInteractions)) { | ||
| return <View style={[aspectRatioStyle, props.style]} />; | ||
| } | ||
|
|
||
|
|
@@ -100,7 +102,15 @@ function Lottie({source, webStyle, shouldLoadAfterInteractions, ...props}: Props | |
| // eslint-disable-next-line react/jsx-props-no-spreading | ||
| {...props} | ||
| source={animationFile} | ||
| ref={ref} | ||
| ref={(ref) => { | ||
| if (typeof forwardedRef === 'function') { | ||
| forwardedRef(ref); | ||
| } else if (forwardedRef && 'current' in forwardedRef) { | ||
| // eslint-disable-next-line no-param-reassign | ||
| forwardedRef.current = ref; | ||
| } | ||
| animationRef.current = ref; | ||
| }} | ||
| style={[aspectRatioStyle, props.style]} | ||
| webStyle={{...aspectRatioStyle, ...webStyle}} | ||
| onAnimationFailure={() => setIsError(true)} | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.