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

WebView touchstart events are invoked even when the WebView is not hit tested on iOS #30143

Closed
amirh opened this issue Mar 28, 2019 · 30 comments
Closed
Assignees
Labels
a: platform-views Embedding Android/iOS views in Flutter apps customer: money (g3) found in release: 2.2 Found to occur in 2.2 found in release: 2.5 Found to occur in 2.5 p: webview The WebView plugin P0 Critical issues such as a build break or regression package flutter/packages repository. See also p: labels. platform-ios iOS applications specifically r: fixed Issue is closed as already fixed in a newer version team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team

Comments

@amirh
Copy link
Contributor

amirh commented Mar 28, 2019

Internal: b/126614142
Internal: b/285315999

Sample repro app:

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

void main() => runApp(MaterialApp(home: WebViewExample()));

class WebViewExample extends StatelessWidget {
  final Completer<WebViewController> _controller =
      Completer<WebViewController>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: WebView(
        initialUrl: 'https://master-docs-flutter-io.firebaseapp.com/',
        javascriptMode: JavascriptMode.unrestricted,
        onWebViewCreated: (WebViewController webViewController) {
          _controller.complete(webViewController);
        },
        onPageFinished: (String url) {
          injectTouchListener();
        },
        javascriptChannels: <JavascriptChannel> [
          JavascriptChannel(name: 'Log', onMessageReceived: (JavascriptMessage msg) { print(msg.message); })
        ].toSet() ,
      ),
      floatingActionButton: FloatingActionButton(
        child: Container(color: Colors.orange,),
          onPressed: () {}
          ),
    );
  }
  Future<void> injectTouchListener() async {
    final WebViewController controller = await _controller.future;
    controller.evaluateJavascript("document.addEventListener('touchstart', (event) => { Log.postMessage(String(event)); }, true);");
  }
}

On iOS the message is printing even when tapping the FAB.

@amirh amirh added platform-ios iOS applications specifically plugin a: platform-views Embedding Android/iOS views in Flutter apps p: webview The WebView plugin labels Mar 28, 2019
@amirh amirh added this to the Goals milestone Mar 28, 2019
@amirh
Copy link
Contributor Author

amirh commented Mar 28, 2019

cc @cyanglaz

@cyanglaz
Copy link
Contributor

cyanglaz commented Apr 2, 2019

Spent some time investigate this issue with @amirh and @chinmaygarde debugging this issue. We tried replacing 'touchstart' with a different event like 'click', it works fine. We think there could be some special case handling for events like 'touchstart' in iOS. We have not found any way to work around it.

Meanwhile, if anyone encounter this issue, I suggest working around it with a different event type on the web application.

@jmagman jmagman added this to Awaiting triage in iOS Platform - platform view review Feb 25, 2020
@kf6gpe kf6gpe added the P2 Important issues not at the top of the work list label May 29, 2020
@cyanglaz cyanglaz added this to To do in [webview_flutter] gesture issues on iOS via automation Jul 10, 2020
@Hixie Hixie removed this from the None. milestone Aug 17, 2020
@asavartsov
Copy link

asavartsov commented Oct 19, 2020

In my case, it even worse. When I tap a block in front of WebView, WebView receives touchstart, but does not receive touchend. And it will receive touchend on the next tap with new touchstart right after it.

Finger down
**touchstart**

Finger up
**nothing**

Finger down
**touchend**
**touchstart**

Finger up
**nothing**

Finger down
**touchend**
**touchstart**

Finger up
**nothing**

This behavior breaks my Leaflet map completely. It behaves like always touched.

controller.reload() does fix this behavior until the next touch of any block in front of WebView.

Adding IgnorePointer/AbsorbPointer does not help here. Somehow the page inside WebView still receives touchstart/touchend.

I think other issues about broken map controls could probably have the same source of a problem.

Both of WebView/iOS/touch-related proposed fixes at

macoshita/plugins@65113db

and

https://gist.github.com/Voxar/5dbef0b76cc8cb55d2fe74a492d41c54

does not work for me.

I'm testing on iOS 13.6.

@asavartsov
Copy link

asavartsov commented Oct 19, 2020

A little clarification. As for Leaflet, it actually does not use these touch events on iOS by default. Leaflet detects support for pointer events and uses them instead of touchstart/touchend. And glitches occur because of this: if WebView is touched directly it does receive pointerup and pointerdown. But if a block in front of WebView is touched, pointerdown event is leaking to DOM event listener, but somehow pointerup event does not occur leaving pointerdown alone in the Leaflet's internal array of pointer events. For my project I fixed that by overriding pointer detection @ https://github.com/Leaflet/Leaflet/blob/9b0d7c2a7023e6a83222d96febaee74880601ad8/src/core/Browser.js#L96 setting it to false. Leaflet fallbacks to touchstart/touchend and even though it does receive events from other blocks when it shouldn't because of this bug, it maintains internal state correctly.

