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

Add scroll-based animation to HeaderBackground #4706

Merged
merged 4 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ exports[`CreateWalletAccountSelect renders 1`] = `
</RNSVGSvgView>
</BVLinearGradient>,
<RCTScrollView
collapsable={false}
contentContainerStyle={
{
"paddingBottom": 0,
Expand All @@ -217,16 +218,14 @@ exports[`CreateWalletAccountSelect renders 1`] = `
"paddingTop": 64,
}
}
onScroll={[Function]}
scrollEventThrottle={0.0001}
style={
[
{
"height": 1334,
"width": 750,
},
{
"padding": 0,
},
]
{
"height": 1334,
"padding": 0,
"width": 750,
}
}
>
<View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ exports[`CurrencyNotificationComponent should render with loading props 1`] = `
</RNSVGSvgView>
</BVLinearGradient>,
<RCTScrollView
collapsable={false}
contentContainerStyle={
{
"paddingBottom": 0,
Expand All @@ -217,16 +218,14 @@ exports[`CurrencyNotificationComponent should render with loading props 1`] = `
"paddingTop": 64,
}
}
onScroll={[Function]}
scrollEventThrottle={0.0001}
style={
[
{
"height": 1334,
"width": 750,
},
{
"padding": 0,
},
]
{
"height": 1334,
"padding": 0,
"width": 750,
}
}
>
<View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ exports[`CurrencySettings should render 1`] = `
</RNSVGSvgView>
</BVLinearGradient>,
<RCTScrollView
collapsable={false}
contentContainerStyle={
{
"paddingBottom": 0,
Expand All @@ -217,16 +218,14 @@ exports[`CurrencySettings should render 1`] = `
"paddingTop": 64,
}
}
onScroll={[Function]}
scrollEventThrottle={0.0001}
style={
[
{
"height": 1334,
"width": 750,
},
{
"padding": 0,
},
]
{
"height": 1334,
"padding": 0,
"width": 750,
}
}
>
<View>
Expand Down
34 changes: 16 additions & 18 deletions src/__tests__/scenes/__snapshots__/SettingsScene.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ exports[`MyComponent should render Locked SettingsOverview 1`] = `
</RNSVGSvgView>
</BVLinearGradient>,
<RCTScrollView
collapsable={false}
contentContainerStyle={
{
"paddingBottom": 0,
Expand All @@ -217,16 +218,14 @@ exports[`MyComponent should render Locked SettingsOverview 1`] = `
"paddingTop": 64,
}
}
onScroll={[Function]}
scrollEventThrottle={0.0001}
style={
[
{
"height": 1334,
"width": 750,
},
{
"padding": 0,
},
]
{
"height": 1334,
"padding": 0,
"width": 750,
}
}
>
<View>
Expand Down Expand Up @@ -3644,6 +3643,7 @@ exports[`MyComponent should render UnLocked SettingsOverview 1`] = `
</RNSVGSvgView>
</BVLinearGradient>,
<RCTScrollView
collapsable={false}
contentContainerStyle={
{
"paddingBottom": 0,
Expand All @@ -3652,16 +3652,14 @@ exports[`MyComponent should render UnLocked SettingsOverview 1`] = `
"paddingTop": 64,
}
}
onScroll={[Function]}
scrollEventThrottle={0.0001}
style={
[
{
"height": 1334,
"width": 750,
},
{
"padding": 0,
},
]
{
"height": 1334,
"padding": 0,
"width": 750,
}
}
>
<View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ exports[`TransactionDetailsScene should render 1`] = `
</RNSVGSvgView>
</BVLinearGradient>,
<RCTScrollView
collapsable={false}
contentContainerStyle={
{
"paddingBottom": 92,
Expand All @@ -172,16 +173,14 @@ exports[`TransactionDetailsScene should render 1`] = `
"paddingTop": 64,
}
}
onScroll={[Function]}
scrollEventThrottle={0.0001}
style={
[
{
"height": 1334,
"width": 750,
},
{
"padding": 11,
},
]
{
"height": 1334,
"padding": 11,
"width": 750,
}
}
>
<View>
Expand Down Expand Up @@ -1882,6 +1881,7 @@ exports[`TransactionDetailsScene should render with negative nativeAmount and fi
</RNSVGSvgView>
</BVLinearGradient>,
<RCTScrollView
collapsable={false}
contentContainerStyle={
{
"paddingBottom": 92,
Expand All @@ -1890,16 +1890,14 @@ exports[`TransactionDetailsScene should render with negative nativeAmount and fi
"paddingTop": 64,
}
}
onScroll={[Function]}
scrollEventThrottle={0.0001}
style={
[
{
"height": 1334,
"width": 750,
},
{
"padding": 11,
},
]
{
"height": 1334,
"padding": 11,
"width": 750,
}
}
>
<View>
Expand Down
14 changes: 10 additions & 4 deletions src/components/common/SceneWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { getDefaultHeaderHeight } from '@react-navigation/elements'
import { useNavigation } from '@react-navigation/native'
import * as React from 'react'
import { useMemo } from 'react'
import { Animated, ScrollView, StyleSheet, useWindowDimensions, View } from 'react-native'
import { Animated, StyleSheet, useWindowDimensions, View } from 'react-native'
import Reanimated from 'react-native-reanimated'
import { EdgeInsets, useSafeAreaFrame, useSafeAreaInsets } from 'react-native-safe-area-context'

