about summary refs log tree commit diff
path: root/src/lib/custom-animations
diff options
context:
space:
mode:
authorSamuel Newman <mozzius@protonmail.com>2024-09-25 18:28:10 +0100
committerGitHub <noreply@github.com>2024-09-25 18:28:10 +0100
commit498f957a1d9c702c3d2d6cfc5c175b0659ec99c0 (patch)
tree900bc1dc4dc2986a52d3d32ba856bb26e2c06346 /src/lib/custom-animations
parent47301661f786f032c5b2f20773a5ee9041fed64e (diff)
downloadvoidsky-498f957a1d9c702c3d2d6cfc5c175b0659ec99c0.tar.zst
Use scale animation for tabs (#5483)
* fix passing PressableScale oPressIn prop

* use PressableScale for tabs
Diffstat (limited to 'src/lib/custom-animations')
-rw-r--r--src/lib/custom-animations/PressableScale.tsx27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/lib/custom-animations/PressableScale.tsx b/src/lib/custom-animations/PressableScale.tsx
index 68315a978..d6eabf8b2 100644
--- a/src/lib/custom-animations/PressableScale.tsx
+++ b/src/lib/custom-animations/PressableScale.tsx
@@ -1,5 +1,5 @@
 import React from 'react'
-import {Pressable, PressableProps} from 'react-native'
+import {Pressable, PressableProps, StyleProp, ViewStyle} from 'react-native'
 import Animated, {
   cancelAnimation,
   runOnJS,
@@ -16,14 +16,17 @@ const DEFAULT_TARGET_SCALE = isNative || isTouchDevice ? 0.98 : 1
 export function PressableScale({
   targetScale = DEFAULT_TARGET_SCALE,
   children,
+  contentContainerStyle,
+  onPressIn,
+  onPressOut,
   ...rest
-}: {targetScale?: number} & Exclude<
-  PressableProps,
-  'onPressIn' | 'onPressOut'
->) {
+}: {
+  targetScale?: number
+  contentContainerStyle?: StyleProp<ViewStyle>
+} & Exclude<PressableProps, 'onPressIn' | 'onPressOut'>) {
   const scale = useSharedValue(1)
 
-  const style = useAnimatedStyle(() => ({
+  const animatedStyle = useAnimatedStyle(() => ({
     transform: [{scale: scale.value}],
   }))
 
@@ -32,22 +35,24 @@ export function PressableScale({
       accessibilityRole="button"
       onPressIn={e => {
         'worklet'
-        if (rest.onPressIn) {
-          runOnJS(rest.onPressIn)(e)
+        if (onPressIn) {
+          runOnJS(onPressIn)(e)
         }
         cancelAnimation(scale)
         scale.value = withTiming(targetScale, {duration: 100})
       }}
       onPressOut={e => {
         'worklet'
-        if (rest.onPressOut) {
-          runOnJS(rest.onPressOut)(e)
+        if (onPressOut) {
+          runOnJS(onPressOut)(e)
         }
         cancelAnimation(scale)
         scale.value = withTiming(1, {duration: 100})
       }}
       {...rest}>
-      <Animated.View style={style}>{children as React.ReactNode}</Animated.View>
+      <Animated.View style={[animatedStyle, contentContainerStyle]}>
+        {children as React.ReactNode}
+      </Animated.View>
     </Pressable>
   )
 }