@danagbemava-nc
Copy link
Member

The issue is reproducible on the latest master (2.5.0-6.0.pre.29) and stable (2.2.3) with the latest webview_flutter: ^2.0.10.

flutter doctor -v
[✓] Flutter (Channel master, 2.5.0-6.0.pre.29, on macOS 11.5.1 20G80 darwin-arm, locale en-GH)
    • Flutter version 2.5.0-6.0.pre.29 at /Users/nexus/dev/sdks/flutters
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 6876c52b5b (8 hours ago), 2021-08-08 15:34:09 -0700
    • Engine revision c0e59bc7b6
    • Dart version 2.14.0 (build 2.14.0-383.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/nexus/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.5.1, Build version 12E507
    • CocoaPods version 1.10.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] VS Code (version 1.59.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.25.0

[✓] Connected device (3 available)
    • sdk gphone64 arm64 (mobile) • emulator-5554                        • android-arm64  • Android
      12 (API 31) (emulator)
    • iPhone 12 (mobile)          • F2592D43-5FE3-46BB-8A2B-A38BA468DCE9 • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
    • Chrome (web)                • chrome                               • web-javascript • Google
      Chrome 92.0.4515.131

• No issues found!
[✓] Flutter (Channel stable, 2.2.3, on macOS 11.5.1 20G80 darwin-arm, locale en-GH)
    • Flutter version 2.2.3 at /Users/nexus/dev/sdks/flutter
    • Framework revision f4abaa0735 (5 weeks ago), 2021-07-01 12:46:11 -0700
    • Engine revision 241c87ad80
    • Dart version 2.13.4

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/nexus/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.5.1, Build version 12E507
    • CocoaPods version 1.10.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] VS Code (version 1.59.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.25.0

[✓] Connected device (3 available)
    • sdk gphone64 arm64 (mobile) • emulator-5554                        • android-arm64  • Android
      12 (API 31) (emulator)
    • iPhone 12 (mobile)          • F2592D43-5FE3-46BB-8A2B-A38BA468DCE9 • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
    • Chrome (web)                • chrome                               • web-javascript • Google
      Chrome 92.0.4515.131

• No issues found!

@danagbemava-nc danagbemava-nc added found in release: 2.2 Found to occur in 2.2 found in release: 2.5 Found to occur in 2.5 labels Aug 9, 2021
@cyanglaz cyanglaz moved this from Awaiting triage to Engineer reviewed in iOS Platform - platform view review Aug 25, 2021
@ggirotto
Copy link

ggirotto commented Mar 29, 2022

We are facing the exactly same issue as @asavartsov described in iOS 15.4 and flutter 2.10.3 when using UiKitView.

@ert485
Copy link

ert485 commented Mar 14, 2023

Thanks @asavartsov for the description and your workaround. I can't seem to do the same workaround since I'm using a third party library in the webview - I tried catching/disabling touchstart events and creating fake touchend events, but couldn't get it to work with the library. My options left are (1) don't put buttons on top of the webview (below/beside instead), or (2) put the buttons inside the webview instead of being implemented in flutter (and have the html buttons trigger events that get noticed in flutter - which in flutter Web I needed this hack)

@kcisoul
Copy link

kcisoul commented Apr 10, 2023

I spent couple of days to solve this problem.
I think I tried every workaround here and stackOverflow.
Finally I got the answer myself. (it's just simple workaround.)
When you need to draw widgets over WebView, add empty transparent webView over the original webView.

I wrote code like this

Stack(children: [
Opacity(
opacity: 0.01,
child: WebViewWidget(controller: WebViewController())
),
const CircularProgressIndicator(),
]);

This works fine so far.

@cyanglaz
Copy link
Contributor

cyanglaz commented Jun 8, 2023

@kcisoul Thanks for providing the workaround. To make the workaround easier, I think you only need to create an empty transparent PlatformView (UIView) to cover the region that you don't want the WebView to be interacted with.

@903496130
Copy link

903496130 commented Jul 5, 2023

@kcisoul
you are my superman, boy

@flutter-triage-bot flutter-triage-bot bot added the package flutter/packages repository. See also p: labels. label Jul 5, 2023
@Hixie Hixie removed the plugin label Jul 6, 2023
@cyanglaz cyanglaz self-assigned this Jul 6, 2023
@LouiseHsu
Copy link
Contributor

@krokyze yep! thats the plan

@LouiseHsu
Copy link
Contributor

Update: Plan to merge next week post holiday weekend

auto-submit bot pushed a commit to flutter/packages that referenced this issue Nov 30, 2023
Addresses flutter/flutter#30143 by adding an iOS implementation 

This PR is Part 1 of #5233
auto-submit bot added a commit to flutter/packages that referenced this issue Nov 30, 2023
Reverts #5499
Initiated by: stuartmorgan
This change reverts the following previous change:
Original Description:
Addresses flutter/flutter#30143 by adding an iOS implementation 

This PR is Part 1 of #5233
auto-submit bot pushed a commit to flutter/packages that referenced this issue Nov 30, 2023
Addresses flutter/flutter#30143 by adding an iOS implementation

This PR is Part 1 of #5233

This reverts commit bc72d15 and then fixes the topic format
auto-submit bot pushed a commit to flutter/packages that referenced this issue Dec 6, 2023
…ion to federated structure (#5500)

Addresses flutter/flutter#30143 by adding an iOS implementation 

This PR is Part 2 of #5233
auto-submit bot added a commit to flutter/packages that referenced this issue Dec 6, 2023
…plementation to federated structure" (#5591)

Reverts #5500
Initiated by: stuartmorgan
This change reverts the following previous change:
Original Description:
Addresses flutter/flutter#30143 by adding an iOS implementation 

This PR is Part 2 of #5233
auto-submit bot pushed a commit to flutter/packages that referenced this issue Dec 7, 2023
This is essentially the same PR as #5500, with pubspec updates
Addresses flutter/flutter#30143 by adding an iOS implementation

This PR is Part 2 of #5233
auto-submit bot pushed a commit to flutter/packages that referenced this issue Dec 11, 2023
Addresses flutter/flutter#30143 by adding an iOS implementation, and flutter/flutter#138217 by fixing README links

This PR is Part 3/3 of #5233
@LouiseHsu
Copy link
Contributor

The new pointer_interceptor package should be available on pub.dev. now! https://pub.dev/packages/pointer_interceptor

@danagbemava-nc danagbemava-nc added the r: fixed Issue is closed as already fixed in a newer version label Dec 12, 2023
HugoOlthof pushed a commit to moneybird/packages that referenced this issue Dec 13, 2023
Addresses flutter/flutter#30143 by adding an iOS implementation 

This PR is Part 1 of flutter#5233
HugoOlthof pushed a commit to moneybird/packages that referenced this issue Dec 13, 2023
Reverts flutter#5499
Initiated by: stuartmorgan
This change reverts the following previous change:
Original Description:
Addresses flutter/flutter#30143 by adding an iOS implementation 

This PR is Part 1 of flutter#5233
HugoOlthof pushed a commit to moneybird/packages that referenced this issue Dec 13, 2023
Addresses flutter/flutter#30143 by adding an iOS implementation

This PR is Part 1 of flutter#5233

This reverts commit bc72d15 and then fixes the topic format
HugoOlthof pushed a commit to moneybird/packages that referenced this issue Dec 13, 2023
…ion to federated structure (flutter#5500)

Addresses flutter/flutter#30143 by adding an iOS implementation 

This PR is Part 2 of flutter#5233
HugoOlthof pushed a commit to moneybird/packages that referenced this issue Dec 13, 2023
…plementation to federated structure" (flutter#5591)

Reverts flutter#5500
Initiated by: stuartmorgan
This change reverts the following previous change:
Original Description:
Addresses flutter/flutter#30143 by adding an iOS implementation 

This PR is Part 2 of flutter#5233
HugoOlthof pushed a commit to moneybird/packages that referenced this issue Dec 13, 2023
This is essentially the same PR as flutter#5500, with pubspec updates
Addresses flutter/flutter#30143 by adding an iOS implementation

This PR is Part 2 of flutter#5233
HugoOlthof pushed a commit to moneybird/packages that referenced this issue Dec 13, 2023
…ter#5640)

Addresses flutter/flutter#30143 by adding an iOS implementation, and flutter/flutter#138217 by fixing README links

This PR is Part 3/3 of flutter#5233
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 Dec 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: platform-views Embedding Android/iOS views in Flutter apps customer: money (g3) found in release: 2.2 Found to occur in 2.2 found in release: 2.5 Found to occur in 2.5 p: webview The WebView plugin P0 Critical issues such as a build break or regression package flutter/packages repository. See also p: labels. platform-ios iOS applications specifically r: fixed Issue is closed as already fixed in a newer version team-ios Owned by iOS platform team triaged-ios Triaged by iOS platform team
Development

No branches or pull requests