import { useRef, useEffect } from 'react';

// Most animations are considered 'interactions' - if there is no break
// in the interaction, then InteractionManager.runAfterInteractions() is
// never fired.
const DURATION_OFFSET = 100;

/**
 * Hook used to return a ref which should be applied to an animatable view created by
 * animatable that will trigger an animation to start/stop based on the condition passed.
 *
 * @param {boolean} condition a condition that when true will cause the animation to begin.
 * @param {string} animation the animation type see: react-native-animatable.
 * @param {number} duration the number of milliseconds per animation.
 */
export const useConditionalAnimationRef = (condition, animation = 'flash', duration = 1000) => {
  const ref = useRef();
  const interval = useRef();

  const start = () => {
    interval.current = setInterval(
      () => ref?.current[animation](duration),
      duration + DURATION_OFFSET
    );
  };

  const stop = () => {
    clearInterval(interval.current);
    ref?.current?.stopAnimation();
  };

  useEffect(() => {
    if (condition) start();
    else stop();
    return stop;
  }, [condition]);

  return ref;
};

@@ -40,197 +40,51 @@
 t';%0A
-%0A// Most animations are considered 'interactions' - if there is no break%0A// in the interaction, then InteractionManager.runAfterInteractions() is%0A// never fired.%0Aconst DURATION_OFFSET = 100
+import %7B MILLISECONDS %7D from '../utilities'
 ;%0A%0A/
@@ -552,16 +552,19 @@
 nRef = (
+%0A  
 conditio
@@ -565,16 +565,18 @@
 ndition,
+%0A 
  animati
@@ -588,16 +588,18 @@
 'flash',
+%0A 
  duratio
@@ -606,12 +606,32 @@
 n = 
-1000
+MILLISECONDS.ONE_SECOND%0A
 ) =%3E
@@ -661,250 +661,100 @@
 ();%0A
-  const interval = useRef();%0A%0A  const start = () =%3E %7B%0A    interval.current = setInterval(%0A      () =%3E ref?.current%5Banimation%5D(duration),%0A      duration + DURATION_OFFSET%0A    );%0A  %7D;%0A%0A  const stop = () =%3E %7B%0A    clearInterval(interval.current);
+%0A  const start = () =%3E %7B%0A    ref?.current%5Banimation%5D(duration);%0A  %7D;%0A%0A  const stop = () =%3E %7B
 %0A   

Add change to logic of useConditionalAnimationRef