Skip to content

feat(ios): optional tradeoff to fix ios input delay#1665

Merged
pichillilorenzo merged 1 commit intopichillilorenzo:masterfrom
andreasgangso:feat/disable-ios-delay
Nov 9, 2023
Merged

feat(ios): optional tradeoff to fix ios input delay#1665
pichillilorenzo merged 1 commit intopichillilorenzo:masterfrom
andreasgangso:feat/disable-ios-delay

Conversation

@andreasgangso
Copy link
Copy Markdown
Contributor

@andreasgangso andreasgangso commented May 23, 2023

Connection with issue(s)

Resolves issue #1268

Possibly connected to #216

Testing and Review Notes

Description
There's a very noticable input delay on iOS which is not usable if you want websites with a lot of gestures (e.g. games or similar). To test, simply have a website with a button and see how long it takes to click it before and after enabling the new preventGestureDelay flag.

Cause
I understand this is somehow caused by flutter's DelayingGestureRecognizer.

I honestly don't understand what makes the "WaitUntilTouchesEnded" policy work better here, but it removes the delay.
Other solutions include disabling the DelayingGestureRecognizer completely, but that's very hacky compared to using an official option.

I see google maps is using this policy, so it can't be too bad?
https://github.com/flutter/packages/blob/d449a17f8706850388a16d8acc72398c2118cf9a/packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/FLTGoogleMapsPlugin.m#L16

Tradeoffs
I put this behind the optional flag preventGestureDelay because this has 1 known tradeoff.
This makes the gestures to always fall through to the webview, even if there are opaque widgets stacked on top of it (see
flutter/flutter#94325 (comment))

To Do

  • double check the original issue to confirm it is fully satisfied
  • add testing notes and screenshots in PR description to help guide reviewers

@andreasgangso
Copy link
Copy Markdown
Contributor Author

Any opinions on this @pichillilorenzo?
What are the chances of this being merged?

@harryhjsh
Copy link
Copy Markdown

Any chance of this getting merged?

@andreasgangso
Copy link
Copy Markdown
Contributor Author

andreasgangso commented Jul 31, 2023

Any update @pichillilorenzo?
I'd be happy to do edits if you got any comments.

@andreasgangso
Copy link
Copy Markdown
Contributor Author

@pichillilorenzo let me know if anything needs to be done here

@pichillilorenzo
Copy link
Copy Markdown
Owner

pichillilorenzo commented Nov 9, 2023

@andreasgangso I was trying this fix but currently, I don't see any delay improvements in using FlutterPlatformViewGestureRecognizersBlockingPolicyWaitUntilTouchesEnded.
For example, if you double-tap quickly on a button, it still counts as just one tap.

Instead, adding this code inside hitTest override method of InAppWebView.swift:

public override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
  // other code ...

      if let gestures = superview?.superview?.gestureRecognizers {
          for gesture in gestures {
              if NSStringFromClass(type(of: gesture)) == "DelayingGestureRecognizer" {
                  gesture.isEnabled = false
              }
          }
      }
  // other code ...
}

it seems to work.

I can update this code to work with preventGestureDelay property and call that piece of code only if it is true

@pichillilorenzo pichillilorenzo changed the title feat(ios): optional tradeoff to fix input delay feat(ios): optional tradeoff to fix ios input delay Nov 9, 2023
@pichillilorenzo
Copy link
Copy Markdown
Owner

pichillilorenzo commented Nov 9, 2023

About the tradeoffs, it seems to work correctly also with flutter widgets that are over the webview, such as ElevatedButton.
The flutter button tap event seems to not fall through the webview.

I'm using Flutter 3.13.8

@pichillilorenzo pichillilorenzo merged commit 34e6bea into pichillilorenzo:master Nov 9, 2023
@pichillilorenzo
Copy link
Copy Markdown
Owner

@all-contributors please add @andreasgangso for code

@allcontributors
Copy link
Copy Markdown
Contributor

@pichillilorenzo

I've put up a pull request to add @andreasgangso! 🎉

@andreasgangso andreasgangso deleted the feat/disable-ios-delay branch November 10, 2023 13:37
@andreasgangso andreasgangso restored the feat/disable-ios-delay branch November 13, 2023 08:25
@andreasgangso andreasgangso deleted the feat/disable-ios-delay branch November 13, 2023 15:24
@codemobiles
Copy link
Copy Markdown

I still see the delay problem. Have the problem been really fixed in v6.0.0-beta.28? Thanks

@andreasgangso
Copy link
Copy Markdown
Contributor Author

I still see the delay problem. Have the problem been really fixed in v6.0.0-beta.28? Thanks

Are you using the preventGestureDelay flag?

@pichillilorenzo
Copy link
Copy Markdown
Owner

@codemobiles using the InAppWebView.preventGestureDelay parameter. It should disable the Flutter native delay gesture.

@codemobiles
Copy link
Copy Markdown

Thanks so much. I forgot to set preventGestureDelay first. ex: InAppWebView(...preventGestureDelay: true,); It fixed the problem. @andreasgangso @pichillilorenzo

@tangsj
Copy link
Copy Markdown

tangsj commented Jul 4, 2025

On version 6.1.5, the preventGestureDelay parameter seems to have no effect.

@andreasgangso
Copy link
Copy Markdown
Contributor Author

On version 6.1.5, the preventGestureDelay parameter seems to have no effect.

Any reason you're not using webview_flutter? I migrated to it a year ago. It's actively maintained and has a lot of features now. Don't think i had this problem with that one.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants