react-native-macos/React/CoreModules
Devon Deonarine f319ff321c iOS: Update RCTAlertManager to use new RCTAlertController (#29295)
Summary:
This should fix https://github.com/facebook/react-native/issues/29082 and https://github.com/facebook/react-native/issues/10471

Currently when an alert is being shown while a modal is being dismissed, it causes the alert not to show and In some cases it causes the UI to become unresponsive. I think this was caused by using RCTPresentedViewController to try and display the Alert the currently presented view. The View the Alert was going to be shown on is dismissed and the modal doesn't show. I implemented a new RCTAlertController to show the alert on top of the view, the modal being dismissed should now not interfere with the alert being shown.

## Changelog

[iOS] [Fixed] - Fixed showing Alert while closing a Modal

Pull Request resolved: https://github.com/facebook/react-native/pull/29295

Test Plan:
To recreate the bug:

1. npx react-native init Test --version 0.63.0-rc.1
2. Paste the following code into App.js

```javascript
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * format
 * flow strict-local
 */

import React from 'react';
import {
  SafeAreaView,
  StyleSheet,
  View,
  Text,
  StatusBar,
  Modal,
  Alert
} from 'react-native';

const App: () => React$Node = () => {
  const [visible, setVisible] = React.useState(false)

  const onShowModal = () => {
    setVisible(true)
  }

  onCloseBroken = () => {
    setVisible(false)
    Alert.alert('Alert', 'Alert won\'t show')
  }

  onCloseWorking = () => {
    setVisible(false)
    setTimeout(() => Alert.alert('Alert', 'Works fine'), 10)
  }

  return (
    <>
      <StatusBar barStyle="dark-content" />
      <SafeAreaView style={styles.container}>
        <Text onPress={onShowModal}>Show modal</Text>
      </SafeAreaView>
      <Modal animationType="fade" visible={visible} onRequestClose={onCloseWorking} >
        <View style={styles.container}>
          <Text onPress={onCloseBroken}>Close modal immediately</Text>
          <Text onPress={onCloseWorking}>Close modal with delay</Text>
        </View>
      </Modal>
    </>
  )
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'space-around',
  },
})

export default App

```

3. cd Test && npx react-native run-ios
4. Show the modal and click the `Close modal immediately` button

The first button doesn't show the alert, the second does because it gets rendered after the modal view is dismissed. After this commit, the alert always shows on top of every view properly. You can test by pointing the react native package to my branch by modifying the package json file like this

```
    "react-native": "https://github.com/devon94/react-native.git#fix-ios-modal"
```

I was unable to reproduce the case where it causes the UI to be responsive in the test app but was able to reproduce it in our react native app at work. I can provide a video later if needed but the code is too complex to simplify into a test case.

Reviewed By: sammy-SC

Differential Revision: D22783371

Pulled By: PeteTheHeat

fbshipit-source-id: 3e359645c610074ea855ee5686c59bdb9d6b696b
2020-08-06 16:20:47 -07:00
..
BUCK Add `RCTDevSplitBundleLoader` native module 2020-06-08 09:07:42 -07:00
CoreModulesPlugins.h Add `RCTDevSplitBundleLoader` native module 2020-06-08 09:07:42 -07:00
CoreModulesPlugins.mm Add `RCTDevSplitBundleLoader` native module 2020-06-08 09:07:42 -07:00
RCTAccessibilityManager.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTAccessibilityManager.mm Part 2: Update ObjC++ codegen classes to use ObjCTurboModule::InitParams 2020-04-16 17:29:55 -07:00
RCTActionSheetManager.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTActionSheetManager.mm Revert D21396409: Add possibility to disable buttons in action sheet ios 2020-05-19 16:36:32 -07:00
RCTAlertController.h iOS: Update RCTAlertManager to use new RCTAlertController (#29295) 2020-08-06 16:20:47 -07:00
RCTAlertController.m iOS: Update RCTAlertManager to use new RCTAlertController (#29295) 2020-08-06 16:20:47 -07:00
RCTAlertManager.h Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTAlertManager.mm iOS: Update RCTAlertManager to use new RCTAlertController (#29295) 2020-08-06 16:20:47 -07:00
RCTAppState.h Guard against nil bridge during teardown 2020-01-06 17:03:06 -08:00
RCTAppState.mm Run getConstants method statements on main queue 2020-06-02 23:01:35 -07:00
RCTAppearance.h Add dark mode to loading progress 2020-05-12 20:56:06 -07:00
RCTAppearance.mm Add dark mode to loading progress 2020-05-12 20:56:06 -07:00
RCTAsyncLocalStorage.h Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTAsyncLocalStorage.mm Part 2: Update ObjC++ codegen classes to use ObjCTurboModule::InitParams 2020-04-16 17:29:55 -07:00
RCTClipboard.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTClipboard.mm Part 2: Update ObjC++ codegen classes to use ObjCTurboModule::InitParams 2020-04-16 17:29:55 -07:00
RCTDevLoadingView.h Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTDevLoadingView.mm Add dark mode to loading progress 2020-05-12 20:56:06 -07:00
RCTDevMenu.h Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTDevMenu.mm Part 2: Update ObjC++ codegen classes to use ObjCTurboModule::InitParams 2020-04-16 17:29:55 -07:00
RCTDevSettings.h Add `RCTDevSplitBundleLoader` native module 2020-06-08 09:07:42 -07:00
RCTDevSettings.mm Add `RCTDevSplitBundleLoader` native module 2020-06-08 09:07:42 -07:00
RCTDevSplitBundleLoader.h Fix loading from Metro in Bridgeless mode (#29453) 2020-07-23 17:11:32 -07:00
RCTDevSplitBundleLoader.mm Fix loading from Metro in Bridgeless mode (#29453) 2020-07-23 17:11:32 -07:00
RCTDeviceInfo.h Remove unneeded NSNotification center removeObserver 2019-11-04 10:19:30 -08:00
RCTDeviceInfo.mm Run getConstants method statements on main queue 2020-06-02 23:01:35 -07:00
RCTExceptionsManager.h Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTExceptionsManager.mm Rename RCTTurboModuleLookupDelegate to RCTTurboModuleRegistry 2020-07-07 16:25:11 -07:00
RCTFPSGraph.h Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTFPSGraph.m Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTI18nManager.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTI18nManager.mm Part 2: Update ObjC++ codegen classes to use ObjCTurboModule::InitParams 2020-04-16 17:29:55 -07:00
RCTKeyboardObserver.h Make RCTKeyboardObserver TurboModule-compatible 2019-11-01 12:06:20 -07:00
RCTKeyboardObserver.mm Part 2: Update ObjC++ codegen classes to use ObjCTurboModule::InitParams 2020-04-16 17:29:55 -07:00
RCTLogBox.h Cleanup logbox imports 2020-05-12 22:40:29 -07:00
RCTLogBox.mm Cleanup logbox imports 2020-05-12 22:40:29 -07:00
RCTPerfMonitor.mm Fix crash when enabling Performance Monitor on iOS 13.4 (#28512) 2020-04-03 20:44:20 -07:00
RCTPlatform.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTPlatform.mm Run getConstants method statements on main queue 2020-06-02 23:01:35 -07:00
RCTRedBox.h Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTRedBox.mm Part 2: Update ObjC++ codegen classes to use ObjCTurboModule::InitParams 2020-04-16 17:29:55 -07:00
RCTSourceCode.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTSourceCode.mm Part 2: Update ObjC++ codegen classes to use ObjCTurboModule::InitParams 2020-04-16 17:29:55 -07:00
RCTStatusBarManager.h Make RCTStatusBarManager TurboModule-compatible 2019-11-01 12:06:20 -07:00
RCTStatusBarManager.mm Run getConstants method statements on main queue 2020-06-02 23:01:35 -07:00
RCTTVNavigationEventEmitter.h Make RCTTVNavigationEventEmitter TurboModule-compatible 2019-11-04 16:07:24 -08:00
RCTTVNavigationEventEmitter.mm Part 2: Update ObjC++ codegen classes to use ObjCTurboModule::InitParams 2020-04-16 17:29:55 -07:00
RCTTiming.h Clang format for all React Native files 2020-03-08 23:01:17 -07:00
RCTTiming.mm Make RCTTiming a regular NativeModule 2019-11-08 17:28:23 -08:00
RCTWebSocketExecutor.h Make RCTWebSocketModule TurboModule-compatible 2019-11-08 14:14:46 -08:00
RCTWebSocketExecutor.mm "The Metro Server" -> Metro 2020-07-02 14:51:18 -07:00
RCTWebSocketModule.h Make RCTWebSocketModule TurboModule-compatible 2019-11-08 14:14:46 -08:00
RCTWebSocketModule.mm Part 2: Update ObjC++ codegen classes to use ObjCTurboModule::InitParams 2020-04-16 17:29:55 -07:00
React-CoreModules.podspec Fix Cocoapods builds 2020-04-07 19:07:19 -07:00