Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Animations in Modal Fail to Display in React StrictMode #50451

Open
AsteriskZuo opened this issue Apr 2, 2025 · 8 comments
Open

Custom Animations in Modal Fail to Display in React StrictMode #50451

AsteriskZuo opened this issue Apr 2, 2025 · 8 comments
Labels
API: Animated Component: Modal Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Newer Patch Available

Comments

@AsteriskZuo
Copy link

AsteriskZuo commented Apr 2, 2025

Description

When using the Animated.View component within a Modal component, custom animations cannot be displayed properly while in StrictMode.

Steps to reproduce

  1. create react-native app npx @react-native-community/cli@latest init --version 0.76 simple_demo
  2. code:
// https://github.com/hakymz/ReactNativeCustomModal/blob/main/App.js
import React from 'react';
import {
  Animated,
  Button,
  Image,
  Modal,
  StyleSheet,
  Text,
  TouchableOpacity,
  View,
} from 'react-native';

const ModalPoup = ({ visible, children }: any) => {
  const [showModal, setShowModal] = React.useState(visible);
  // const scaleValue = React.useRef(new Animated.Value(0)).current;
  const translateY = React.useRef(new Animated.Value(0)).current;
  const toggleModal = React.useCallback(() => {
    if (visible) {
      setShowModal(true);
      // Animated.spring(scaleValue, {
      //   toValue: 1,
      //   // duration: 300,
      //   useNativeDriver: true,
      // }).start();
      Animated.timing(translateY, {
        toValue: 100,
        duration: 300,
        useNativeDriver: true,
      }).start();
    } else {
      // setTimeout(() => setShowModal(false), 200);
      // Animated.timing(scaleValue, {
      //   toValue: 0,
      //   duration: 300,
      //   useNativeDriver: true,
      // }).start();
      Animated.timing(translateY, {
        toValue: 0,
        duration: 300,
        useNativeDriver: true,
      }).start(() => {
        setShowModal(false);
      });
    }
  }, [translateY, visible]);

  React.useEffect(() => {
    toggleModal();
  }, [toggleModal, visible]);

  return (
    <Modal transparent animationType="none" visible={showModal}>
      <View style={styles.modalBackGround}>
        <Animated.View
          style={[styles.modalContainer, { transform: [{ translateY }] }]}
        >
          {children}
        </Animated.View>
      </View>
    </Modal>
  );
};

const App = () => {
  const [visible, setVisible] = React.useState(false);
  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <ModalPoup visible={visible}>
        <View style={{ alignItems: 'center' }}>
          <View style={styles.header}>
            <TouchableOpacity onPress={() => setVisible(false)}>
              <Image
                source={require('../../assets/agora_about_logo.png')}
                style={{ height: 30, width: 30 }}
              />
            </TouchableOpacity>
          </View>
        </View>
        <View style={{ alignItems: 'center' }}>
          <Image
            source={require('../../assets/agora_logo_2x.png')}
            style={{ height: 150, width: 150, marginVertical: 10 }}
          />
        </View>

        <Text style={{ marginVertical: 30, fontSize: 20, textAlign: 'center' }}>
          Congratulations registration was successful
        </Text>
      </ModalPoup>
      <Button title="Open Modal" onPress={() => setVisible(true)} />
    </View>
  );
};

const styles = StyleSheet.create({
  modalBackGround: {
    flex: 1,
    backgroundColor: 'rgba(0,0,0,0.5)',
    justifyContent: 'center',
    alignItems: 'center',
  },
  modalContainer: {
    width: '80%',
    backgroundColor: 'white',
    paddingHorizontal: 20,
    paddingVertical: 30,
    borderRadius: 20,
    elevation: 20,
  },
  header: {
    width: '100%',
    height: 40,
    alignItems: 'flex-end',
    justifyContent: 'center',
  },
});

const Wrapper = () => {
  return <App />;
  // return (
  //   <React.StrictMode>
  //     <App />
  //   </React.StrictMode>
  // );
};

export default App;
  1. yarn run android
  2. try strict and not strict mode.