import { useSceneDrawerState } from '../../state/SceneDrawerState'
import { useSceneScrollHandler } from '../../state/SceneScrollState'
import { useSelector } from '../../types/reactRedux'
import { NavigationBase } from '../../types/routerTypes'
import { OverrideDots } from '../../types/Theme'
Expand Down Expand Up @@ -129,6 +131,9 @@ export function SceneWrapper(props: SceneWrapperProps): JSX.Element {
const notificationHeight = theme.rem(4)
const headerBarHeight = getDefaultHeaderHeight(frame, false, 0)

// If the scene has scroll, this will be required for tabs and/or header animation
const handleScroll = useSceneScrollHandler(scroll && (hasTabs || hasHeader))

const renderScene = (safeAreaInsets: EdgeInsets, keyboardAnimation: Animated.Value | undefined, trackerValue: number): JSX.Element => {
// If function children, the caller handles the insets and overscroll
const hasKeyboardAnimation = keyboardAnimation != null
Expand Down Expand Up @@ -172,18 +177,19 @@ export function SceneWrapper(props: SceneWrapperProps): JSX.Element {
backgroundGradientStart={backgroundGradientStart}
backgroundGradientEnd={backgroundGradientEnd}
/>
<MaybeScrollView
<MaybeAnimatedScrollView
when={scroll && !hasKeyboardAnimation}
style={[layoutStyles, { padding }]}
keyboardShouldPersistTaps={keyboardShouldPersistTaps}
contentContainerStyle={insetStyles}
onScroll={hasTabs || hasHeader ? handleScroll : () => {}}
>
<MaybeView when={!scroll && !hasKeyboardAnimation} style={[styles.sceneContainer, layoutStyles, maybeInsetStyles, { padding }]}>
{isFuncChildren ? children(info) : children}
{hasNotifications ? <NotificationView navigation={navigation} /> : null}
{renderDrawer == null ? null : <SceneDrawer info={info}>{renderDrawer}</SceneDrawer>}
</MaybeView>
</MaybeScrollView>
</MaybeAnimatedScrollView>
</MaybeAnimatedView>
)
}
Expand Down Expand Up @@ -218,5 +224,5 @@ const styles = StyleSheet.create({
})

const MaybeAnimatedView = maybeComponent(Animated.View)
const MaybeScrollView = maybeComponent(ScrollView)
const MaybeAnimatedScrollView = maybeComponent(Reanimated.ScrollView)
const MaybeView = maybeComponent(View)
27 changes: 19 additions & 8 deletions src/components/navigation/HeaderBackground.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
import * as React from 'react'
import { StyleSheet, View } from 'react-native'
import { StyleSheet } from 'react-native'
import LinearGradient from 'react-native-linear-gradient'
import Animated, { interpolate, SharedValue, useAnimatedStyle } from 'react-native-reanimated'
import { BlurView } from 'rn-id-blurview'

import { useSceneScrollContext } from '../../state/SceneScrollState'
import { styled } from '../hoc/styled'
import { useTheme } from '../services/ThemeContext'
import { DividerLine } from '../themed/DividerLine'
import { MAX_TAB_BAR_HEIGHT } from '../themed/MenuTabs'

export const HeaderBackground = () => {
export const HeaderBackground = (props: any) => {
const theme = useTheme()

const { scrollY } = useSceneScrollContext()

return (
<HeaderBackgroundContainerView>
<HeaderBackgroundContainerView scrollY={scrollY}>
<BlurView blurType={theme.isDark ? 'dark' : 'light'} style={StyleSheet.absoluteFill} overlayColor="#00000000" />
<HeaderLinearGradient colors={theme.headerBackground} start={theme.headerBackgroundStart} end={theme.headerBackgroundEnd} />
<DividerLine colors={theme.headerOutlineColors} />
</HeaderBackgroundContainerView>
)
}

const HeaderBackgroundContainerView = styled(View)({
...StyleSheet.absoluteFillObject,
alignItems: 'stretch',
justifyContent: 'flex-end'
})
const HeaderBackgroundContainerView = styled(Animated.View)<{ scrollY: SharedValue<number> }>(() => ({ scrollY }) => [
{
...StyleSheet.absoluteFillObject,
alignItems: 'stretch',
justifyContent: 'flex-end',
opacity: 0
},
useAnimatedStyle(() => ({
opacity: interpolate(scrollY.value, [0, MAX_TAB_BAR_HEIGHT], [0, 1])
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: MAX_TAB_BAR_HEIGHT might be the wrong constant to use in the header. Do we have a header height constant somewhere?

}))
])

const HeaderLinearGradient = styled(LinearGradient)({
flex: 1
Expand Down
Loading
Loading