react / react/react-native

[iOS] ModalHostViewController not properly dismissed if presenting another VC

未关闭
#54,856 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Component: Modal Needs: Triage :mag: Platform: iOS
主要语言
C++
星标
127k
派生
25.3k
平均合并
1 天 23 小时
30 天内合并 PR
4

描述

Description

In our brownfield application, we have a scenario where we can open a login flow from the RN Modal component. The login flow shows an iOS system view controller with a webview. At the same time, the dialog is getting closed. The result of these two actions happening roughly at the same time is that: 1) the login VC gets dismissed, while the RCTModalHostViewController is still present as a top-level VC, but without any UI. It is intercepting all touches and preventing further usage of the app.

Here is the view hierarchy:
Image

I've done some investigation and found that this is due to the following RN code:

- (void)dismissViewController:(UIViewController *)modalViewController
                     animated:(BOOL)animated
                   completion:(void (^)(void))completion
{
  [modalViewController dismissViewControllerAnimated:animated completion:completion];
}

Basically the modal VC is trying to dismiss itself. However, the dismissViewControllerAnimated:completion: method has two modes:

  • When given VC is the top presented on, it dismisses itself from its parent
  • When given VC is presenting another VC, it is dismissing that VC instead, but it stays presented itself.

Relevant docs from iOS API:

The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, UIKit asks the presenting view controller to handle the dismissal.

Fix for that would be to make the code dismiss the same whether modal VC is presenting another VC or not. A simple way would be to replace:

  [modalViewController dismissViewControllerAnimated:animated completion:completion];

with

  [modalViewController.presentingViewController dismissViewControllerAnimated:animated completion:completion];

Note: the reproducer uses react-native-image-picker library to show another VC, but in our brownfield app, we use our VC. The type of VC does not really matter, as the important part is that it's presented on top of the modal VC that will be dismissed before the 2nd VC gets dismissed.

Steps to reproduce
  1. Download & run the reproducer repo: https://github.com/mdjastrzebski/rn-repro-stale-modal-vc-blocks-touches
  2. Press the "Open Modal" button
  3. The modal should open, press "Open Photo Library"
  4. The system Photo Picker should slide in briefly and get dismissed
  5. After you are back to the initial VC you cannot make any more touch actions, as an invisible RCTModalHostViewController is still present (see view hierarchy screenshot)

You may need to repeat this a few times, but you should be able to trigger the issue. In our brownfield app, we have 100% repro, but in the contrived example, it only occurs sometimes.

https://github.com/user-attachments/assets/0b2e63d6-4301-4045-b108-a8bfeccc5b3c

React Native Version

0.83.0

Affected Platforms

Runtime - iOS

Output of npx @react-native-community/cli info
System:
  OS: macOS 26.1
  CPU: (11) arm64 Apple M3 Pro
  Memory: 266.56 MB / 36.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.17.1
    path: /Users/mdj/.nvm/versions/node/v22.17.1/bin/node
  Yarn:
    version: 1.22.22
    path: /Users/mdj/.nvm/versions/node/v22.17.1/bin/yarn
  npm:
    version: 10.9.2
    path: /Users/mdj/.nvm/versions/node/v22.17.1/bin/npm
  Watchman:
    version: 2025.07.28.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /Users/mdj/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.0
      - iOS 26.0
      - macOS 26.0
      - tvOS 26.0
      - visionOS 26.0
      - watchOS 26.0
  Android SDK:
    API Levels:
      - "35"
      - "36"
    Build Tools:
      - 35.0.0
      - 36.0.0
    System Images:
      - android-35 | Google Play ARM 64 v8a
      - android-36 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2025.2 AI-252.25557.131.2521.14432022
  Xcode:
    version: 26.0.1/17A400
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.16
    path: /usr/bin/javac
  Ruby:
    version: 3.4.5
    path: /Users/mdj/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.0.0
    wanted: 20.0.0
  react:
    installed: 19.2.0
    wanted: 19.2.0
  react-native:
    installed: 0.83.0
    wanted: 0.83.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true
Stacktrace or Logs
n/a
MANDATORY Reproducer

https://github.com/mdjastrzebski/rn-repro-stale-modal-vc-blocks-touches

Screenshots and Videos

No response

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm 中的 dismissViewController: 开始。运行链接的 rn-repro-stale-modal-vc-blocks-touches reproducer,并验证在呈现另一个 view controller 时的 dismissal 路径。完成的标准是:photo picker 或另一个 controller 关闭后,modal host 已完全 dismiss,且不再拦截 touches。

由索引模型根据 Issue 内容生成。

评估

技术栈
ios, objective-c, react-native
领域
mobile-dev
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
描述清楚
新手友好度
68/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。