about summary refs log tree commit diff
path: root/src/view/com/util/fab/FABInner.tsx
diff options
context:
space:
mode:
authorSamuel Newman <mozzius@protonmail.com>2024-09-30 21:49:53 +0300
committerGitHub <noreply@github.com>2024-09-30 21:49:53 +0300
commit9ca2928aac4940eaad311ed8ccab8d33c45dc352 (patch)
treea6ba4236522bbc2fa699d6458b467fdaa044e91f /src/view/com/util/fab/FABInner.tsx
parent587c0c625752964d8ce64faf1d329dce3c834a5c (diff)
downloadvoidsky-9ca2928aac4940eaad311ed8ccab8d33c45dc352.tar.zst
use PressableScale for animation (#5541)
Diffstat (limited to 'src/view/com/util/fab/FABInner.tsx')
-rw-r--r--src/view/com/util/fab/FABInner.tsx74
1 files changed, 31 insertions, 43 deletions
diff --git a/src/view/com/util/fab/FABInner.tsx b/src/view/com/util/fab/FABInner.tsx
index 5d8aac81a..bc89ddb60 100644
--- a/src/view/com/util/fab/FABInner.tsx
+++ b/src/view/com/util/fab/FABInner.tsx
@@ -1,9 +1,10 @@
 import React, {ComponentProps} from 'react'
 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 {LinearGradient} from 'expo-linear-gradient'
 
+import {PressableScale} from '#/lib/custom-animations/PressableScale'
 import {useHaptics} from '#/lib/haptics'
 import {useMinimalShellFabTransform} from '#/lib/hooks/useMinimalShellTransform'
 import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
@@ -11,7 +12,6 @@ import {clamp} from '#/lib/numbers'
 import {gradients} from '#/lib/styles'
 import {isWeb} from '#/platform/detection'
 import {useHapticsDisabled} from '#/state/preferences'
-import {useInteractionState} from '#/components/hooks/useInteractionState'
 
 export interface FABProps
   extends ComponentProps<typeof TouchableWithoutFeedback> {
@@ -25,11 +25,6 @@ export function FABInner({testID, icon, onPress, ...props}: FABProps) {
   const playHaptic = useHaptics()
   const isHapticsDisabled = useHapticsDisabled()
   const fabMinimalShellTransform = useMinimalShellFabTransform()
-  const {
-    state: pressed,
-    onIn: onPressIn,
-    onOut: onPressOut,
-  } = useInteractionState()
 
   const size = isTablet ? styles.sizeLarge : styles.sizeRegular
 
@@ -37,43 +32,36 @@ export function FABInner({testID, icon, onPress, ...props}: FABProps) {
     ? {right: 50, bottom: 50}
     : {right: 24, bottom: clamp(insets.bottom, 15, 60) + 15}
 
-  const scale = useAnimatedStyle(() => ({
-    transform: [{scale: withTiming(pressed ? 0.95 : 1)}],
-  }))
-
   return (
-    <TouchableWithoutFeedback
-      testID={testID}
-      onPressIn={onPressIn}
-      onPressOut={onPressOut}
-      onPress={e => {
-        playHaptic('Light')
-        setTimeout(
-          () => {
-            onPress?.(e)
-          },
-          isHapticsDisabled ? 0 : 75,
-        )
-      }}
-      {...props}>
-      <Animated.View
-        style={[
-          styles.outer,
-          size,
-          tabletSpacing,
-          isMobile && fabMinimalShellTransform,
-        ]}>
-        <Animated.View style={scale}>
-          <LinearGradient
-            colors={[gradients.blueLight.start, gradients.blueLight.end]}
-            start={{x: 0, y: 0}}
-            end={{x: 1, y: 1}}
-            style={[styles.inner, size]}>
-            {icon}
-          </LinearGradient>
-        </Animated.View>
-      </Animated.View>
-    </TouchableWithoutFeedback>
+    <Animated.View
+      style={[
+        styles.outer,
+        size,
+        tabletSpacing,
+        isMobile && fabMinimalShellTransform,
+      ]}>
+      <PressableScale
+        testID={testID}
+        onPress={e => {
+          playHaptic('Light')
+          setTimeout(
+            () => {
+              onPress?.(e)
+            },
+            isHapticsDisabled ? 0 : 75,
+          )
+        }}
+        targetScale={0.9}
+        {...props}>
+        <LinearGradient
+          colors={[gradients.blueLight.start, gradients.blueLight.end]}
+          start={{x: 0, y: 0}}
+          end={{x: 1, y: 1}}
+          style={[styles.inner, size]}>
+          {icon}
+        </LinearGradient>
+      </PressableScale>
+    </Animated.View>
   )
 }