React Native Version

0.76.7

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info

info Fetching system and libraries information...
System:
  OS: macOS 14.7.2
  CPU: (10) arm64 Apple M1 Max
  Memory: 69.98 MB / 64.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.18.0
    path: /private/var/folders/_x/3sg_ghyj03q5_xhxffbhy2k00000gp/T/xfs-1ca108b1/node
  Yarn:
    version: 4.7.0
    path: /private/var/folders/_x/3sg_ghyj03q5_xhxffbhy2k00000gp/T/xfs-1ca108b1/yarn
  npm:
    version: 10.8.2
    path: ~/.nvm/versions/node/v20.18.0/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.16.2
    path: /opt/homebrew/opt/cocoapods/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.2
      - iOS 18.2
      - macOS 15.2
      - tvOS 18.2
      - visionOS 2.2
      - watchOS 11.2
  Android SDK:
    API Levels:
      - "30"
      - "31"
      - "33"
      - "34"
      - "35"
    Build Tools:
      - 30.0.2
      - 30.0.3
      - 33.0.0
      - 34.0.0
      - 35.0.0
    System Images:
      - android-35 | Google APIs ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: Not Found
  Xcode:
    version: 16.2/16C5032a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.10
    path: /Applications/Android Studio 2024.app/Contents/jbr/Contents/Home/bin/javac
  Ruby:
    version: 3.3.6
    path: /opt/homebrew/opt/ruby/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: 15.0.1
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.7
    wanted: 0.76.7
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

info React Native v0.78.2 is now available (your project is running on v0.76.7).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.78.2
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.76.7&to=0.78.2
info For more info, check out "https://reactnative.dev/docs/upgrading?os=macos".

Stacktrace or Logs

INFO  
 💡 JavaScript logs will be removed from Metro in React Native 0.77! Please use React Native DevTools as your default tool. Tip: Type j in the terminal to open (requires Google Chrome or Microsoft Edge).

Reproducer

https://github.com/AsteriskZuo/test_rn076_new_arch_issues/blob/test2/QA.md

Screenshots and Videos

No response

@react-native-bot
Copy link
Collaborator

Tip

Newer version available: You are on a supported minor version, but it looks like there's a newer patch available - 0.76.8. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@react-native-bot react-native-bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. API: Animated Component: Modal labels Apr 2, 2025
@AsteriskZuo AsteriskZuo changed the title When using the Animated.View component within a Modal component, custom animations cannot be displayed properly while in StrictMode. Custom Animations in Modal Fail to Display in React StrictMode Apr 2, 2025
@react-native-bot
Copy link
Collaborator

Tip

Newer version available: You are on a supported minor version, but it looks like there's a newer patch available - undefined. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@react-native-bot
Copy link
Collaborator

Warning

Missing reproducer: We could not detect a reproducible example in your issue report. Please provide either:

@devanshsaini11
Copy link
Collaborator

devanshsaini11 commented Apr 3, 2025

@AsteriskZuo can u share a valid reproducer so it can be validated quickly

@AsteriskZuo
Copy link
Author

AsteriskZuo commented Apr 4, 2025

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Apr 4, 2025
@AsteriskZuo
Copy link
Author

@devanshsaini11 Please confirm. thx.

@devanshsaini11
Copy link
Collaborator

@AsteriskZuo
Thanks for reporting this. I was able to reproduce the issue locally. However, I noticed that the repro includes a large number of dependencies, which might be contributing to the problem.

To help us isolate the root cause more effectively, could you please provide a minimal reproduction with only the absolutely necessary dependencies? This will make it easier to identify whether the issue lies within React Native itself or is being influenced by other libraries.

@devanshsaini11 devanshsaini11 added Needs: Author Feedback and removed Needs: Attention Issues where the author has responded to feedback. labels Apr 7, 2025
@devanshsaini11
Copy link
Collaborator

@AsteriskZuo Please use latest react-native version for repro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: Animated Component: Modal Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Newer Patch Available
Projects
None yet
Development

No branches or pull requests

3 participants