Граф коммитов

8 Коммитов

Автор SHA1 Сообщение Дата
Luna Wei ab5f26bf02 Back out "Fix `Alert` not showing in an app using `UIScene`"
Summary:
Changelog: [Internal] - Revert https://github.com/facebook/react-native/pull/34562

re: [iOS] [Fixed] - Fix Alert not showing in an app using UIScene

Reviewed By: alsun2001

Differential Revision: D39591113

fbshipit-source-id: ba707c11b3fb97eb3a6fee32e57b92403aa8b3d8
2022-09-17 07:05:37 -07:00
Tommy Nguyen 153aedce41 Fix `Alert` not showing in an app using `UIScene` (#34562)
Summary:
In an app using `UIScene`, `Alert` no longer pops up because the window
that gets created are not attached to a scene.

## Changelog

[iOS] [Fixed] - Fix `Alert` not showing in an app using `UIScene`

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

Test Plan: Use the test plan in https://github.com/facebook/react-native/issues/29295. This should not regress that fix.

Reviewed By: cipolleschi

Differential Revision: D39276976

Pulled By: lunaleaps

fbshipit-source-id: e48e985ed4abec77d6f01a6c17292d664ed88f13
2022-09-08 12:54:08 -07:00
Vojtech Novak 18542b6ef5 fix: RCTAlertController's UserInterfaceStyle to follow root window (#34218)
Summary:
The motivation of this PR is for the Alert to follow the same style override (`overrideUserInterfaceStyle` being light/dark) as the one used by the root window (`UIApplication.sharedApplication.delegate.window`).

This is something that has worked previously because `RCTPResentedViewController()` was used to present the Alert (the behavior has changed in f319ff321c). With the former approach, the alert would "inherit" the `userInterfaceStyle` of the view controller it was presented within (and that one, in turn, would "inherit" from `UIApplication.sharedApplication.delegate.window`).

With the current approach, the "style inheritance" does not work with the view controller being created [here](f3db6cc527/React/CoreModules/RCTAlertController.m (L24)).

Because this viewcontroller instance does not have where to "inherit" the styling from, the styling might be different from the rest of the app. This PR fixes that.

## Changelog

[iOS] [Fixed] - fix: RCTAlertController's UserInterfaceStyle to follow root window

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

Test Plan:
Instead of

```
self.overrideUserInterfaceStyle = UIApplication.sharedApplication.delegate.window.overrideUserInterfaceStyle;
```

you can do

```
self.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
```

and observe the result. So if the override is set, it'll manifest itself. If it's not set, the value of `UIApplication.sharedApplication.delegate.window.overrideUserInterfaceStyle` will be `UIUserInterfaceStyleUnspecified`, and it'll have no effect.

<details>
  <summary>screenshot</summary>

![Simulator Screen Shot - iPhone 11 - 2022-07-18 at 21 40 06](https://user-images.githubusercontent.com/1566403/179616673-d0e48e07-50b5-41a1-afb7-0aa8f7ec37b5.png)
</details>

Reviewed By: dmitryrykun

Differential Revision: D38660799

Pulled By: cipolleschi

fbshipit-source-id: c979266900e27be7a4732bdb6e9a496906534931
2022-08-25 11:09:10 -07:00
Asaf Korem a46a99e120 fix(iOS): remove alert's window when call to `hide`. (#32833)
Summary:
Resolves this issue: https://github.com/facebook/react-native/issues/32304.
**NOTE:** This PR is based on a prior PR for this fix: https://github.com/facebook/react-native/pull/32305, I've co-authorized its creator for this change (paddlefish).

Without this change, calling to hide an alert, leaves a `UIWindow` that blocks user interactions with the screen.

The correct way to remove a `UIWindow` in iOS is to set its hidden property to `YES`. Also, it is required to remove all references to the window (the associated `windowScene` for example) and ARC will automatically free this `UIWindow`.

The line after this change, set the `_alertWindow` reference to `nil`, but the window is already associated with a scene (see the screenshots from [this PR](https://github.com/facebook/react-native/pull/32305#discussion_r720521707)). So we also need to remove the `windowScene` from that window, as recommended by Apple: https://developer.apple.com/documentation/uikit/uiwindowscene/3198091-windows.
>To remove the window from the current scene, or move it to a different scene, change the value of the window's windowScene property.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[iOS] [Fixed] - remove alert's window when call to `hide`.

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

Test Plan: See https://github.com/facebook/react-native/pull/32305

Reviewed By: hramos

Differential Revision: D33460430

Pulled By: lunaleaps

fbshipit-source-id: b13c2c7ee6404f1e1c787265bc4af8a31005bcf1
2022-01-19 01:09:17 -08:00
Andres Suarez 8bd3edec88 Update copyright headers from Facebook to Meta
Reviewed By: aaronabramov

Differential Revision: D33367752

fbshipit-source-id: 4ce94d184485e5ee0a62cf67ad2d3ba16e285c8f
2021-12-30 15:11:21 -08:00
Nick Fujita 614e6025ab Fix RCTAlertController import when embed in existing iOS projects (#32457)
Summary:
Fixes a build error relating to RCTAlertController import when embedding react-native into existing iOS app. This PR resolves the issue detailed in https://github.com/facebook/react-native/issues/32356

## Changelog

Adjusts the import syntax which was added in:
f319ff321c (diff-56beca6ee071cdd162c269ce765ab12d5af8c8c0ca840bca1e9d1f59e9fab790)

Existing:
#import "RCTAlertController.h"

New:
#import <React/RCTAlertController.h>

[iOS] [Fix] - Fix RCTAlertController import build error when embedded in existing iOS projects

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

Test Plan:
Build this branch in existing iOS project using swift, and should not have the build error described in the issue above.

Would also like to have this fix cherry-pick'd to release 0.63 after merging.

Reviewed By: RSNara

Differential Revision: D31861814

Pulled By: charlesbdudley

fbshipit-source-id: e60f80c8ea982e400cbf6d9375037d4197bbb8a3
2021-11-11 15:30:50 -08:00
Peter Argany dee937c7c1 Fix retain cycle in RCTAlertController
Summary:
`RCTAlertController` creates a new window, and presents itself in that window.

RCTAlertController strongly retains the window, and the window strongly retains RCTAlertController when presenting it.

This adds a new method to break that cycle once alert is dismissed.

Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D25312413

fbshipit-source-id: e4048922aa697eb42c4c149827bac61bc7bc5528
2020-12-04 18:12:23 -08:00
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