about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorSamuel Newman <mozzius@protonmail.com>2024-05-30 07:36:07 +0300
committerGitHub <noreply@github.com>2024-05-30 05:36:07 +0100
commitfba4a9ca023b5acfe8ae51e1839d4e5e305ea967 (patch)
tree084e3b417710c764b97973e2cac2e2e7146653d2 /src
parente48f8e15eb24320b74be579eb414c36fed24149b (diff)
downloadvoidsky-fba4a9ca023b5acfe8ae51e1839d4e5e305ea967.tar.zst
scale down FAB on press (#4259)
Diffstat (limited to 'src')
-rw-r--r--src/view/com/util/fab/FABInner.tsx50
1 files changed, 30 insertions, 20 deletions
diff --git a/src/view/com/util/fab/FABInner.tsx b/src/view/com/util/fab/FABInner.tsx
index a01756da0..ccf2f31db 100644
--- a/src/view/com/util/fab/FABInner.tsx
+++ b/src/view/com/util/fab/FABInner.tsx
@@ -1,6 +1,6 @@
 import React, {ComponentProps} from 'react'
 import {StyleSheet, TouchableWithoutFeedback} from 'react-native'
-import Animated from 'react-native-reanimated'
+import Animated, {useAnimatedStyle, withTiming} from 'react-native-reanimated'
 import {useSafeAreaInsets} from 'react-native-safe-area-context'
 import {LinearGradient} from 'expo-linear-gradient'
 
@@ -9,6 +9,7 @@ import {useMinimalShellMode} from 'lib/hooks/useMinimalShellMode'
 import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
 import {clamp} from 'lib/numbers'
 import {gradients} from 'lib/styles'
+import {useInteractionState} from '#/components/hooks/useInteractionState'
 
 export interface FABProps
   extends ComponentProps<typeof TouchableWithoutFeedback> {
@@ -20,21 +21,28 @@ export function FABInner({testID, icon, ...props}: FABProps) {
   const insets = useSafeAreaInsets()
   const {isMobile, isTablet} = useWebMediaQueries()
   const {fabMinimalShellTransform} = useMinimalShellMode()
+  const {
+    state: pressed,
+    onIn: onPressIn,
+    onOut: onPressOut,
+  } = useInteractionState()
 
-  const size = React.useMemo(() => {
-    return isTablet ? styles.sizeLarge : styles.sizeRegular
-  }, [isTablet])
-  const tabletSpacing = React.useMemo(() => {
-    return isTablet
-      ? {right: 50, bottom: 50}
-      : {
-          right: 24,
-          bottom: clamp(insets.bottom, 15, 60) + 15,
-        }
-  }, [insets.bottom, isTablet])
+  const size = isTablet ? styles.sizeLarge : styles.sizeRegular
+
+  const tabletSpacing = isTablet
+    ? {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} {...props}>
+    <TouchableWithoutFeedback
+      testID={testID}
+      onPressIn={onPressIn}
+      onPressOut={onPressOut}
+      {...props}>
       <Animated.View
         style={[
           styles.outer,
@@ -42,13 +50,15 @@ export function FABInner({testID, icon, ...props}: FABProps) {
           tabletSpacing,
           isMobile && fabMinimalShellTransform,
         ]}>
-        <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 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>
   )