-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
subtle avatar grow animation (#5480)
- Loading branch information
Showing
2 changed files
with
88 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react' | ||
import {StyleProp, View, ViewStyle} from 'react-native' | ||
import Animated, { | ||
Extrapolation, | ||
interpolate, | ||
SharedValue, | ||
useAnimatedStyle, | ||
} from 'react-native-reanimated' | ||
|
||
import {isIOS} from '#/platform/detection' | ||
import {usePagerHeaderContext} from '#/view/com/pager/PagerHeaderContext' | ||
|
||
export function GrowableAvatar({ | ||
children, | ||
style, | ||
}: { | ||
children: React.ReactNode | ||
style?: StyleProp<ViewStyle> | ||
}) { | ||
const pagerContext = usePagerHeaderContext() | ||
|
||
// pagerContext should only be present on iOS, but better safe than sorry | ||
if (!pagerContext || !isIOS) { | ||
return <View style={style}>{children}</View> | ||
} | ||
|
||
const {scrollY} = pagerContext | ||
|
||
return ( | ||
<GrowableAvatarInner scrollY={scrollY} style={style}> | ||
{children} | ||
</GrowableAvatarInner> | ||
) | ||
} | ||
|
||
function GrowableAvatarInner({ | ||
scrollY, | ||
children, | ||
style, | ||
}: { | ||
scrollY: SharedValue<number> | ||
children: React.ReactNode | ||
style?: StyleProp<ViewStyle> | ||
}) { | ||
const animatedStyle = useAnimatedStyle(() => ({ | ||
transform: [ | ||
{ | ||
scale: interpolate(scrollY.value, [-150, 0], [1.2, 1], { | ||
extrapolateRight: Extrapolation.CLAMP, | ||
}), | ||
}, | ||
], | ||
})) | ||
|
||
return ( | ||
<Animated.View | ||
style={[style, {transformOrigin: 'bottom left'}, animatedStyle]}> | ||
{children} | ||
</Animated.View> | ||
) | ||
} |
This file contains 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