rxm-rick

rxm-rick

Member Since 8 months ago

Experience Points
0
follower
Lessons Completed
0
follow
Best Reply Awards
0
repos

2 contributions in the last year

Pinned
Activity
Oct
21
1 month ago
Activity icon
issue

rxm-rick issue comment facebook/react-native

rxm-rick
rxm-rick

Animated.Value addListener can't working

Hi everybody. I'm building a function based on Animated.Value. But I'm facing error can't listen to value change.

Can you help me check it? Thank you!

Code

const [percent, setPercent] = useState(0);
const progressAnimation = useRef(new Animated.Value(0)).current;

  useEffect(() => {
    const interval = setInterval(() => {
      setPercent(Math.floor(Math.random() * 3));
    }, 2000);
    return () => {
      clearInterval(interval);
    };
  }, []);

  const animation = (toValue: number) => {
    Animated.timing(progressAnimation, {
      toValue,
      duration: 250,
      useNativeDriver: true,
    }).start();
  };

  useEffect(() => {
    animation(percent);
  }, [percent]);

  useEffect(() => {
    progressAnimation.addListener(() => {
      console.log('cannot listen');
    });
    return () => {
      progressAnimation.removeAllListeners();
    };
  }, []);

React Native version:

System:
    OS: macOS 10.15.7
    CPU: (4) x64 Intel(R) Core(TM) i5-4308U CPU @ 2.80GHz
    Memory: 46.07 MB / 8.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.16.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.11 - /usr/local/bin/npm
    Watchman: Not Found
  Managers:
    CocoaPods: 1.11.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 23, 24, 25, 26, 27, 28, 29, 30
      Build Tools: 28.0.3, 29.0.2, 30.0.0, 30.0.2
      System Images: android-28 | Google Play Intel x86 Atom, android-29 | Google APIs Intel x86 Atom_64, android-29 | Google Play Intel x86 Atom, android-30 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 2020.3 AI-203.7717.56.2031.7784292
    Xcode: 11.5/11E608c - /usr/bin/xcodebuild
  Languages:
    Java: 14.0.1 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.66.0 => 0.66.0 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found
rxm-rick
rxm-rick
Oct
15
1 month ago
Activity icon
issue

rxm-rick issue facebook/react-native

rxm-rick
rxm-rick

Animated.Value addListener can't working

Hi everybody. I'm building a function based on Animated.Value. But I'm facing error can't listen to value change.

Can you help me check it? Thank you!

Code

const [percent, setPercent] = useState(0);
const progressAnimation = useRef(new Animated.Value(0)).current;

  useEffect(() => {
    const interval = setInterval(() => {
      setPercent(Math.floor(Math.random() * 3));
    }, 2000);
    return () => {
      clearInterval(interval);
    };
  }, []);

  const animation = (toValue: number) => {
    Animated.timing(progressAnimation, {
      toValue,
      duration: 250,
      useNativeDriver: true,
    }).start();
  };

  useEffect(() => {
    animation(percent);
  }, [percent]);

  useEffect(() => {
    progressAnimation.addListener(() => {
      console.log('cannot listen');
    });
    return () => {
      progressAnimation.removeAllListeners();
    };
  }, []);

React Native version:

System:
    OS: macOS 10.15.7
    CPU: (4) x64 Intel(R) Core(TM) i5-4308U CPU @ 2.80GHz
    Memory: 46.07 MB / 8.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.16.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.11 - /usr/local/bin/npm
    Watchman: Not Found
  Managers:
    CocoaPods: 1.11.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 23, 24, 25, 26, 27, 28, 29, 30
      Build Tools: 28.0.3, 29.0.2, 30.0.0, 30.0.2
      System Images: android-28 | Google Play Intel x86 Atom, android-29 | Google APIs Intel x86 Atom_64, android-29 | Google Play Intel x86 Atom, android-30 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 2020.3 AI-203.7717.56.2031.7784292
    Xcode: 11.5/11E608c - /usr/bin/xcodebuild
  Languages:
    Java: 14.0.1 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.66.0 => 0.66.0 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found