Skip to content

Commit

Permalink
[webview_flutter] Update minimum Flutter version to 3.3 and iOS 11 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jmagman authored Mar 2, 2023
1 parent 60637eb commit b7812d9
Show file tree
Hide file tree
Showing 20 changed files with 89 additions and 114 deletions.
4 changes: 4 additions & 0 deletions packages/webview_flutter/webview_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.0.6

* Updates iOS minimum version in README.

## 4.0.5

* Updates links for the merge of flutter/plugins into flutter/packages.
Expand Down
6 changes: 3 additions & 3 deletions packages/webview_flutter/webview_flutter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ A Flutter plugin that provides a WebView widget.
On iOS the WebView widget is backed by a [WKWebView](https://developer.apple.com/documentation/webkit/wkwebview).
On Android the WebView widget is backed by a [WebView](https://developer.android.com/reference/android/webkit/WebView).

| | Android | iOS |
|-------------|----------------|------|
| **Support** | SDK 19+ or 20+ | 9.0+ |
| | Android | iOS |
|-------------|----------------|-------|
| **Support** | SDK 19+ or 20+ | 11.0+ |

## Usage
Add `webview_flutter` as a [dependency in your pubspec.yaml file](https://pub.dev/packages/webview_flutter/install).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>11.0</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
# platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -274,7 +274,7 @@
isa = PBXProject;
attributes = {
DefaultBuildSystemTypeForWorkspace = Original;
LastUpgradeCheck = 1030;
LastUpgradeCheck = 1300;
ORGANIZATIONNAME = "The Flutter Authors";
TargetAttributes = {
68BDCAE823C3F7CB00D9C032 = {
Expand Down Expand Up @@ -363,10 +363,12 @@
};
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand All @@ -377,6 +379,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -552,7 +555,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -602,7 +605,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1030"
LastUpgradeVersion = "1300"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,17 @@ - (void)testCanInitFLTWebViewFactory {
XCTAssertNotNil(factory);
}

- (void)webViewContentInsetBehaviorShouldBeNeverOnIOS11 {
if (@available(iOS 11, *)) {
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;
XCTAssertEqual(webView.scrollView.contentInsetAdjustmentBehavior,
UIScrollViewContentInsetAdjustmentNever);
}
- (void)webViewContentInsetBehaviorShouldBeNever {
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;
XCTAssertEqual(webView.scrollView.contentInsetAdjustmentBehavior,
UIScrollViewContentInsetAdjustmentNever);
}

- (void)testWebViewScrollIndicatorAticautomaticallyAdjustsScrollIndicatorInsetsShouldbeNoOnIOS13 {
Expand All @@ -76,16 +74,14 @@ - (void)testContentInsetsSumAlwaysZeroAfterSetFrame {
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(webView.scrollView.contentInset, UIEdgeInsetsZero));
XCTAssertTrue(CGRectEqualToRect(webView.frame, CGRectMake(0, 0, 300, 200)));

if (@available(iOS 11, *)) {
// After iOS 11, we need to make sure the contentInset compensates the adjustedContentInset.
UIScrollView *partialMockScrollView = OCMPartialMock(webView.scrollView);
UIEdgeInsets insetToAdjust = UIEdgeInsetsMake(0, 0, 300, 0);
OCMStub(partialMockScrollView.adjustedContentInset).andReturn(insetToAdjust);
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(webView.scrollView.contentInset, UIEdgeInsetsZero));
webView.frame = CGRectMake(0, 0, 300, 100);
XCTAssertTrue(feq(webView.scrollView.contentInset.bottom, -insetToAdjust.bottom));
XCTAssertTrue(CGRectEqualToRect(webView.frame, CGRectMake(0, 0, 300, 100)));
}
// Make sure the contentInset compensates the adjustedContentInset.
UIScrollView *partialMockScrollView = OCMPartialMock(webView.scrollView);
UIEdgeInsets insetToAdjust = UIEdgeInsetsMake(0, 0, 300, 0);
OCMStub(partialMockScrollView.adjustedContentInset).andReturn(insetToAdjust);
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(webView.scrollView.contentInset, UIEdgeInsetsZero));
webView.frame = CGRectMake(0, 0, 300, 100);
XCTAssertTrue(feq(webView.scrollView.contentInset.bottom, -insetToAdjust.bottom));
XCTAssertTrue(CGRectEqualToRect(webView.frame, CGRectMake(0, 0, 300, 100)));
}

@end
2 changes: 1 addition & 1 deletion packages/webview_flutter/webview_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: webview_flutter
description: A Flutter plugin that provides a WebView widget on Android and iOS.
repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22
version: 4.0.5
version: 4.0.6

environment:
sdk: ">=2.17.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.2.0

* Updates minimum Flutter version to 3.3 and iOS 11.

## 3.1.1

* Updates links for the merge of flutter/plugins into flutter/packages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ @interface FWFHTTPCookieStoreHostApiTests : XCTestCase
@end

@implementation FWFHTTPCookieStoreHostApiTests
- (void)testCreateFromWebsiteDataStoreWithIdentifier API_AVAILABLE(ios(11.0)) {
- (void)testCreateFromWebsiteDataStoreWithIdentifier {
FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
FWFHTTPCookieStoreHostApiImpl *hostAPI =
[[FWFHTTPCookieStoreHostApiImpl alloc] initWithInstanceManager:instanceManager];
Expand All @@ -28,7 +28,7 @@ - (void)testCreateFromWebsiteDataStoreWithIdentifier API_AVAILABLE(ios(11.0)) {
XCTAssertNil(error);
}

- (void)testSetCookie API_AVAILABLE(ios(11.0)) {
- (void)testSetCookie {
WKHTTPCookieStore *mockHttpCookieStore = OCMClassMock([WKHTTPCookieStore class]);

FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ - (void)testEvaluateJavaScriptReturnsNSErrorData {
XCTAssertEqualObjects(errorData.localizedDescription, @"description");
}

- (void)testWebViewContentInsetBehaviorShouldBeNeverOnIOS11 API_AVAILABLE(ios(11.0)) {
- (void)testWebViewContentInsetBehaviorShouldBeNever {
FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init];
FWFWebViewHostApiImpl *hostAPI = [[FWFWebViewHostApiImpl alloc]
initWithBinaryMessenger:OCMProtocolMock(@protocol(FlutterBinaryMessenger))
Expand Down Expand Up @@ -454,16 +454,14 @@ - (void)testContentInsetsSumAlwaysZeroAfterSetFrame {
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(webView.scrollView.contentInset, UIEdgeInsetsZero));
XCTAssertTrue(CGRectEqualToRect(webView.frame, CGRectMake(0, 0, 300, 200)));

if (@available(iOS 11, *)) {
// After iOS 11, we need to make sure the contentInset compensates the adjustedContentInset.
UIScrollView *partialMockScrollView = OCMPartialMock(webView.scrollView);
UIEdgeInsets insetToAdjust = UIEdgeInsetsMake(0, 0, 300, 0);
OCMStub(partialMockScrollView.adjustedContentInset).andReturn(insetToAdjust);
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(webView.scrollView.contentInset, UIEdgeInsetsZero));

webView.frame = CGRectMake(0, 0, 300, 100);
XCTAssertTrue(feq(webView.scrollView.contentInset.bottom, -insetToAdjust.bottom));
XCTAssertTrue(CGRectEqualToRect(webView.frame, CGRectMake(0, 0, 300, 100)));
}
// Make sure the contentInset compensates the adjustedContentInset.
UIScrollView *partialMockScrollView = OCMPartialMock(webView.scrollView);
UIEdgeInsets insetToAdjust = UIEdgeInsetsMake(0, 0, 300, 0);
OCMStub(partialMockScrollView.adjustedContentInset).andReturn(insetToAdjust);
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(webView.scrollView.contentInset, UIEdgeInsetsZero));

webView.frame = CGRectMake(0, 0, 300, 100);
XCTAssertTrue(feq(webView.scrollView.contentInset.bottom, -insetToAdjust.bottom));
XCTAssertTrue(CGRectEqualToRect(webView.frame, CGRectMake(0, 0, 300, 100)));
}
@end
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ extern WKUserScriptInjectionTime FWFWKUserScriptInjectionTimeFromEnumData(
*
* @return A WKAudiovisualMediaType or -1 if data could not be converted.
*/
API_AVAILABLE(ios(10.0))
extern WKAudiovisualMediaTypes FWFWKAudiovisualMediaTypeFromEnumData(
FWFWKAudiovisualMediaTypeEnumData *data);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ WKUserScriptInjectionTime FWFWKUserScriptInjectionTimeFromEnumData(
return -1;
}

API_AVAILABLE(ios(10.0))
WKAudiovisualMediaTypes FWFWKAudiovisualMediaTypeFromEnumData(
FWFWKAudiovisualMediaTypeEnumData *data) {
switch (data.value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,28 @@ - (instancetype)initWithInstanceManager:(FWFInstanceManager *)instanceManager {
return self;
}

- (WKHTTPCookieStore *)HTTPCookieStoreForIdentifier:(NSNumber *)identifier
API_AVAILABLE(ios(11.0)) {
- (WKHTTPCookieStore *)HTTPCookieStoreForIdentifier:(NSNumber *)identifier {
return (WKHTTPCookieStore *)[self.instanceManager instanceForIdentifier:identifier.longValue];
}

- (void)createFromWebsiteDataStoreWithIdentifier:(nonnull NSNumber *)identifier
dataStoreIdentifier:(nonnull NSNumber *)websiteDataStoreIdentifier
error:(FlutterError *_Nullable __autoreleasing *_Nonnull)
error {
if (@available(iOS 11.0, *)) {
WKWebsiteDataStore *dataStore = (WKWebsiteDataStore *)[self.instanceManager
instanceForIdentifier:websiteDataStoreIdentifier.longValue];
[self.instanceManager addDartCreatedInstance:dataStore.httpCookieStore
withIdentifier:identifier.longValue];
} else {
*error = [FlutterError
errorWithCode:@"FWFUnsupportedVersionError"
message:@"WKWebsiteDataStore.httpCookieStore is only supported on versions 11+."
details:nil];
}
WKWebsiteDataStore *dataStore = (WKWebsiteDataStore *)[self.instanceManager
instanceForIdentifier:websiteDataStoreIdentifier.longValue];
[self.instanceManager addDartCreatedInstance:dataStore.httpCookieStore
withIdentifier:identifier.longValue];
}

- (void)setCookieForStoreWithIdentifier:(nonnull NSNumber *)identifier
cookie:(nonnull FWFNSHttpCookieData *)cookie
completion:(nonnull void (^)(FlutterError *_Nullable))completion {
NSHTTPCookie *nsCookie = FWFNSHTTPCookieFromCookieData(cookie);

if (@available(iOS 11.0, *)) {
[[self HTTPCookieStoreForIdentifier:identifier] setCookie:nsCookie
completionHandler:^{
completion(nil);
}];
} else {
completion([FlutterError errorWithCode:@"FWFUnsupportedVersionError"
message:@"setCookie is only supported on versions 11+."
details:nil]);
}
[[self HTTPCookieStoreForIdentifier:identifier] setCookie:nsCookie
completionHandler:^{
completion(nil);
}];
}
@end
Original file line number Diff line number Diff line change
Expand Up @@ -117,28 +117,10 @@ - (void)setAllowsInlineMediaPlaybackForConfigurationWithIdentifier:(nonnull NSNu

WKWebViewConfiguration *configuration =
(WKWebViewConfiguration *)[self webViewConfigurationForIdentifier:identifier];
if (@available(iOS 10.0, *)) {
WKAudiovisualMediaTypes typesInt = 0;
for (FWFWKAudiovisualMediaTypeEnumData *data in types) {
typesInt |= FWFWKAudiovisualMediaTypeFromEnumData(data);
}
[configuration setMediaTypesRequiringUserActionForPlayback:typesInt];
} else {
for (FWFWKAudiovisualMediaTypeEnumData *data in types) {
switch (data.value) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
case FWFWKAudiovisualMediaTypeEnumNone:
configuration.requiresUserActionForMediaPlayback = false;
break;
case FWFWKAudiovisualMediaTypeEnumAudio:
case FWFWKAudiovisualMediaTypeEnumVideo:
case FWFWKAudiovisualMediaTypeEnumAll:
configuration.requiresUserActionForMediaPlayback = true;
break;
#pragma clang diagnostic pop
}
}
WKAudiovisualMediaTypes typesInt = 0;
for (FWFWKAudiovisualMediaTypeEnumData *data in types) {
typesInt |= FWFWKAudiovisualMediaTypeFromEnumData(data);
}
[configuration setMediaTypesRequiringUserActionForPlayback:typesInt];
}
@end
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ - (instancetype)initWithFrame:(CGRect)frame
if (self) {
_objectApi = [[FWFObjectFlutterApiImpl alloc] initWithBinaryMessenger:binaryMessenger
instanceManager:instanceManager];
if (@available(iOS 11.0, *)) {
self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
if (@available(iOS 13.0, *)) {
self.scrollView.automaticallyAdjustsScrollIndicatorInsets = NO;
}

self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
if (@available(iOS 13.0, *)) {
self.scrollView.automaticallyAdjustsScrollIndicatorInsets = NO;
}
}
return self;
Expand All @@ -34,16 +33,15 @@ - (void)setFrame:(CGRect)frame {
[super setFrame:frame];
// Prevents the contentInsets from being adjusted by iOS and gives control to Flutter.
self.scrollView.contentInset = UIEdgeInsetsZero;
if (@available(iOS 11, *)) {
// Above iOS 11, adjust contentInset to compensate the adjustedContentInset so the sum will
// always be 0.
if (UIEdgeInsetsEqualToEdgeInsets(self.scrollView.adjustedContentInset, UIEdgeInsetsZero)) {
return;
}
UIEdgeInsets insetToAdjust = self.scrollView.adjustedContentInset;
self.scrollView.contentInset = UIEdgeInsetsMake(-insetToAdjust.top, -insetToAdjust.left,
-insetToAdjust.bottom, -insetToAdjust.right);

// Adjust contentInset to compensate the adjustedContentInset so the sum will
// always be 0.
if (UIEdgeInsetsEqualToEdgeInsets(self.scrollView.adjustedContentInset, UIEdgeInsetsZero)) {
return;
}
UIEdgeInsets insetToAdjust = self.scrollView.adjustedContentInset;
self.scrollView.contentInset = UIEdgeInsetsMake(-insetToAdjust.top, -insetToAdjust.left,
-insetToAdjust.bottom, -insetToAdjust.right);
}

- (void)observeValueForKeyPath:(NSString *)keyPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ Downloaded by pub (not CocoaPods).
s.module_map = 'Classes/FlutterWebView.modulemap'
s.dependency 'Flutter'

s.platform = :ios, '9.0'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
s.platform = :ios, '11.0'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
end
Loading

0 comments on commit b7812d9

Please # to comment.