use PressableScale for animation (#5541)

This commit is contained in:
Samuel Newman
2024-09-30 21:49:53 +03:00
committed by GitHub
parent 587c0c6257
commit 9ca2928aac
2 changed files with 33 additions and 44 deletions
+2 -1
View File
@@ -1,7 +1,8 @@
import React from 'react' import React from 'react'
import {View} from 'react-native' import {View} from 'react-native'
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
import {FABInner, FABProps} from './FABInner' import {FABInner, FABProps} from './FABInner'
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
export const FAB = (_opts: FABProps) => { export const FAB = (_opts: FABProps) => {
const {isDesktop} = useWebMediaQueries() const {isDesktop} = useWebMediaQueries()
+31 -43
View File
@@ -1,9 +1,10 @@
import React, {ComponentProps} from 'react' import React, {ComponentProps} from 'react'
import {StyleSheet, TouchableWithoutFeedback} from 'react-native' import {StyleSheet, TouchableWithoutFeedback} from 'react-native'
import Animated, {useAnimatedStyle, withTiming} from 'react-native-reanimated' import Animated from 'react-native-reanimated'
import {useSafeAreaInsets} from 'react-native-safe-area-context' import {useSafeAreaInsets} from 'react-native-safe-area-context'
import {LinearGradient} from 'expo-linear-gradient' import {LinearGradient} from 'expo-linear-gradient'
import {PressableScale} from '#/lib/custom-animations/PressableScale'
import {useHaptics} from '#/lib/haptics' import {useHaptics} from '#/lib/haptics'
import {useMinimalShellFabTransform} from '#/lib/hooks/useMinimalShellTransform' import {useMinimalShellFabTransform} from '#/lib/hooks/useMinimalShellTransform'
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries' import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
@@ -11,7 +12,6 @@ import {clamp} from '#/lib/numbers'
import {gradients} from '#/lib/styles' import {gradients} from '#/lib/styles'
import {isWeb} from '#/platform/detection' import {isWeb} from '#/platform/detection'
import {useHapticsDisabled} from '#/state/preferences' import {useHapticsDisabled} from '#/state/preferences'
import {useInteractionState} from '#/components/hooks/useInteractionState'
export interface FABProps export interface FABProps
extends ComponentProps<typeof TouchableWithoutFeedback> { extends ComponentProps<typeof TouchableWithoutFeedback> {
@@ -25,11 +25,6 @@ export function FABInner({testID, icon, onPress, ...props}: FABProps) {
const playHaptic = useHaptics() const playHaptic = useHaptics()
const isHapticsDisabled = useHapticsDisabled() const isHapticsDisabled = useHapticsDisabled()
const fabMinimalShellTransform = useMinimalShellFabTransform() const fabMinimalShellTransform = useMinimalShellFabTransform()
const {
state: pressed,
onIn: onPressIn,
onOut: onPressOut,
} = useInteractionState()
const size = isTablet ? styles.sizeLarge : styles.sizeRegular const size = isTablet ? styles.sizeLarge : styles.sizeRegular
@@ -37,43 +32,36 @@ export function FABInner({testID, icon, onPress, ...props}: FABProps) {
? {right: 50, bottom: 50} ? {right: 50, bottom: 50}
: {right: 24, bottom: clamp(insets.bottom, 15, 60) + 15} : {right: 24, bottom: clamp(insets.bottom, 15, 60) + 15}
const scale = useAnimatedStyle(() => ({
transform: [{scale: withTiming(pressed ? 0.95 : 1)}],
}))
return ( return (
<TouchableWithoutFeedback <Animated.View
testID={testID} style={[
onPressIn={onPressIn} styles.outer,
onPressOut={onPressOut} size,
onPress={e => { tabletSpacing,
playHaptic('Light') isMobile && fabMinimalShellTransform,
setTimeout( ]}>
() => { <PressableScale
onPress?.(e) testID={testID}
}, onPress={e => {
isHapticsDisabled ? 0 : 75, playHaptic('Light')
) setTimeout(
}} () => {
{...props}> onPress?.(e)
<Animated.View },
style={[ isHapticsDisabled ? 0 : 75,
styles.outer, )
size, }}
tabletSpacing, targetScale={0.9}
isMobile && fabMinimalShellTransform, {...props}>
]}> <LinearGradient
<Animated.View style={scale}> colors={[gradients.blueLight.start, gradients.blueLight.end]}
<LinearGradient start={{x: 0, y: 0}}
colors={[gradients.blueLight.start, gradients.blueLight.end]} end={{x: 1, y: 1}}
start={{x: 0, y: 0}} style={[styles.inner, size]}>
end={{x: 1, y: 1}} {icon}
style={[styles.inner, size]}> </LinearGradient>
{icon} </PressableScale>
</LinearGradient> </Animated.View>
</Animated.View>
</Animated.View>
</TouchableWithoutFeedback>
) )
} }