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

Alerts not showing iOS 13+ Scenedelegate + Multiwindow Support enabled #31251

Closed
tanakaderoy opened this issue Mar 26, 2021 · 4 comments
Closed
Labels
Needs: Triage 🔍 Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@tanakaderoy
Copy link

tanakaderoy commented Mar 26, 2021

Description

On an iOS project using the new SceneDelegate and have multiwindow support turned on the Alert.alert() function is not working anymore. Seems like the change to use the new RCTAlertController in #29295 introduced the issue. Making the window via _alertWindow = [[UIWindow alloc] initWithFrame:RCTSharedApplication().keyWindow.bounds]; seems to be the problem. I have found a workaround of replacing the _alertWindow initialisation with this:

if (@available(iOS 13.0, *)) {
        for (UIWindowScene *scene in RCTSharedApplication().connectedScenes) {
          if(scene.activationState == UISceneActivationStateForegroundActive && scene.class == UIWindowScene.class) {
            _alertWindow = [[UIWindow alloc] initWithWindowScene:scene];
            break;
          }
        }
      }
      if (_alertWindow == nil) {
        _alertWindow = [[UIWindow alloc] initWithFrame:RCTSharedApplication().keyWindow.bounds];
      }

That allows the Alerts to show on both projects using regular Appdelegate & projects using the Scenedelegate

React Native version:

Run react-native info in your terminal and copy the results here.

System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 2.65 GB / 32.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 10.16.3 - ~/.nvm/versions/node/v10.16.3/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.9.0 - ~/.nvm/versions/node/v10.16.3/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.10.1 - /Users/[USERNAME]/.rvm/gems/ruby-2.6.3/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2
    Android SDK:
      API Levels: 28, 29, 30
      Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.1, 30.0.3
      System Images: android-29 | Intel x86 Atom_64, android-29 | Google Play Intel x86 Atom, android-30 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.1 AI-201.8743.12.41.6953283
    Xcode: 12.4/12D4e - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_275 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: Not Found
    react-native: 0.63.4 => 0.63.4
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. make a new RN project -- 0.64.0 as per usual
  2. convert it to use the Scenedelegate and enable multiwindow support (good Guide on adding scenedelegate)
  3. make a simple App.js that shows an alert on button press
  4. run on iOS 13+ Alert won't show
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * format
 * flow strict-local
 */

import React from 'react';
import {SafeAreaView, StyleSheet, StatusBar, Alert, Button} from 'react-native';

const App: () => React$Node = () => {
  const showAlert = () => {
    Alert.alert('Alert', "Hey I'm an Alert!");
    //Now Not Working!!!
  };

  return (
    <>
      <StatusBar barStyle="dark-content" />
      <SafeAreaView style={styles.container}>
        <Button onPress={showAlert} title="Show Alert" />
      </SafeAreaView>
    </>
  );
};

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

export default App;

Expected Results

Alerts should be showing on iOS 13+

Snack, code example, screenshot, or link to a repository:

Here is a small repo that just shows the problem RNiOSAlertIssue
it has 2 branches main and AlertWorkingNoMultiWindow. main has the Scenedelegate changes. AlertWorkingNoMultiWindow branch is the repo before any scenedelegate changes or enabling multi window.

You may provide a screenshot of the application if you think it is relevant to your bug report.
Here are some tips for providing a minimal example: https://stackoverflow.com/help/mcve

@michalis-ligopsychakis
Copy link

@tanakaderoy because you are using 'Scenes' with 'react-native', I just want to ask you if now with the 'iOS 15' and it's new feature 'prewarming', do you have any problems on your app's launch ?
We have some serious issues after iOS15 and because of 'Scenes' here: https://stackoverflow.com/questions/70668709/on-ios15-prewarming-issue-on-app-launch-using-scenedelegate

@elmcapp
Copy link

elmcapp commented Oct 20, 2022

Seem as of now we can not use SceneDelegate. I have the same issue. I convert my React Native objective-c to a swift template. When use SceneDelegate I get the same problem. Sometimes the Alert will show and some time it will not. Once I put my code into AppDelete problem was fixed.

Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Dec 13, 2023
Copy link

This issue was closed because it has been stalled for 7 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Triage 🔍 Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants