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

iOS gesture down OtherViewController to FlutterViewController #35784

Closed
helang1991 opened this issue Jul 9, 2019 · 9 comments
Closed

iOS gesture down OtherViewController to FlutterViewController #35784

helang1991 opened this issue Jul 9, 2019 · 9 comments
Labels
f: gestures flutter/packages/flutter/gestures repository. framework flutter/packages/flutter repository. See also f: labels. platform-ios iOS applications specifically waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds

Comments

@helang1991
Copy link

helang1991 commented Jul 9, 2019

Steps to Reproduce

I wanna jump to other viewController by Plugin in Flutter, however, i met a problem: the FlutterViewController can receive gesture events from other viewController.
this is my demo link: https://github.com/helang1991/flutter_iOS_gesture_demo

screenshot:
image

Logs

Reloaded 1 of 441 libraries in 502ms.
flutter: I received gesture events in FlutterViewController
flutter: I received gesture events in FlutterViewController
flutter: I received gesture events in FlutterViewController
flutter: I received gesture events in FlutterViewController
flutter: I received gesture events in FlutterViewController
flutter: I received gesture events in FlutterViewController
flutter: I received gesture events in FlutterViewController
flutter: I received gesture events in FlutterViewController
flutter: I received gesture events in FlutterViewController
[✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.14.5 18F132, locale
    en-CN)
    • Flutter version 1.5.4-hotfix.2 at /Users/helang/Flutter/flutter
    • Framework revision 7a4c33425d (2 months ago), 2019-04-29 11:05:24 -0700
    • Engine revision 52c7a1e849
    • Dart version 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)

 
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/helang/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling
      support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = /Users/helang/Library/Android/sdk
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_152-release-1343-b01)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor
      --android-licenses

[!] iOS toolchain - develop for iOS devices (Xcode 10.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.2.1, Build version 10E1001
    ✗ libimobiledevice and ideviceinstaller are not installed. To install with
      Brew, run:
        brew update
        brew install --HEAD usbmuxd
        brew link usbmuxd
        brew install --HEAD libimobiledevice
        brew install ideviceinstaller
    ✗ ios-deploy not installed. To install:
        brew install ios-deploy
    • CocoaPods version 1.6.1

[✓] Android Studio (version 3.4)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 37.0.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build
      1.8.0_152-release-1343-b01)

[✓] Connected device (1 available)
    • iPhone Xʀ • 72F8738C-7190-48B4-956C-50A0DE6B74BC • ios •
      com.apple.CoreSimulator.SimRuntime.iOS-12-2 (simulator)

! Doctor found issues in 3 categories.
@Piinks
Copy link
Contributor

Piinks commented Jul 9, 2019

Hi @helang1991, can you post a reproduction of the issue as well as the output of flutter doctor? We will need more information to help you resolve it.

@Piinks Piinks added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 9, 2019
@helang1991
Copy link
Author

Hi @Piinks ,I clicked screen in other viewController by plugin, why the FlutterViewController received gesture events? Maybe other developers made similar issue.

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 10, 2019
@crackerli
Copy link

Hi @helang1991, can you post a reproduction of the issue as well as the output of flutter doctor? We will need more information to help you resolve it.

I also met the problem, from the beginning, I want to develop a customized camera, a new plugin is developed to achieve this, the customized camera is a native page, when I open the camera page from flutter button, then there are two pages in app, foreground native camera page and background flutter page, something bad happened here were that when I click on the native camera page, the background futter page can receive the click event, eg. some button can react to these events.

Til now, I found the issue can be reproduced only in ios platform, android works well.

I found that image_picker have the same issue, please refer this link below:
#32896

Further more, to find the root cause, I replace the camera native page with one common native page of ios, this issue can be produced too

@crackerli
Copy link

Any update on this issue? @Piinks Piinks

@maeharin
Copy link

I encountered the same problem. Here is my investigation and current workaround.

Sample application

https://github.com/maeharin/flutter_ios_present_sample

Screenshot

screenshot

Why this occured

