about summary refs log tree commit diff
path: root/src/view/com/util/anim/TriggerableAnimated.tsx
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2024-11-23 16:20:24 -0800
committerGitHub <noreply@github.com>2024-11-23 16:20:24 -0800
commit32bf8122e8c8a0fbadd53b8a015cfbc9014519a2 (patch)
tree55bd24596e6fadadbf4326b26e3d14e418c5c7bb /src/view/com/util/anim/TriggerableAnimated.tsx
parent523d1f01a51c0e85e49916fb42b204f7004ffac1 (diff)
parentb4d07c4112b9a62b5380948051aa4a7fd391a2d4 (diff)
downloadvoidsky-32bf8122e8c8a0fbadd53b8a015cfbc9014519a2.tar.zst
Merge branch 'main' into main
Diffstat (limited to 'src/view/com/util/anim/TriggerableAnimated.tsx')
-rw-r--r--src/view/com/util/anim/TriggerableAnimated.tsx74
1 files changed, 0 insertions, 74 deletions
diff --git a/src/view/com/util/anim/TriggerableAnimated.tsx b/src/view/com/util/anim/TriggerableAnimated.tsx
deleted file mode 100644
index 97605fb46..000000000
--- a/src/view/com/util/anim/TriggerableAnimated.tsx
+++ /dev/null
@@ -1,74 +0,0 @@
-import React from 'react'
-import {Animated, StyleProp, View, ViewStyle} from 'react-native'
-
-import {useAnimatedValue} from '#/lib/hooks/useAnimatedValue'
-
-type CreateAnimFn = (interp: Animated.Value) => Animated.CompositeAnimation
-type FinishCb = () => void
-
-interface TriggeredAnimation {
-  start: CreateAnimFn
-  style: (
-    interp: Animated.Value,
-  ) => Animated.WithAnimatedValue<StyleProp<ViewStyle>>
-}
-
-export interface TriggerableAnimatedRef {
-  trigger: (anim: TriggeredAnimation, onFinish?: FinishCb) => void
-}
-
-type TriggerableAnimatedProps = React.PropsWithChildren<{}>
-
-type PropsInner = TriggerableAnimatedProps & {
-  anim: TriggeredAnimation
-  onFinish: () => void
-}
-
-export const TriggerableAnimated = React.forwardRef<
-  TriggerableAnimatedRef,
-  TriggerableAnimatedProps
->(function TriggerableAnimatedImpl({children, ...props}, ref) {
-  const [anim, setAnim] = React.useState<TriggeredAnimation | undefined>(
-    undefined,
-  )
-  const [finishCb, setFinishCb] = React.useState<FinishCb | undefined>(
-    undefined,
-  )
-  React.useImperativeHandle(ref, () => ({
-    trigger(v: TriggeredAnimation, cb?: FinishCb) {
-      setFinishCb(() => cb) // note- wrap in function due to react behaviors around setstate
-      setAnim(v)
-    },
-  }))
-  const onFinish = () => {
-    finishCb?.()
-    setAnim(undefined)
-    setFinishCb(undefined)
-  }
-  return (
-    <View key="triggerable">
-      {anim ? (
-        <AnimatingView anim={anim} onFinish={onFinish} {...props}>
-          {children}
-        </AnimatingView>
-      ) : (
-        children
-      )}
-    </View>
-  )
-})
-
-function AnimatingView({
-  anim,
-  onFinish,
-  children,
-}: React.PropsWithChildren<PropsInner>) {
-  const interp = useAnimatedValue(0)
-  React.useEffect(() => {
-    anim?.start(interp).start(() => {
-      onFinish()
-    })
-  })
-  const animStyle = anim?.style(interp)
-  return <Animated.View style={animStyle}>{children}</Animated.View>
-}