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

fix(5907): webview bouncing issue on ios 16 #5909

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

rpanadero
Copy link

Fixes issue #5907

@jcesarmobile
Copy link
Member

Can you provide a video or gif of the behavior before and after the change?
I have tested the code and the WebView is still bouncing with the proposed changes.

@thoasty-dev
Copy link

I can confirm the fix works. Would be great if you got this merged.

@kemalcany
Copy link

Tested on the simulator and the bouncing seems to be fixed (haven't tested on a physical device tho)

@giralte-ionic
Copy link
Contributor

Could we get some videos or gifs of the problem behavior? We are thinking this may be a 16.0 issue and could be fixed in 16.1, so I'd also recommend testing with the current iOS Beta

@thoasty-dev
Copy link

thoasty-dev commented Oct 13, 2022

It is not fixed on iOS 16.1 Developer Beta.

Video from a real device (iPhone 14 Pro): https://imgur.com/a/40XFTc0

@fabltd
Copy link

fabltd commented Oct 17, 2022

How do I install this branch?

@Sharcoux
Copy link

@rpanadero Do you use your fork internally? How can we use it?

@rpanadero
Copy link
Author

rpanadero commented Nov 24, 2022

@rpanadero Do you use your fork internally? How can we use it?

@Sharcoux no, I don't. As a temporal fix until this PR is merged/reviewed, I developed an ad-hoc plugin for my project that changes the Capacitor webview configuration. Just add these two files to your iOS project:

WebViewPlugin.m

#import <Capacitor/Capacitor.h>

CAP_PLUGIN(WebViewPlugin, "WebViewPlugin",)

WebViewPlugin.swift

import Capacitor

@objc(WebViewPlugin)
public class WebViewPlugin: CAPPlugin {
    @objc override public func load() {
        // Called when the plugin is first constructed in the bridge
        self.bridge?.webView?.scrollView.bounces = false
        self.bridge?.webView?.scrollView.alwaysBounceVertical = false
        self.bridge?.webView?.scrollView.alwaysBounceHorizontal = false
    }
}

After adding/creating them to your iOS project, be sure that the files are included in the bundle resources.

@IJustDev
Copy link

@rpanadero thank you very much this works for me!

If anybody reading this and don't know how to put this in practice:

  • open Xcode (VSCode won't track them in the build process)
  • create both files respectively on the same level as AppDelegate

Copy link

@IJustDev IJustDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@willgardner9
Copy link

Thanks for the instructions @rpanadero and @IJustDev! I can't seem to get web view bounce to stop. I have created both files in the same dir as the AppDelegate.swift - I'm sure this is my fault for missing something

Screenshot 2022-11-28 at 15 17 49

Do I need to create a bridging file or anything? I can see the Xcode project has changed and the files are present in my ./ios/App/App.xcodeproj/project.pbxproj file

Appreciate all your efforts on this, thanks so much 🙌

@IJustDev
Copy link

Do these files appear in XCode?

@willgardner9
Copy link

Yep, the files appear as expected in XCode

Screenshot of XCode file explorer showing WebViewPlugin.m and WebViewPlugin.swift in the same level as AppDelegate.swift

I also experimented by adding:

  ios: {
    scrollEnabled: false,
  },

to my capacitor.config.ts and that still didn't fix the bounce, so I think perhaps there is some other issue at work not related to the code in this PR. Have run npx cap sync etc, will report back if I find out what's going on 👍

@bsalesc
Copy link
Contributor

bsalesc commented Dec 7, 2022

The above code didn't work, so creating an object c file with the below code worked for me:

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@implementation UIScrollView (NoBounce)
- (void)didMoveToWindow {
    [super didMoveToWindow];
    self.bounces = NO;
}
@end

Found this code here: #1169 (comment)

So maybe moving this piece of code inside WKWebView+Capacitor.m might work for everyone?

@piotrfonte
Copy link

piotrfonte commented Dec 20, 2022

Can’t get any of the above snippets to work to solve the problem. How can I check if added files get included in the bundle?

@thoasty-dev
Copy link

This is not an issue anymore on iOS 16.2

@piotrfonte
Copy link

Gotcha. Can confirm that this is fixed in iOS 16.2.

@BenjaminDish
Copy link

This is not an issue anymore on iOS 16.2

@thoasty-dev You say it is fixed on ios 16.2 but i can't understand what is the expected behaviour.

Is bouncing automatically disabled in capacitor apps by default ? (i don't think so as bouncing is ON on my ios 14 iphone)

Or, does it need any configuration/code to disable it ? If yes, which one ?

@brilliantinsane
Copy link

Will this ever be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet