0

I'm trying to shoot the log only once, I tried using useEffect it fires only one but cancels my animation, can someone help me?

use reanimated 2 (typescript), maybe useMemo can help? without useEffect it shoot 8 times

return block([
  cond(
    isBack, call([], () => console.log('online'),  //here
  ),
     cond(....

and I Tried:

const [online,setOnline] = useState(false);
   ......

  useEffect(() => {
    if (online) {
      console.log("online!");
      return
    }
  }, [online]);

  ......

  return block([
  cond(
    isBack, call([], () => setOnline(true),  //here
  ),
     cond(....animation......

I believe it is canceling my animation because my animation uses some states.

but I don't want to edit my animation because there is a huge alternative?

maybe some return within the useeffect that to continue the animation loop?

I tried this as well:

useEffect(() => {
  let isCancelled = false;
  stopClock(clock);
  const runAsync = () => {return block([
          cond(
            isBack, call([], () => {setOnline(online +1),console.log('abc')}),
          ),
            cond(
              
              eq(gesture, State.ACTIVE),
              [
                cond(
                
                  clockRunning(clock),
                  [stopClock(clock), set(offset, state.position)],
                  set(state.position, diffClamp(add(offset, value), 0, 1))
                ),
                
              ],
              [
                cond(not(clockRunning(clock)), [
                  set(state.time, 0),
                  set(state.finished, 0),
                  set(config.toValue, point),
                  startClock(clock),
              
                ]),
                
                spring(clock, state, config),
                cond(and(eq(state.finished, 1,), clockRunning(clock)), [
        
                  set(isBack, point),
                  stopClock(clock),
                  set(offset, 0),
                  
                ]),
              
              ]
            ),
            state.position,
         
          ])};

          runAsync();

  return () => {
    isCancelled = true;
    
  };
}, [online]);

but my another script need the return on function, because in this way my another script can't check de state values on main function.

Burn Jack
  • 1
  • 2

0 Answers0