Skip to content

Commit

Permalink
[C-5378] Fade in mobile screen content on load (#10369)
Browse files Browse the repository at this point in the history
Co-authored-by: amendelsohn <[email protected]>
  • Loading branch information
dharit-tan and amendelsohn authored Nov 6, 2024
1 parent b6d4155 commit ff7b841
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { useEffect, type ReactNode } from 'react'

import { Platform } from 'react-native'
import Animated, { FadeIn } from 'react-native-reanimated'

import { useScreenContext } from './ScreenContextProvider'

type ScreenPrimaryContentProps = {
Expand All @@ -23,5 +26,13 @@ export const ScreenPrimaryContent = (props: ScreenPrimaryContentProps) => {
setIsPrimaryContentReady(true)
}, [isScreenReady, setIsPrimaryContentReady])

return isScreenReady ? <>{children}</> : <>{skeleton ?? null}</>
// Note: not animating on Android because shadows are rendered natively behind the
// animated view and thus don't follow the animation.
return isScreenReady ? (
<Animated.View entering={Platform.OS === 'ios' ? FadeIn : undefined}>
{children}
</Animated.View>
) : (
<>{skeleton ?? null}</>
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { ReactNode } from 'react'

import { Platform } from 'react-native'
import Animated, { FadeIn } from 'react-native-reanimated'

import { useScreenContext } from './ScreenContextProvider'

type ScreenSecondaryContentProps = {
Expand All @@ -18,5 +21,16 @@ export const ScreenSecondaryContent = (props: ScreenSecondaryContentProps) => {
const { children, skeleton } = props
const { isPrimaryContentReady } = useScreenContext()

return <>{isPrimaryContentReady ? children : skeleton ?? null}</>
// Note: not animating on Android because shadows are rendered natively behind the
// animated view and thus don't follow the animation.
return isPrimaryContentReady ? (
<Animated.View
entering={Platform.OS === 'ios' ? FadeIn : undefined}
style={{ flex: 1 }}
>
{children}
</Animated.View>
) : (
<>{skeleton ?? null}</>
)
}

0 comments on commit ff7b841

Please sign in to comment.