Skip to content

iOS gesture down OtherViewController to FlutterViewController #35784

Closed
@helang1991

Description

@helang1991

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.

Activity

Piinks

Piinks commented on Jul 9, 2019

@Piinks
Contributor

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.

added
waiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds
on Jul 9, 2019
helang1991

helang1991 commented on Jul 10, 2019

@helang1991
Author

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

removed
waiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds
on Jul 10, 2019
crackerli

crackerli commented on Jul 10, 2019

@crackerli

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

crackerli commented on Jul 17, 2019

@crackerli

Any update on this issue? @Piinks Piinks

maeharin

maeharin commented on Jul 30, 2019

@maeharin

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

helang1991 commented on Jul 30, 2019

@helang1991
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

added
f: gesturesflutter/packages/flutter/gestures repository.
frameworkflutter/packages/flutter repository. See also f: labels.
platform-iosiOS applications specifically
on Sep 30, 2019
iapicca

iapicca commented on Mar 16, 2020

@iapicca
Contributor

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

added
waiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds
on Mar 16, 2020

7 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    f: gesturesflutter/packages/flutter/gestures repository.frameworkflutter/packages/flutter repository. See also f: labels.platform-iosiOS applications specificallywaiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @maeharin@crackerli@Piinks@BondarenkoStas@helang1991

        Issue actions

          iOS gesture down OtherViewController to FlutterViewController · Issue #35784 · flutter/flutter