From f338843576ac577bc9495d82c88d029a25d8c109 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 4 Dec 2019 09:01:51 -0800 Subject: [PATCH 01/10] fix --- .../webview_flutter/example/lib/main.dart | 19 +++++++++++++++++-- .../ios/Classes/FlutterWebView.m | 4 ++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/webview_flutter/example/lib/main.dart b/packages/webview_flutter/example/lib/main.dart index 4016e1063dad..d2a49b507143 100644 --- a/packages/webview_flutter/example/lib/main.dart +++ b/packages/webview_flutter/example/lib/main.dart @@ -213,7 +213,22 @@ class SampleMenu extends StatelessWidget { _getCookieList(cookies), ], ), - )); + ); + } + + void _onShowUserAgent( + WebViewController controller, BuildContext context) async { + // Send a message with the user agent string to the Toaster JavaScript channel we registered + // with the WebView. + controller.evaluateJavascript( + 'Toaster.postMessage("User Agent: " + navigator.userAgent);'); + } + + void _onNavigationDelegateExample( + WebViewController controller, BuildContext context) async { + final String contentBase64 = + base64Encode(const Utf8Encoder().convert(kNavigationExamplePage)); + await controller.loadUrl('data:text/html;base64,$contentBase64'); } void _onAddToCache(WebViewController controller, BuildContext context) async { @@ -252,7 +267,7 @@ class SampleMenu extends StatelessWidget { WebViewController controller, BuildContext context) async { final String contentBase64 = base64Encode(const Utf8Encoder().convert(kNavigationExamplePage)); - await controller.loadUrl('data:text/html;base64,$contentBase64'); + controller.loadUrl('data:text/html;base64,$contentBase64'); } Widget _getCookieList(String cookies) { diff --git a/packages/webview_flutter/ios/Classes/FlutterWebView.m b/packages/webview_flutter/ios/Classes/FlutterWebView.m index 60fa24052038..b8a6dd179450 100644 --- a/packages/webview_flutter/ios/Classes/FlutterWebView.m +++ b/packages/webview_flutter/ios/Classes/FlutterWebView.m @@ -77,6 +77,10 @@ - (instancetype)initWithFrame:(CGRect)frame [weakSelf onMethodCall:call result:result]; }]; + if (@available(iOS 13.0, *)) { + _webView.scrollView.automaticallyAdjustsScrollIndicatorInsets = NO; + } + [self applySettings:settings]; // TODO(amirh): return an error if apply settings failed once it's possible to do so. // https://github.com/flutter/flutter/issues/36228 From a0df60c70cd8a8d7fd4368829eefda1cc55b3025 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 4 Dec 2019 09:47:45 -0800 Subject: [PATCH 02/10] update version --- packages/webview_flutter/CHANGELOG.md | 4 ++++ packages/webview_flutter/pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/webview_flutter/CHANGELOG.md b/packages/webview_flutter/CHANGELOG.md index c90205d42c11..3f00b2b9987b 100644 --- a/packages/webview_flutter/CHANGELOG.md +++ b/packages/webview_flutter/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.3.17+1 + +* Fix an iOS 13 bug where the scroll indicator shows at random location. + ## 0.3.17 * Fix pedantic lint errors. Added missing documentation and awaited some futures diff --git a/packages/webview_flutter/pubspec.yaml b/packages/webview_flutter/pubspec.yaml index 236d591aea61..54e2553a16bb 100644 --- a/packages/webview_flutter/pubspec.yaml +++ b/packages/webview_flutter/pubspec.yaml @@ -1,6 +1,6 @@ name: webview_flutter description: A Flutter plugin that provides a WebView widget on Android and iOS. -version: 0.3.17 +version: 0.3.17+1 author: Flutter Team homepage: https://github.com/flutter/plugins/tree/master/packages/webview_flutter From 60342143c92ec35486a8e4abc469867cc670ac86 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 4 Dec 2019 09:50:39 -0800 Subject: [PATCH 03/10] fix merge issues --- .../webview_flutter/example/lib/main.dart | 31 +------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/packages/webview_flutter/example/lib/main.dart b/packages/webview_flutter/example/lib/main.dart index d2a49b507143..8aeddf3e8d58 100644 --- a/packages/webview_flutter/example/lib/main.dart +++ b/packages/webview_flutter/example/lib/main.dart @@ -213,38 +213,9 @@ class SampleMenu extends StatelessWidget { _getCookieList(cookies), ], ), - ); - } - - void _onShowUserAgent( - WebViewController controller, BuildContext context) async { - // Send a message with the user agent string to the Toaster JavaScript channel we registered - // with the WebView. - controller.evaluateJavascript( - 'Toaster.postMessage("User Agent: " + navigator.userAgent);'); - } - - void _onNavigationDelegateExample( - WebViewController controller, BuildContext context) async { - final String contentBase64 = - base64Encode(const Utf8Encoder().convert(kNavigationExamplePage)); - await controller.loadUrl('data:text/html;base64,$contentBase64'); - } - - void _onAddToCache(WebViewController controller, BuildContext context) async { - await controller.evaluateJavascript( - 'caches.open("test_caches_entry"); localStorage["test_localStorage"] = "dummy_entry";'); - Scaffold.of(context).showSnackBar(const SnackBar( - content: Text('Added a test entry to cache.'), )); } - void _onListCache(WebViewController controller, BuildContext context) async { - await controller.evaluateJavascript('caches.keys()' - '.then((cacheKeys) => JSON.stringify({"cacheKeys" : cacheKeys, "localStorage" : localStorage}))' - '.then((caches) => Toaster.postMessage(caches))'); - } - void _onClearCache(WebViewController controller, BuildContext context) async { await controller.clearCache(); Scaffold.of(context).showSnackBar(const SnackBar( @@ -267,7 +238,7 @@ class SampleMenu extends StatelessWidget { WebViewController controller, BuildContext context) async { final String contentBase64 = base64Encode(const Utf8Encoder().convert(kNavigationExamplePage)); - controller.loadUrl('data:text/html;base64,$contentBase64'); + await controller.loadUrl('data:text/html;base64,$contentBase64'); } Widget _getCookieList(String cookies) { From 898d4bfd07264a27e6135d3046b86333c8f66ed7 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 4 Dec 2019 09:54:31 -0800 Subject: [PATCH 04/10] fix merge issue --- packages/webview_flutter/example/lib/main.dart | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/webview_flutter/example/lib/main.dart b/packages/webview_flutter/example/lib/main.dart index 8aeddf3e8d58..4016e1063dad 100644 --- a/packages/webview_flutter/example/lib/main.dart +++ b/packages/webview_flutter/example/lib/main.dart @@ -216,6 +216,20 @@ class SampleMenu extends StatelessWidget { )); } + void _onAddToCache(WebViewController controller, BuildContext context) async { + await controller.evaluateJavascript( + 'caches.open("test_caches_entry"); localStorage["test_localStorage"] = "dummy_entry";'); + Scaffold.of(context).showSnackBar(const SnackBar( + content: Text('Added a test entry to cache.'), + )); + } + + void _onListCache(WebViewController controller, BuildContext context) async { + await controller.evaluateJavascript('caches.keys()' + '.then((cacheKeys) => JSON.stringify({"cacheKeys" : cacheKeys, "localStorage" : localStorage}))' + '.then((caches) => Toaster.postMessage(caches))'); + } + void _onClearCache(WebViewController controller, BuildContext context) async { await controller.clearCache(); Scaffold.of(context).showSnackBar(const SnackBar( From 5e80a470bdb2cbd444d9c4e95ec69f27e6ad3c38 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Fri, 13 Dec 2019 16:17:27 -0800 Subject: [PATCH 05/10] set contentInsetAdjustmentBehavior to never --- packages/webview_flutter/ios/Classes/FlutterWebView.m | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/webview_flutter/ios/Classes/FlutterWebView.m b/packages/webview_flutter/ios/Classes/FlutterWebView.m index b8a6dd179450..2ead4f18bb82 100644 --- a/packages/webview_flutter/ios/Classes/FlutterWebView.m +++ b/packages/webview_flutter/ios/Classes/FlutterWebView.m @@ -78,6 +78,7 @@ - (instancetype)initWithFrame:(CGRect)frame }]; if (@available(iOS 13.0, *)) { + _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; _webView.scrollView.automaticallyAdjustsScrollIndicatorInsets = NO; } From 35d497da932471bae0163d131d99069206b9df62 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Thu, 26 Dec 2019 13:59:38 -0800 Subject: [PATCH 06/10] update CHANGELOG --- packages/webview_flutter/CHANGELOG.md | 1 + packages/webview_flutter/ios/Classes/FlutterWebView.m | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/webview_flutter/CHANGELOG.md b/packages/webview_flutter/CHANGELOG.md index da1d84051e64..de1547eedb4d 100644 --- a/packages/webview_flutter/CHANGELOG.md +++ b/packages/webview_flutter/CHANGELOG.md @@ -1,5 +1,6 @@ ## 0.3.19+1 +* On iOS, fix the scroll view content inset is automatically adjusted. After the fix, the content position of the WebView is customizable by Flutter. * Fix an iOS 13 bug where the scroll indicator shows at random location. ## 0.3.19 diff --git a/packages/webview_flutter/ios/Classes/FlutterWebView.m b/packages/webview_flutter/ios/Classes/FlutterWebView.m index eb7e6858281e..e4ed3fc16ed2 100644 --- a/packages/webview_flutter/ios/Classes/FlutterWebView.m +++ b/packages/webview_flutter/ios/Classes/FlutterWebView.m @@ -77,9 +77,12 @@ - (instancetype)initWithFrame:(CGRect)frame [weakSelf onMethodCall:call result:result]; }]; - if (@available(iOS 13.0, *)) { - _webView.scrollView.automaticallyAdjustsScrollIndicatorInsets = NO; + if (@available(iOS 11.0, *)) { + _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } + if (@available(iOS 13.0, *)) { + _webView.scrollView.automaticallyAdjustsScrollIndicatorInsets = NO; + } [self applySettings:settings]; // TODO(amirh): return an error if apply settings failed once it's possible to do so. From 5c08047df5d38b09a062f6ce166eafe8d0c8f1b8 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Thu, 26 Dec 2019 14:01:54 -0800 Subject: [PATCH 07/10] formatting --- packages/webview_flutter/ios/Classes/FlutterWebView.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/webview_flutter/ios/Classes/FlutterWebView.m b/packages/webview_flutter/ios/Classes/FlutterWebView.m index e4ed3fc16ed2..beea803bf818 100644 --- a/packages/webview_flutter/ios/Classes/FlutterWebView.m +++ b/packages/webview_flutter/ios/Classes/FlutterWebView.m @@ -80,9 +80,9 @@ - (instancetype)initWithFrame:(CGRect)frame if (@available(iOS 11.0, *)) { _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } - if (@available(iOS 13.0, *)) { - _webView.scrollView.automaticallyAdjustsScrollIndicatorInsets = NO; - } + if (@available(iOS 13.0, *)) { + _webView.scrollView.automaticallyAdjustsScrollIndicatorInsets = NO; + } [self applySettings:settings]; // TODO(amirh): return an error if apply settings failed once it's possible to do so. From 2ca9b4e2518500c795739a2115cf45f71d3475ec Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 7 Jan 2020 11:48:16 -0800 Subject: [PATCH 08/10] formatting --- .../ios/Tests/FLTWebViewTests.m | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/packages/webview_flutter/ios/Tests/FLTWebViewTests.m b/packages/webview_flutter/ios/Tests/FLTWebViewTests.m index f7a3911bb9d7..1c3df6937bbe 100644 --- a/packages/webview_flutter/ios/Tests/FLTWebViewTests.m +++ b/packages/webview_flutter/ios/Tests/FLTWebViewTests.m @@ -9,7 +9,7 @@ @end -@interface FLTWebViewTests : XCTestCase + @interface FLTWebViewTests : XCTestCase @property(strong, nonatomic) NSObject *mockBinaryMessenger; @@ -37,7 +37,7 @@ - (void)canInitFLTWebViewFactory { XCTAssertNotNil(factory); } -- (void)webViewContentInsetBehaviorShouldBeNeverOnIOS11{ +- (void)webViewContentInsetBehaviorShouldBeNeverOnIOS11 { if (@available(iOS 11, *)) { FLTWebViewController *controller = [[FLTWebViewController alloc] initWithFrame:CGRectMake(0, 0, 300, 400) @@ -47,22 +47,23 @@ - (void)webViewContentInsetBehaviorShouldBeNeverOnIOS11{ UIView *view = controller.view; XCTAssertTrue([view isKindOfClass:WKWebView.class]); WKWebView *webView = (WKWebView *)view; - XCTAssertEqual(webView.scrollView.contentInsetAdjustmentBehavior, UIScrollViewContentInsetAdjustmentNever); + XCTAssertEqual(webView.scrollView.contentInsetAdjustmentBehavior, + UIScrollViewContentInsetAdjustmentNever); } } --(void)webViewScrollIndicatorAticautomaticallyAdjustsScrollIndicatorInsetsShouldbeNoOnIOS13{ - if (@available(iOS 13, *)) { - FLTWebViewController *controller = - [[FLTWebViewController alloc] initWithFrame:CGRectMake(0, 0, 300, 400) - viewIdentifier:1 - arguments:nil - binaryMessenger:self.mockBinaryMessenger]; - UIView *view = controller.view; - XCTAssertTrue([view isKindOfClass:WKWebView.class]); - WKWebView *webView = (WKWebView *)view - XCTAssertFalse(webView.scrollView.automaticallyAdjustsScrollIndicatorInsets); - } +- (void)webViewScrollIndicatorAticautomaticallyAdjustsScrollIndicatorInsetsShouldbeNoOnIOS13 { + if (@available(iOS 13, *)) { + FLTWebViewController *controller = + [[FLTWebViewController alloc] initWithFrame:CGRectMake(0, 0, 300, 400) + viewIdentifier:1 + arguments:nil + binaryMessenger:self.mockBinaryMessenger]; + UIView *view = controller.view; + XCTAssertTrue([view isKindOfClass:WKWebView.class]); + WKWebView *webView = (WKWebView *)view XCTAssertFalse( + webView.scrollView.automaticallyAdjustsScrollIndicatorInsets); + } } @end From 52fa5985abbc9fb4ba19913755fb907b182b386d Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 7 Jan 2020 11:50:36 -0800 Subject: [PATCH 09/10] remove typo --- packages/webview_flutter/ios/Tests/FLTWebViewTests.m | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/webview_flutter/ios/Tests/FLTWebViewTests.m b/packages/webview_flutter/ios/Tests/FLTWebViewTests.m index 1c3df6937bbe..e24654db0934 100644 --- a/packages/webview_flutter/ios/Tests/FLTWebViewTests.m +++ b/packages/webview_flutter/ios/Tests/FLTWebViewTests.m @@ -7,9 +7,7 @@ @import XCTest; @import webview_flutter; -@end - - @interface FLTWebViewTests : XCTestCase +@interface FLTWebViewTests : XCTestCase @property(strong, nonatomic) NSObject *mockBinaryMessenger; From 0ef1a12871cd227dccd8a8b327d2796e7f64e9fc Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 7 Jan 2020 12:55:34 -0800 Subject: [PATCH 10/10] fix compiler error --- packages/webview_flutter/ios/Tests/FLTWebViewTests.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/webview_flutter/ios/Tests/FLTWebViewTests.m b/packages/webview_flutter/ios/Tests/FLTWebViewTests.m index e24654db0934..a545fd75c78c 100644 --- a/packages/webview_flutter/ios/Tests/FLTWebViewTests.m +++ b/packages/webview_flutter/ios/Tests/FLTWebViewTests.m @@ -59,8 +59,8 @@ - (void)webViewScrollIndicatorAticautomaticallyAdjustsScrollIndicatorInsetsShoul binaryMessenger:self.mockBinaryMessenger]; UIView *view = controller.view; XCTAssertTrue([view isKindOfClass:WKWebView.class]); - WKWebView *webView = (WKWebView *)view XCTAssertFalse( - webView.scrollView.automaticallyAdjustsScrollIndicatorInsets); + WKWebView *webView = (WKWebView *)view; + XCTAssertFalse(webView.scrollView.automaticallyAdjustsScrollIndicatorInsets); } }