wcandillon / react-native-redash

The React Native Reanimated and Gesture Handler Toolbelt
https://wcandillon.gitbook.io/redash/
MIT License
1.99k stars 117 forks source link

withPause cause crashing #477

Open yuhh8899 opened 2 years ago

yuhh8899 commented 2 years ago

I am currently using react-native 0.66.3, reanimated 2.3.0-beta.3 and redash 16.2.2. I followed your tutorial on start-react-native.dev (the high-order animations video) and my program just crash with error: Cannot read property '__nodeId' of undefined, here are the code: image

I am a newbie in reanimated so i can't know where the problem was I am running on android 12 emulator

yuhh8899 commented 2 years ago

Even with the code on the github it still crash image

branaust commented 2 years ago

+1

tsdmrfth commented 2 years ago

+1

andrewdang17 commented 2 years ago

+1 with the latest release 16.3.0

wcandillon commented 2 years ago

it should be fixed part of 16.3.0, could you send me an example to reproduce the issue?

andrewdang17 commented 2 years ago

it should be fixed part of 16.3.0, could you send me an example to reproduce the issue?

@wcandillon here is how I am using it. I am also on reanimated 2.8.0 and it crashes without any stacktrace in the console.


import React, { useEffect } from 'react'
import { StyleSheet, View } from 'react-native'
import { colors } from 'app/theme'
import { withPause } from "react-native-redash"
import Animated, { Easing, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated'
import { SCREEN_WIDTH } from 'app/constants'

const ProgressBar = ({ loading }) => {
  const paused = useSharedValue(true)
  const progressWidth = useSharedValue(0)
  const progressStyle = useAnimatedStyle(() => {
    return {
      width: withTiming(progressWidth.value, {
        duration: 10000,
        easing: Easing.linear
      })
    }
  })

  useEffect(() => {
    if (loading) {
      progressWidth.value = withPause(SCREEN_WIDTH, paused)
    } else {
      paused.value = true
    }
  }, [loading])

  return (
    <View style={[styles.base]}>
      <Animated.View style={[progressStyle, styles.base, styles.progress]} />
    </View>
  )
}

export default ProgressBar
andrewdang17 commented 2 years ago

@wcandillon I might be using it wrong cause when I wrap the value with withTiming() as shown in the docs it doesn't crash but the animation doesn't work.

withPause(withTiming(SCREEN_WIDTH, paused))
wcandillon commented 2 years ago

shouldn't it be:

withPause(withTiming(SCREEN_WIDTH), paused)
andrewdang17 commented 2 years ago

@wcandillon nevermind I figured it out! I forgot to set paused.value to false 🤦 . It does crash still though if not used with withTiming on my end.

wcandillon commented 2 years ago

Which other function other than withTiming would you like to use it for? I use it with withRepeat for instance.

andrewdang17 commented 2 years ago

@wcandillon I don't need it with any other function, withTiming works perfectly for my case. I was just putting withTiming in the useAnimatedStyle instead of where the new shared value is being set