diff --git a/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md b/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md index 07544187be1a..ffd9a1222dc9 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.23.9 + +* Updates platform views on iOS to only have a weak reference to the native view. + ## 3.23.8 * Fixes lossy transition from Dart Color to native UIColor when calling `setBackgroundColor`. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/PlatformViewImplTests.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/PlatformViewImplTests.swift new file mode 100644 index 000000000000..be9a9ff1b64e --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/Tests/PlatformViewImplTests.swift @@ -0,0 +1,25 @@ +// Copyright 2013 The Flutter Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import XCTest + +@testable import webview_flutter_wkwebview + +#if os(iOS) + import UIKit +#endif + +class PlatformViewImplTests: XCTestCase { + #if os(iOS) + func testPlatformViewImplStoresViewWithAWeakReference() { + var view: UIView? = UIView() + let platformView = PlatformViewImpl(uiView: view!) + + XCTAssertNotNil(platformView.uiView) + + view = nil + XCTAssertNil(platformView.uiView) + } + #endif +} diff --git a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FlutterViewFactory.swift b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FlutterViewFactory.swift index 757a329ea364..2e3db6092eb9 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FlutterViewFactory.swift +++ b/packages/webview_flutter/webview_flutter_wkwebview/darwin/webview_flutter_wkwebview/Sources/webview_flutter_wkwebview/FlutterViewFactory.swift @@ -13,23 +13,23 @@ import Foundation #error("Unsupported platform.") #endif -/// Implementation of `FlutterPlatformViewFactory` that retrieves the view from the `WebKitLibraryPigeonInstanceManager`. -class FlutterViewFactory: NSObject, FlutterPlatformViewFactory { - unowned let instanceManager: WebKitLibraryPigeonInstanceManager - - #if os(iOS) - class PlatformViewImpl: NSObject, FlutterPlatformView { - let uiView: UIView +#if os(iOS) + class PlatformViewImpl: NSObject, FlutterPlatformView { + weak var uiView: UIView? - init(uiView: UIView) { - self.uiView = uiView - } + init(uiView: UIView) { + self.uiView = uiView + } - func view() -> UIView { - return uiView - } + func view() -> UIView { + return uiView ?? UIView() } - #endif + } +#endif + +/// Implementation of `FlutterPlatformViewFactory` that retrieves the view from the `WebKitLibraryPigeonInstanceManager`. +class FlutterViewFactory: NSObject, FlutterPlatformViewFactory { + unowned let instanceManager: WebKitLibraryPigeonInstanceManager init(instanceManager: WebKitLibraryPigeonInstanceManager) { self.instanceManager = instanceManager @@ -42,14 +42,9 @@ class FlutterViewFactory: NSObject, FlutterPlatformViewFactory { let identifier: Int64 = args is Int64 ? args as! Int64 : Int64(args as! Int32) let instance: AnyObject? = instanceManager.instance(forIdentifier: identifier) - if let instance = instance as? FlutterPlatformView { - instance.view().frame = frame - return instance - } else { - let view = instance as! UIView - view.frame = frame - return PlatformViewImpl(uiView: view) - } + let view = instance as! UIView + view.frame = frame + return PlatformViewImpl(uiView: view) } #elseif os(macOS) func create( diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner.xcodeproj/project.pbxproj b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner.xcodeproj/project.pbxproj index f7a909728079..37b4858d96e5 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 60; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -43,6 +43,7 @@ 8F1488FE2D2DE27000191744 /* HTTPCookieProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F1488C82D2DE27000191744 /* HTTPCookieProxyAPITests.swift */; }; 8F1488FF2D2DE27000191744 /* NavigationActionProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F1488CB2D2DE27000191744 /* NavigationActionProxyAPITests.swift */; }; 8F1489012D2DE91C00191744 /* AuthenticationChallengeResponseProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F1489002D2DE91C00191744 /* AuthenticationChallengeResponseProxyAPITests.swift */; }; + 8F95A6EE2F5765B50071F2C2 /* PlatformViewImplTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F95A6ED2F5765B50071F2C2 /* PlatformViewImplTests.swift */; }; 8FEC64852DA2C6DC00C48569 /* GetTrustResultResponseProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8FEC64812DA2C6DC00C48569 /* GetTrustResultResponseProxyAPITests.swift */; }; 8FEC64862DA2C6DC00C48569 /* WebpagePreferencesProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8FEC64842DA2C6DC00C48569 /* WebpagePreferencesProxyAPITests.swift */; }; 8FEC64872DA2C6DC00C48569 /* SecCertificateProxyAPITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8FEC64822DA2C6DC00C48569 /* SecCertificateProxyAPITests.swift */; }; @@ -136,6 +137,7 @@ 8F1488E12D2DE27000191744 /* WebViewProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = WebViewProxyAPITests.swift; path = ../../darwin/Tests/WebViewProxyAPITests.swift; sourceTree = SOURCE_ROOT; }; 8F1489002D2DE91C00191744 /* AuthenticationChallengeResponseProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AuthenticationChallengeResponseProxyAPITests.swift; path = ../../darwin/Tests/AuthenticationChallengeResponseProxyAPITests.swift; sourceTree = SOURCE_ROOT; }; 8F66D9D72D1362BE000835F9 /* RunnerTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RunnerTests-Bridging-Header.h"; sourceTree = ""; }; + 8F95A6ED2F5765B50071F2C2 /* PlatformViewImplTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PlatformViewImplTests.swift; path = ../../darwin/Tests/PlatformViewImplTests.swift; sourceTree = SOURCE_ROOT; }; 8FEC64812DA2C6DC00C48569 /* GetTrustResultResponseProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = GetTrustResultResponseProxyAPITests.swift; path = ../../darwin/Tests/GetTrustResultResponseProxyAPITests.swift; sourceTree = SOURCE_ROOT; }; 8FEC64822DA2C6DC00C48569 /* SecCertificateProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SecCertificateProxyAPITests.swift; path = ../../darwin/Tests/SecCertificateProxyAPITests.swift; sourceTree = SOURCE_ROOT; }; 8FEC64832DA2C6DC00C48569 /* SecTrustProxyAPITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SecTrustProxyAPITests.swift; path = ../../darwin/Tests/SecTrustProxyAPITests.swift; sourceTree = SOURCE_ROOT; }; @@ -185,6 +187,7 @@ 68BDCAEA23C3F7CB00D9C032 /* RunnerTests */ = { isa = PBXGroup; children = ( + 8F95A6ED2F5765B50071F2C2 /* PlatformViewImplTests.swift */, 8F0E23512EEB5D6B002AB342 /* ColorProxyAPITests.swift */, 33C8DAD92E8D711500A9B7CA /* TemporaryObjCStub.h */, 33C8DADA2E8D711500A9B7CA /* TemporaryObjCStub.m */, @@ -505,12 +508,10 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh", - "${PODS_CONFIGURATION_BUILD_DIR}/path_provider_foundation/path_provider_foundation_privacy.bundle", "${PODS_CONFIGURATION_BUILD_DIR}/webview_flutter_wkwebview/webview_flutter_wkwebview_privacy.bundle", ); name = "[CP] Copy Pods Resources"; outputPaths = ( - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/path_provider_foundation_privacy.bundle", "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/webview_flutter_wkwebview_privacy.bundle", ); runOnlyForDeploymentPostprocessing = 0; @@ -579,6 +580,7 @@ 8F1488ED2D2DE27000191744 /* ErrorProxyAPITests.swift in Sources */, 8F1488EE2D2DE27000191744 /* NSObjectProxyAPITests.swift in Sources */, 33C8DADB2E8D711500A9B7CA /* TemporaryObjCStub.m in Sources */, + 8F95A6EE2F5765B50071F2C2 /* PlatformViewImplTests.swift in Sources */, 8F1488EF2D2DE27000191744 /* NavigationResponseProxyAPITests.swift in Sources */, 8FEC64852DA2C6DC00C48569 /* GetTrustResultResponseProxyAPITests.swift in Sources */, 8FEC64862DA2C6DC00C48569 /* WebpagePreferencesProxyAPITests.swift in Sources */, diff --git a/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml b/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml index 4b8554e0bb73..7fa309619ba4 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml @@ -2,7 +2,7 @@ name: webview_flutter_wkwebview description: A Flutter plugin that provides a WebView widget based on Apple's WKWebView control. repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_wkwebview issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22 -version: 3.23.8 +version: 3.23.9 environment: sdk: ^3.9.0