Looking at the implementation of FlutterViewController (ex: engine v1.5.4-hotfixes branch), we can see they are overriding 4 methods(such as the touchesBegan). From here, the iOS touch event is propagated to the Flutter side
https://github.com/flutter/engine/blob/v1.5.4-hotfixes/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm#L649-L663

See the apple documentation below for how to call touchesBegan. Touch events on the iOS side are designed to run up the Responder Chain
https://developer.apple.com/documentation/uikit/touches_presses_and_gestures/using_responders_and_the_responder_chain_to_handle_events

In our case, Responder Chain is like this

  • Tap the part of UI where there is no event handler
  • A tap event runs up the Responder Chain on iOS and propagates to FlutterViewController's touchesBegan ()
  • Flutter side event handler is called

スクリーンショット 2019-07-30 12 13 28

Workaround

The following workarounds can be considered

1. Override 4 methods of UIViewController that is presented from FlutterViewController

This prevents propagating unhandled events to FlutterViewController

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {}
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {}

2. Stop doing present from FlutterViewController

Do not present() the UIViewController directly from the FlutterViewController, for example, by making the iOS side rootViewController a NavigationController instead of a FlutterViewController.
This article will be helpful for how to change rootViewController

https://medium.com/@najeira/change-ios-rootviewcontroller-with-flutter-fc4234f37105

@helang1991
Copy link
Author

I encountered the same problem. Here is my investigation and current workaround.

Sample application

https://github.com/maeharin/flutter_ios_present_sample

Screenshot

screenshot

Why this occured

Looking at the implementation of FlutterViewController (ex: engine v1.5.4-hotfixes branch), we can see they are overriding 4 methods(such as the touchesBegan). From here, the iOS touch event is propagated to the Flutter side
https://github.com/flutter/engine/blob/v1.5.4-hotfixes/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm#L649-L663

See the apple documentation below for how to call touchesBegan. Touch events on the iOS side are designed to run up the Responder Chain
https://developer.apple.com/documentation/uikit/touches_presses_and_gestures/using_responders_and_the_responder_chain_to_handle_events

In our case, Responder Chain is like this

  • Tap the part of UI where there is no event handler
  • A tap event runs up the Responder Chain on iOS and propagates to FlutterViewController's touchesBegan ()
  • Flutter side event handler is called

スクリーンショット 2019-07-30 12 13 28

Workaround

The following workarounds can be considered

1. Override 4 methods of UIViewController that is presented from FlutterViewController

This prevents propagating unhandled events to FlutterViewController

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {}
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {}

2. Stop doing present from FlutterViewController

Do not present() the UIViewController directly from the FlutterViewController, for example, by making the iOS side rootViewController a NavigationController instead of a FlutterViewController.
This article will be helpful for how to change rootViewController

https://medium.com/@najeira/change-ios-rootviewcontroller-with-flutter-fc4234f37105

Thanks for your advice, I'll try your methods to fix it

@BondarenkoStas BondarenkoStas added f: gestures flutter/packages/flutter/gestures repository. framework flutter/packages/flutter repository. See also f: labels. platform-ios iOS applications specifically labels Sep 30, 2019
@iapicca
Copy link
Contributor

iapicca commented Mar 16, 2020

Hi @helang1991
if the issue persist with the latest stable version of flutter
could you please provide your updated flutter doctor -v ,
your flutter run --verbose
and if possible a reproducible minimal code sample.
Thank you

@iapicca iapicca added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Mar 16, 2020
@iapicca
Copy link
Contributor

iapicca commented May 29, 2020

Without additional information we are unfortunately not sure how to resolve this issue.
We are therefore reluctantly going to close this bug for now.
Please don't hesitate to comment on the bug if you have any more information for us; we will reopen it right away!
Thanks for your contribution.

Could everyone who still has this problem please file a new issue with the exact description of what happens, logs and the output of flutter doctor -v.
All system setups can be slightly different, so it's always better to open new issues and reference related issues.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
f: gestures flutter/packages/flutter/gestures repository. framework flutter/packages/flutter repository. See also f: labels. platform-ios iOS applications specifically waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds
Projects
None yet
Development

No branches or pull requests

6 participants