From 94c9394addfd8f198f6a650ded596e9d42b5e151 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 31 Jan 2023 16:10:17 -0500 Subject: [PATCH 01/12] implementation of the webViewIdentifier field --- .../webview_flutter_android/CHANGELOG.md | 4 ++ .../webviewflutter/WebViewFlutterPlugin.java | 42 ++++++++++++++++++- .../WebViewFlutterPluginTest.java | 21 +++++++++- .../lib/src/android_webview_controller.dart | 10 +++++ .../webview_flutter_android/pubspec.yaml | 2 +- .../test/android_webview_controller_test.dart | 24 +++++++++++ .../webview_flutter_wkwebview/CHANGELOG.md | 4 ++ .../FLTWebViewFlutterPluginTests.m | 27 ++++++++++++ .../ios/Classes/FLTWebViewFlutterPlugin.h | 20 +++++++++ .../ios/Classes/FLTWebViewFlutterPlugin.m | 13 ++++++ .../lib/src/webkit_webview_controller.dart | 10 +++++ .../webview_flutter_wkwebview/pubspec.yaml | 2 +- .../test/webkit_webview_controller_test.dart | 20 +++++++++ 13 files changed, 193 insertions(+), 6 deletions(-) create mode 100644 packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FLTWebViewFlutterPluginTests.m diff --git a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md index 136d71485a0f..ed6c546ed147 100644 --- a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.3.0 + +* Adds support to access native `WebView`. + ## 3.2.4 * Renames Pigeon output files. diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java index 1c5a55057ca6..951a6ebfdffd 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java @@ -7,8 +7,11 @@ import android.content.Context; import android.os.Handler; import android.view.View; +import android.webkit.WebView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.VisibleForTesting; +import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.embedding.engine.plugins.activity.ActivityAware; import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding; @@ -33,12 +36,43 @@ *

Call {@link #registerWith} to use the stable {@code io.flutter.plugin.common} package instead. */ public class WebViewFlutterPlugin implements FlutterPlugin, ActivityAware { - private InstanceManager instanceManager; + @Nullable private InstanceManager instanceManager; private FlutterPluginBinding pluginBinding; private WebViewHostApiImpl webViewHostApi; private JavaScriptChannelHostApiImpl javaScriptChannelHostApi; + /** + * Retrieves the {@link WebView} that is associated with `identifer`. + * + *

See the Dart method `AndroidWebViewController.webViewIdentifier` to get the identifier of an + * underlying `WebView`. + * + * @param engine the execution environment the {@link WebViewFlutterPlugin} should belong to. If + * the engine doesn't contain an attached instance of {@link WebViewFlutterPlugin}, this + * method returns null. + * @param identifier the associated identifier of the `WebView`. + * @return the `WebView` associated with `identifier` or null if a `WebView` instance associated + * with `identifier` could not be found. + */ + @SuppressWarnings("unused") + @Nullable + public static WebView getWebView(FlutterEngine engine, long identifier) { + final WebViewFlutterPlugin webViewPlugin = + (WebViewFlutterPlugin) engine.getPlugins().get(WebViewFlutterPlugin.class); + + if (webViewPlugin == null || webViewPlugin.instanceManager == null) { + return null; + } + + final Object instance = webViewPlugin.instanceManager.getInstance(identifier); + if (instance instanceof WebView) { + return (WebView) instance; + } + + return null; + } + /** * Add an instance of this to {@link io.flutter.embedding.engine.plugins.PluginRegistry} to * register it. @@ -148,7 +182,10 @@ public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) { @Override public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { - instanceManager.close(); + if (instanceManager != null) { + instanceManager.close(); + instanceManager = null; + } } @Override @@ -179,6 +216,7 @@ private void updateContext(Context context) { /** Maintains instances used to communicate with the corresponding objects in Dart. */ @Nullable + @VisibleForTesting public InstanceManager getInstanceManager() { return instanceManager; } diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewFlutterPluginTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewFlutterPluginTest.java index 16dc6cf5de2b..b8cde778708a 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewFlutterPluginTest.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewFlutterPluginTest.java @@ -4,11 +4,16 @@ package io.flutter.plugins.webviewflutter; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import android.content.Context; +import android.webkit.WebView; +import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.plugins.FlutterPlugin; +import io.flutter.embedding.engine.plugins.PluginRegistry; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.platform.PlatformViewRegistry; import org.junit.Rule; @@ -29,7 +34,7 @@ public class WebViewFlutterPluginTest { @Mock FlutterPlugin.FlutterPluginBinding mockPluginBinding; @Test - public void getInstanceManagerAfterOnAttachedToEngine() { + public void getWebView() { final WebViewFlutterPlugin webViewFlutterPlugin = new WebViewFlutterPlugin(); when(mockPluginBinding.getApplicationContext()).thenReturn(mockContext); @@ -38,7 +43,19 @@ public void getInstanceManagerAfterOnAttachedToEngine() { webViewFlutterPlugin.onAttachedToEngine(mockPluginBinding); - assertNotNull(webViewFlutterPlugin.getInstanceManager()); + final InstanceManager instanceManager = webViewFlutterPlugin.getInstanceManager(); + assertNotNull(instanceManager); + + final WebView mockWebView = mock(WebView.class); + instanceManager.addDartCreatedInstance(mockWebView, 0); + + final PluginRegistry mockPluginRegistry = mock(PluginRegistry.class); + when(mockPluginRegistry.get(WebViewFlutterPlugin.class)).thenReturn(webViewFlutterPlugin); + + final FlutterEngine mockFlutterEngine = mock(FlutterEngine.class); + when(mockFlutterEngine.getPlugins()).thenReturn(mockPluginRegistry); + + assertEquals(WebViewFlutterPlugin.getWebView(mockFlutterEngine, 0), mockWebView); webViewFlutterPlugin.onDetachedFromEngine(mockPluginBinding); } diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart index fd287a515c65..6bd3dc03746c 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart @@ -144,6 +144,16 @@ class AndroidWebViewController extends PlatformWebViewController { return webViewProxy.setWebContentsDebuggingEnabled(enabled); } + /// Identifier used to retrieve the underlying native `WKWebView`. + /// + /// This is typically used by other plugins to retrieve the native `WebView` + /// from an `InstanceManager`. + /// + /// See Java method `WebViewFlutterPlugin.getWebView`. + int get webViewIdentifier => + // ignore: invalid_use_of_visible_for_testing_member + android_webview.WebView.api.instanceManager.getIdentifier(_webView)!; + @override Future loadFile( String absoluteFilePath, diff --git a/packages/webview_flutter/webview_flutter_android/pubspec.yaml b/packages/webview_flutter/webview_flutter_android/pubspec.yaml index d90844d9ce08..ac8971006ba2 100644 --- a/packages/webview_flutter/webview_flutter_android/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_android/pubspec.yaml @@ -2,7 +2,7 @@ name: webview_flutter_android description: A Flutter plugin that provides a WebView widget on Android. repository: https://github.com/flutter/plugins/tree/main/packages/webview_flutter/webview_flutter_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22 -version: 3.2.4 +version: 3.3.0 environment: sdk: ">=2.17.0 <3.0.0" diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart index 03e71ec5d987..43bab384e0cc 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart @@ -14,6 +14,7 @@ import 'package:mockito/mockito.dart'; import 'package:webview_flutter_android/src/android_proxy.dart'; import 'package:webview_flutter_android/src/android_webview.dart' as android_webview; +import 'package:webview_flutter_android/src/android_webview_api_impls.dart'; import 'package:webview_flutter_android/src/instance_manager.dart'; import 'package:webview_flutter_android/src/platform_views_service_proxy.dart'; import 'package:webview_flutter_android/webview_flutter_android.dart'; @@ -884,6 +885,29 @@ void main() { verify(mockSettings.setMediaPlaybackRequiresUserGesture(true)).called(1); }); + test('webViewIdentifier', () { + final MockWebView mockWebView = MockWebView(); + final InstanceManager instanceManager = InstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + instanceManager.addHostCreatedInstance(mockWebView, 0); + + android_webview.WebView.api = WebViewHostApiImpl( + instanceManager: instanceManager, + ); + + final AndroidWebViewController controller = createControllerWithMocks( + mockWebView: mockWebView, + ); + + expect( + controller.webViewIdentifier, + 0, + ); + + android_webview.WebView.api = WebViewHostApiImpl(); + }); + group('AndroidWebViewWidget', () { testWidgets('Builds Android view using supplied parameters', (WidgetTester tester) async { diff --git a/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md b/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md index d8442c2c1f0e..d0c5a726b5f7 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.1.0 + +* Adds support to access native `WKWebView`. + ## 3.0.5 * Renames Pigeon output files. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FLTWebViewFlutterPluginTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FLTWebViewFlutterPluginTests.m new file mode 100644 index 000000000000..dac932257a81 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FLTWebViewFlutterPluginTests.m @@ -0,0 +1,27 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import +#import + +@import webview_flutter_wkwebview; + +@interface FLTWebViewFlutterPluginTests : XCTestCase +@end + +@implementation FLTWebViewFlutterPluginTests +- (void)testWebViewForIdentifier { + WKWebView *webView = [[WKWebView alloc] init]; + FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; + [instanceManager addDartCreatedInstance:webView withIdentifier:0]; + + id mockPluginRegistry = OCMProtocolMock(@protocol(FlutterPluginRegistry)); + OCMStub([mockPluginRegistry valuePublishedByPlugin:@"FLTWebViewFlutterPlugin"]) + .andReturn(instanceManager); + + XCTAssertEqualObjects([FLTWebViewFlutterPlugin webViewForIdentifier:0 + withPluginRegistry:mockPluginRegistry], + webView); +} +@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FLTWebViewFlutterPlugin.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FLTWebViewFlutterPlugin.h index 2a80c7d886f2..fe640c67abbf 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FLTWebViewFlutterPlugin.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FLTWebViewFlutterPlugin.h @@ -3,6 +3,26 @@ // found in the LICENSE file. #import +#import + +NS_ASSUME_NONNULL_BEGIN @interface FLTWebViewFlutterPlugin : NSObject +/** +Retrieves the `WKWebView` that is associated with `identifer`. + +See the Dart method `WebKitWebViewController.webViewIdentifier` to get the identifier of an +underlying `WKWebView`. + +@param identifier The associated identifier of the `WebView`. +@param registry The plugin registry the `FLTWebViewFlutterPlugin` should belong to. If + the registry doesn't contain an attached instance of `FLTWebViewFlutterPlugin`, + this method returns nil. +@return The `WKWebView` associated with `identifier` or nil if a `WKWebView` instance associated +with `identifier` could not be found. +*/ ++ (nullable WKWebView *)webViewForIdentifier:(long)identifier + withPluginRegistry:(id)registry; @end + +NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FLTWebViewFlutterPlugin.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FLTWebViewFlutterPlugin.m index 5795018b2043..2f0438729903 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FLTWebViewFlutterPlugin.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FLTWebViewFlutterPlugin.m @@ -108,6 +108,19 @@ + (void)registerWithRegistrar:(NSObject *)registrar { [registrar publish:instanceManager]; } ++ (nullable WKWebView *)webViewForIdentifier:(long)identifier + withPluginRegistry:(id)registry { + FWFInstanceManager *instanceManager = + (FWFInstanceManager *)[registry valuePublishedByPlugin:@"FLTWebViewFlutterPlugin"]; + + NSObject *instance = [instanceManager instanceForIdentifier:identifier]; + if ([instance isKindOfClass:[WKWebView class]]) { + return (WKWebView *)instance; + } + + return nil; +} + - (void)detachFromEngineForRegistrar:(NSObject *)registrar { [registrar publish:[NSNull null]]; } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_controller.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_controller.dart index 02b5b73b5971..8abd0c1afe8a 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_controller.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/webkit_webview_controller.dart @@ -164,6 +164,16 @@ class WebKitWebViewController extends PlatformWebViewController { WebKitWebViewControllerCreationParams get _webKitParams => params as WebKitWebViewControllerCreationParams; + /// Identifier used to retrieve the underlying native `WKWebView`. + /// + /// This is typically used by other plugins to retrieve the native `WKWebView` + /// from an `FWFInstanceManager`. + /// + /// See Objective-C method + /// `FLTWebViewFlutterPlugin:webViewForIdentifier:withPluginRegistry`. + int get webViewIdentifier => + _webKitParams._instanceManager.getIdentifier(_webView)!; + @override Future loadFile(String absoluteFilePath) { return _webView.loadFileUrl( diff --git a/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml b/packages/webview_flutter/webview_flutter_wkwebview/pubspec.yaml index 5c4df9922840..d1aaa7cf9203 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/plugins/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.0.5 +version: 3.1.0 environment: sdk: ">=2.17.0 <3.0.0" diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.dart index 0360c13b052a..b7b729a97926 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/webkit_webview_controller_test.dart @@ -81,6 +81,7 @@ void main() { return nonNullMockWebView; }, ), + instanceManager: instanceManager, ); final WebKitWebViewController controller = WebKitWebViewController( @@ -935,6 +936,25 @@ void main() { expect(callbackProgress, 0); }); + + test('webViewIdentifier', () { + final InstanceManager instanceManager = InstanceManager( + onWeakReferenceRemoved: (_) {}, + ); + final MockWKWebView mockWebView = MockWKWebView(); + when(mockWebView.copy()).thenReturn(MockWKWebView()); + instanceManager.addHostCreatedInstance(mockWebView, 0); + + final WebKitWebViewController controller = createControllerWithMocks( + createMockWebView: (_, {dynamic observeValue}) => mockWebView, + instanceManager: instanceManager, + ); + + expect( + controller.webViewIdentifier, + instanceManager.getIdentifier(mockWebView), + ); + }); }); group('WebKitJavaScriptChannelParams', () { From e050085a9de4a895a51cd2b6d038dd2f9e8335c1 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 8 Feb 2023 15:58:31 -0500 Subject: [PATCH 02/12] change to external classes --- .../WebViewFlutterAndroidExternalApi.java | 49 +++++++++++++++++++ .../webviewflutter/WebViewFlutterPlugin.java | 32 ------------ ...WebViewFlutterAndroidExternalApiTest.java} | 31 +++++++----- ...WebViewFlutterWKWebViewExternalAPITests.m} | 6 +-- .../ios/Classes/FLTWebViewFlutterPlugin.h | 15 ------ .../ios/Classes/FLTWebViewFlutterPlugin.m | 13 ----- .../FWFWebViewFlutterWKWebViewExternalAPI.h | 36 ++++++++++++++ .../FWFWebViewFlutterWKWebViewExternalAPI.m | 21 ++++++++ .../ios/Classes/webview-umbrella.h | 1 + 9 files changed, 129 insertions(+), 75 deletions(-) create mode 100644 packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApi.java rename packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/{WebViewFlutterPluginTest.java => WebViewFlutterAndroidExternalApiTest.java} (82%) rename packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/{FLTWebViewFlutterPluginTests.m => FWFWebViewFlutterWKWebViewExternalAPITests.m} (79%) create mode 100644 packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h create mode 100644 packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.m diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApi.java new file mode 100644 index 000000000000..2d5b7d671044 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApi.java @@ -0,0 +1,49 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package io.flutter.plugins.webviewflutter; + +import android.webkit.WebView; + +import androidx.annotation.Nullable; + +import io.flutter.embedding.engine.FlutterEngine; + +/** + * App and package facing native API provided by the `webview_flutter_android` plugin. + * + * This class follows the convention of breaking changes of the Dart API, which means that any + * changes to the class that are not backwards compatible will only be done with a major version + * change of the plugin. + */ +@SuppressWarnings("unused") +public interface WebViewFlutterAndroidExternalApi { + /** + * Retrieves the {@link WebView} that is associated with `identifier`. + * + *

See the Dart method `AndroidWebViewController.webViewIdentifier` to get the identifier of an + * underlying `WebView`. + * + * @param engine the execution environment the {@link WebViewFlutterPlugin} should belong to. If + * the engine doesn't contain an attached instance of {@link WebViewFlutterPlugin}, this + * method returns null. + * @param identifier the associated identifier of the `WebView`. + * @return the `WebView` associated with `identifier` or null if a `WebView` instance associated + * with `identifier` could not be found. + */ + @Nullable + static WebView getWebView(FlutterEngine engine, long identifier) { + final WebViewFlutterPlugin webViewPlugin = + (WebViewFlutterPlugin) engine.getPlugins().get(WebViewFlutterPlugin.class); + + if (webViewPlugin != null && webViewPlugin.getInstanceManager() != null) { + final Object instance = webViewPlugin.getInstanceManager().getInstance(identifier); + if (instance instanceof WebView) { + return (WebView) instance; + } + } + + return null; + } +} diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java index 951a6ebfdffd..e34a17d6f60d 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java @@ -42,37 +42,6 @@ public class WebViewFlutterPlugin implements FlutterPlugin, ActivityAware { private WebViewHostApiImpl webViewHostApi; private JavaScriptChannelHostApiImpl javaScriptChannelHostApi; - /** - * Retrieves the {@link WebView} that is associated with `identifer`. - * - *

See the Dart method `AndroidWebViewController.webViewIdentifier` to get the identifier of an - * underlying `WebView`. - * - * @param engine the execution environment the {@link WebViewFlutterPlugin} should belong to. If - * the engine doesn't contain an attached instance of {@link WebViewFlutterPlugin}, this - * method returns null. - * @param identifier the associated identifier of the `WebView`. - * @return the `WebView` associated with `identifier` or null if a `WebView` instance associated - * with `identifier` could not be found. - */ - @SuppressWarnings("unused") - @Nullable - public static WebView getWebView(FlutterEngine engine, long identifier) { - final WebViewFlutterPlugin webViewPlugin = - (WebViewFlutterPlugin) engine.getPlugins().get(WebViewFlutterPlugin.class); - - if (webViewPlugin == null || webViewPlugin.instanceManager == null) { - return null; - } - - final Object instance = webViewPlugin.instanceManager.getInstance(identifier); - if (instance instanceof WebView) { - return (WebView) instance; - } - - return null; - } - /** * Add an instance of this to {@link io.flutter.embedding.engine.plugins.PluginRegistry} to * register it. @@ -216,7 +185,6 @@ private void updateContext(Context context) { /** Maintains instances used to communicate with the corresponding objects in Dart. */ @Nullable - @VisibleForTesting public InstanceManager getInstanceManager() { return instanceManager; } diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewFlutterPluginTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApiTest.java similarity index 82% rename from packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewFlutterPluginTest.java rename to packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApiTest.java index b8cde778708a..8c90d4dc31ef 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewFlutterPluginTest.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApiTest.java @@ -11,27 +11,34 @@ import android.content.Context; import android.webkit.WebView; -import io.flutter.embedding.engine.FlutterEngine; -import io.flutter.embedding.engine.plugins.FlutterPlugin; -import io.flutter.embedding.engine.plugins.PluginRegistry; -import io.flutter.plugin.common.BinaryMessenger; -import io.flutter.plugin.platform.PlatformViewRegistry; + import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; -public class WebViewFlutterPluginTest { - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); +import io.flutter.embedding.engine.FlutterEngine; +import io.flutter.embedding.engine.plugins.FlutterPlugin; +import io.flutter.embedding.engine.plugins.PluginRegistry; +import io.flutter.plugin.common.BinaryMessenger; +import io.flutter.plugin.platform.PlatformViewRegistry; + +public class WebViewFlutterAndroidExternalApiTest { + @Rule + public MockitoRule mockitoRule = MockitoJUnit.rule(); - @Mock Context mockContext; + @Mock + Context mockContext; - @Mock BinaryMessenger mockBinaryMessenger; + @Mock + BinaryMessenger mockBinaryMessenger; - @Mock PlatformViewRegistry mockViewRegistry; + @Mock + PlatformViewRegistry mockViewRegistry; - @Mock FlutterPlugin.FlutterPluginBinding mockPluginBinding; + @Mock + FlutterPlugin.FlutterPluginBinding mockPluginBinding; @Test public void getWebView() { @@ -55,7 +62,7 @@ public void getWebView() { final FlutterEngine mockFlutterEngine = mock(FlutterEngine.class); when(mockFlutterEngine.getPlugins()).thenReturn(mockPluginRegistry); - assertEquals(WebViewFlutterPlugin.getWebView(mockFlutterEngine, 0), mockWebView); + assertEquals(WebViewFlutterAndroidExternalApi.getWebView(mockFlutterEngine, 0), mockWebView); webViewFlutterPlugin.onDetachedFromEngine(mockPluginBinding); } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FLTWebViewFlutterPluginTests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewFlutterWKWebViewExternalAPITests.m similarity index 79% rename from packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FLTWebViewFlutterPluginTests.m rename to packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewFlutterWKWebViewExternalAPITests.m index dac932257a81..07e5e3feceb8 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FLTWebViewFlutterPluginTests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewFlutterWKWebViewExternalAPITests.m @@ -7,10 +7,10 @@ @import webview_flutter_wkwebview; -@interface FLTWebViewFlutterPluginTests : XCTestCase +@interface FWFWebViewFlutterWKWebViewExternalAPITests : XCTestCase @end -@implementation FLTWebViewFlutterPluginTests +@implementation FWFWebViewFlutterWKWebViewExternalAPITests - (void)testWebViewForIdentifier { WKWebView *webView = [[WKWebView alloc] init]; FWFInstanceManager *instanceManager = [[FWFInstanceManager alloc] init]; @@ -20,7 +20,7 @@ - (void)testWebViewForIdentifier { OCMStub([mockPluginRegistry valuePublishedByPlugin:@"FLTWebViewFlutterPlugin"]) .andReturn(instanceManager); - XCTAssertEqualObjects([FLTWebViewFlutterPlugin webViewForIdentifier:0 + XCTAssertEqualObjects([FWFWebViewFlutterWKWebViewExternalAPI webViewForIdentifier:0 withPluginRegistry:mockPluginRegistry], webView); } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FLTWebViewFlutterPlugin.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FLTWebViewFlutterPlugin.h index fe640c67abbf..a1c035e40185 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FLTWebViewFlutterPlugin.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FLTWebViewFlutterPlugin.h @@ -8,21 +8,6 @@ NS_ASSUME_NONNULL_BEGIN @interface FLTWebViewFlutterPlugin : NSObject -/** -Retrieves the `WKWebView` that is associated with `identifer`. - -See the Dart method `WebKitWebViewController.webViewIdentifier` to get the identifier of an -underlying `WKWebView`. - -@param identifier The associated identifier of the `WebView`. -@param registry The plugin registry the `FLTWebViewFlutterPlugin` should belong to. If - the registry doesn't contain an attached instance of `FLTWebViewFlutterPlugin`, - this method returns nil. -@return The `WKWebView` associated with `identifier` or nil if a `WKWebView` instance associated -with `identifier` could not be found. -*/ -+ (nullable WKWebView *)webViewForIdentifier:(long)identifier - withPluginRegistry:(id)registry; @end NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FLTWebViewFlutterPlugin.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FLTWebViewFlutterPlugin.m index 2f0438729903..5795018b2043 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FLTWebViewFlutterPlugin.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FLTWebViewFlutterPlugin.m @@ -108,19 +108,6 @@ + (void)registerWithRegistrar:(NSObject *)registrar { [registrar publish:instanceManager]; } -+ (nullable WKWebView *)webViewForIdentifier:(long)identifier - withPluginRegistry:(id)registry { - FWFInstanceManager *instanceManager = - (FWFInstanceManager *)[registry valuePublishedByPlugin:@"FLTWebViewFlutterPlugin"]; - - NSObject *instance = [instanceManager instanceForIdentifier:identifier]; - if ([instance isKindOfClass:[WKWebView class]]) { - return (WKWebView *)instance; - } - - return nil; -} - - (void)detachFromEngineForRegistrar:(NSObject *)registrar { [registrar publish:[NSNull null]]; } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h new file mode 100644 index 000000000000..3dfa635608b6 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h @@ -0,0 +1,36 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +/** +App and package facing native API provided by the `webview_flutter_wkwebview` plugin. + +This class follows the convention of breaking changes of the Dart API, which means that any +changes to the class that are not backwards compatible will only be done with a major version +change of the plugin. +*/ +@interface FWFWebViewFlutterWKWebViewExternalAPI : NSObject +/** +Retrieves the `WKWebView` that is associated with `identifier`. + +See the Dart method `WebKitWebViewController.webViewIdentifier` to get the identifier of an +underlying `WKWebView`. + +@param identifier The associated identifier of the `WebView`. +@param registry The plugin registry the `FLTWebViewFlutterPlugin` should belong to. If + the registry doesn't contain an attached instance of `FLTWebViewFlutterPlugin`, + this method returns nil. +@return The `WKWebView` associated with `identifier` or nil if a `WKWebView` instance associated +with `identifier` could not be found. +*/ ++ (nullable WKWebView *)webViewForIdentifier:(long)identifier + withPluginRegistry:(id)registry; +@end + +NS_ASSUME_NONNULL_END diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.m new file mode 100644 index 000000000000..05d8fbca8cc5 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.m @@ -0,0 +1,21 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "FWFInstanceManager.h" +#import "FWFWebViewFlutterWKWebViewExternalAPI.h" + +@implementation FWFWebViewFlutterWKWebViewExternalAPI ++ (nullable WKWebView *)webViewForIdentifier:(long)identifier + withPluginRegistry:(id)registry { + FWFInstanceManager *instanceManager = + (FWFInstanceManager *)[registry valuePublishedByPlugin:@"FLTWebViewFlutterPlugin"]; + + NSObject *instance = [instanceManager instanceForIdentifier:identifier]; + if ([instance isKindOfClass:[WKWebView class]]) { + return (WKWebView *)instance; + } + + return nil; +} +@end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/webview-umbrella.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/webview-umbrella.h index dbcd876d15c9..b9ba942b4ed5 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/webview-umbrella.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/webview-umbrella.h @@ -17,5 +17,6 @@ #import #import #import +#import #import #import From 441602dfd5d7b0e8222000f76394200186a14c4a Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 8 Feb 2023 15:59:06 -0500 Subject: [PATCH 03/12] formatting --- .../WebViewFlutterAndroidExternalApi.java | 4 +-- .../webviewflutter/WebViewFlutterPlugin.java | 3 --- .../WebViewFlutterAndroidExternalApiTest.java | 27 +++++++------------ ...FWebViewFlutterWKWebViewExternalAPITests.m | 7 ++--- .../FWFWebViewFlutterWKWebViewExternalAPI.h | 2 +- .../FWFWebViewFlutterWKWebViewExternalAPI.m | 2 +- 6 files changed, 17 insertions(+), 28 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApi.java index 2d5b7d671044..1109fb9a806f 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApi.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApi.java @@ -5,15 +5,13 @@ package io.flutter.plugins.webviewflutter; import android.webkit.WebView; - import androidx.annotation.Nullable; - import io.flutter.embedding.engine.FlutterEngine; /** * App and package facing native API provided by the `webview_flutter_android` plugin. * - * This class follows the convention of breaking changes of the Dart API, which means that any + *

This class follows the convention of breaking changes of the Dart API, which means that any * changes to the class that are not backwards compatible will only be done with a major version * change of the plugin. */ diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java index e34a17d6f60d..04a9735e0281 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterPlugin.java @@ -7,11 +7,8 @@ import android.content.Context; import android.os.Handler; import android.view.View; -import android.webkit.WebView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.annotation.VisibleForTesting; -import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.embedding.engine.plugins.activity.ActivityAware; import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding; diff --git a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApiTest.java b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApiTest.java index 8c90d4dc31ef..0877dcaf2b06 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApiTest.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/test/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApiTest.java @@ -11,34 +11,27 @@ import android.content.Context; import android.webkit.WebView; - -import org.junit.Rule; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; - import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.embedding.engine.plugins.PluginRegistry; import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.platform.PlatformViewRegistry; +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; public class WebViewFlutterAndroidExternalApiTest { - @Rule - public MockitoRule mockitoRule = MockitoJUnit.rule(); + @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); - @Mock - Context mockContext; + @Mock Context mockContext; - @Mock - BinaryMessenger mockBinaryMessenger; + @Mock BinaryMessenger mockBinaryMessenger; - @Mock - PlatformViewRegistry mockViewRegistry; + @Mock PlatformViewRegistry mockViewRegistry; - @Mock - FlutterPlugin.FlutterPluginBinding mockPluginBinding; + @Mock FlutterPlugin.FlutterPluginBinding mockPluginBinding; @Test public void getWebView() { diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewFlutterWKWebViewExternalAPITests.m b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewFlutterWKWebViewExternalAPITests.m index 07e5e3feceb8..1452edeaa647 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewFlutterWKWebViewExternalAPITests.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFWebViewFlutterWKWebViewExternalAPITests.m @@ -20,8 +20,9 @@ - (void)testWebViewForIdentifier { OCMStub([mockPluginRegistry valuePublishedByPlugin:@"FLTWebViewFlutterPlugin"]) .andReturn(instanceManager); - XCTAssertEqualObjects([FWFWebViewFlutterWKWebViewExternalAPI webViewForIdentifier:0 - withPluginRegistry:mockPluginRegistry], - webView); + XCTAssertEqualObjects( + [FWFWebViewFlutterWKWebViewExternalAPI webViewForIdentifier:0 + withPluginRegistry:mockPluginRegistry], + webView); } @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h index 3dfa635608b6..5f96fc91e3af 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h @@ -3,8 +3,8 @@ // found in the LICENSE file. #import -#import #import +#import NS_ASSUME_NONNULL_BEGIN diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.m index 05d8fbca8cc5..b1776d818bce 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.m @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#import "FWFInstanceManager.h" #import "FWFWebViewFlutterWKWebViewExternalAPI.h" +#import "FWFInstanceManager.h" @implementation FWFWebViewFlutterWKWebViewExternalAPI + (nullable WKWebView *)webViewForIdentifier:(long)identifier From bd22235887dd363daaa52c4e675e61b789de347b Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 8 Feb 2023 16:12:28 -0500 Subject: [PATCH 04/12] update readmes --- .../webview_flutter_android/README.md | 14 ++++++++++++++ .../WebViewFlutterAndroidExternalApi.java | 2 +- .../webview_flutter_wkwebview/README.md | 16 ++++++++++++++++ .../FWFWebViewFlutterWKWebViewExternalAPI.h | 2 +- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_android/README.md b/packages/webview_flutter/webview_flutter_android/README.md index 1a54808379fb..f5deb76c6f92 100644 --- a/packages/webview_flutter/webview_flutter_android/README.md +++ b/packages/webview_flutter/webview_flutter_android/README.md @@ -32,6 +32,20 @@ This can be configured for versions >=23 with `AndroidWebViewWidgetCreationParams.displayWithHybridComposition`. See https://pub.dev/packages/webview_flutter#platform-specific-features for more details on setting platform-specific features in the main plugin. +### External Native API + +The plugin also provides a native API for interacting for Android applications. This API follows the +convention of breaking changes of the Dart API, which means that any changes to the class that are +not backwards compatible will only be made with a major version change of the plugin. + +The API can be accessed by importing the native class `WebViewFlutterAndroidExternalApi`.: + +Java: + +```java +import io.flutter.plugins.webviewflutter.WebViewFlutterAndroidExternalApi; +``` + ## Contributing This package uses [pigeon][3] to generate the communication layer between Flutter and the host diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApi.java index 1109fb9a806f..b400fc5098a6 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApi.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApi.java @@ -12,7 +12,7 @@ * App and package facing native API provided by the `webview_flutter_android` plugin. * *

This class follows the convention of breaking changes of the Dart API, which means that any - * changes to the class that are not backwards compatible will only be done with a major version + * changes to the class that are not backwards compatible will only be made with a major version * change of the plugin. */ @SuppressWarnings("unused") diff --git a/packages/webview_flutter/webview_flutter_wkwebview/README.md b/packages/webview_flutter/webview_flutter_wkwebview/README.md index 79359636e742..b8e964355948 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/README.md +++ b/packages/webview_flutter/webview_flutter_wkwebview/README.md @@ -7,6 +7,22 @@ The Apple WKWebView implementation of [`webview_flutter`][1]. This package is [endorsed][2], which means you can simply use `webview_flutter` normally. This package will be automatically included in your app when you do. +### External Native API + +The plugin also provides a native API for interacting for Android applications. This API follows the +convention of breaking changes of the Dart API, which means that any changes to the class that are +not backwards compatible will only be made with a major version change of the plugin. + +The API can be accessed by importing the native plugin `webview_flutter_wkwebview`: + +Objective-C: + +```objectivec +@import webview_flutter_wkwebview; +``` + +Then you will have access to the native class `FWFWebViewFlutterWKWebViewExternalAPI`. + ## Contributing This package uses [pigeon][3] to generate the communication layer between Flutter and the host diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h index 5f96fc91e3af..6372f986f82a 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h @@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN App and package facing native API provided by the `webview_flutter_wkwebview` plugin. This class follows the convention of breaking changes of the Dart API, which means that any -changes to the class that are not backwards compatible will only be done with a major version +changes to the class that are not backwards compatible will only be made with a major version change of the plugin. */ @interface FWFWebViewFlutterWKWebViewExternalAPI : NSObject From 4b580c3ea86208bb926a062e004146c6be6f24f7 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 8 Feb 2023 16:13:40 -0500 Subject: [PATCH 05/12] iOS --- packages/webview_flutter/webview_flutter_wkwebview/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/README.md b/packages/webview_flutter/webview_flutter_wkwebview/README.md index b8e964355948..b644f2c7da7d 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/README.md +++ b/packages/webview_flutter/webview_flutter_wkwebview/README.md @@ -9,7 +9,7 @@ normally. This package will be automatically included in your app when you do. ### External Native API -The plugin also provides a native API for interacting for Android applications. This API follows the +The plugin also provides a native API for interacting for iOS applications. This API follows the convention of breaking changes of the Dart API, which means that any changes to the class that are not backwards compatible will only be made with a major version change of the plugin. From c75a52cfa516a5a4f61acf47647b345d564729ee Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 8 Feb 2023 16:14:35 -0500 Subject: [PATCH 06/12] improve --- packages/webview_flutter/webview_flutter_android/README.md | 2 +- packages/webview_flutter/webview_flutter_wkwebview/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_android/README.md b/packages/webview_flutter/webview_flutter_android/README.md index f5deb76c6f92..006add631543 100644 --- a/packages/webview_flutter/webview_flutter_android/README.md +++ b/packages/webview_flutter/webview_flutter_android/README.md @@ -34,7 +34,7 @@ for more details on setting platform-specific features in the main plugin. ### External Native API -The plugin also provides a native API for interacting for Android applications. This API follows the +The plugin also provides a native API for interacting with Android applications. This API follows the convention of breaking changes of the Dart API, which means that any changes to the class that are not backwards compatible will only be made with a major version change of the plugin. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/README.md b/packages/webview_flutter/webview_flutter_wkwebview/README.md index b644f2c7da7d..5bc03791899a 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/README.md +++ b/packages/webview_flutter/webview_flutter_wkwebview/README.md @@ -9,7 +9,7 @@ normally. This package will be automatically included in your app when you do. ### External Native API -The plugin also provides a native API for interacting for iOS applications. This API follows the +The plugin also provides a native API for interacting with iOS applications. This API follows the convention of breaking changes of the Dart API, which means that any changes to the class that are not backwards compatible will only be made with a major version change of the plugin. From 676fcdc775c90eff37d0c2b81863364be196bfab Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 8 Feb 2023 16:16:35 -0500 Subject: [PATCH 07/12] hmmmm --- packages/webview_flutter/webview_flutter_android/README.md | 7 ++++--- .../webview_flutter/webview_flutter_wkwebview/README.md | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_android/README.md b/packages/webview_flutter/webview_flutter_android/README.md index 006add631543..7ab2b494c676 100644 --- a/packages/webview_flutter/webview_flutter_android/README.md +++ b/packages/webview_flutter/webview_flutter_android/README.md @@ -34,9 +34,10 @@ for more details on setting platform-specific features in the main plugin. ### External Native API -The plugin also provides a native API for interacting with Android applications. This API follows the -convention of breaking changes of the Dart API, which means that any changes to the class that are -not backwards compatible will only be made with a major version change of the plugin. +The plugin also provides a native API accessible by the native code of Android applications or +packages. This API follows the convention of breaking changes of the Dart API, which means that any +changes to the class that are not backwards compatible will only be made with a major version change +of the plugin. The API can be accessed by importing the native class `WebViewFlutterAndroidExternalApi`.: diff --git a/packages/webview_flutter/webview_flutter_wkwebview/README.md b/packages/webview_flutter/webview_flutter_wkwebview/README.md index 5bc03791899a..2a20e40712fa 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/README.md +++ b/packages/webview_flutter/webview_flutter_wkwebview/README.md @@ -9,9 +9,10 @@ normally. This package will be automatically included in your app when you do. ### External Native API -The plugin also provides a native API for interacting with iOS applications. This API follows the -convention of breaking changes of the Dart API, which means that any changes to the class that are -not backwards compatible will only be made with a major version change of the plugin. +The plugin also provides a native API accessible by the native code of iOS applications or packages. +This API follows the convention of breaking changes of the Dart API, which means that any changes to +the class that are not backwards compatible will only be made with a major version change of the +plugin. The API can be accessed by importing the native plugin `webview_flutter_wkwebview`: From f463dacd375c6698bc1e46d17bb1788bbc8cc48d Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 10 Feb 2023 14:36:00 -0500 Subject: [PATCH 08/12] add note about not using other apis --- packages/webview_flutter/webview_flutter_android/README.md | 5 +++-- .../webviewflutter/WebViewFlutterAndroidExternalApi.java | 3 +++ packages/webview_flutter/webview_flutter_wkwebview/README.md | 3 ++- .../ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_android/README.md b/packages/webview_flutter/webview_flutter_android/README.md index 7ab2b494c676..d2f4d94bfed4 100644 --- a/packages/webview_flutter/webview_flutter_android/README.md +++ b/packages/webview_flutter/webview_flutter_android/README.md @@ -37,9 +37,10 @@ for more details on setting platform-specific features in the main plugin. The plugin also provides a native API accessible by the native code of Android applications or packages. This API follows the convention of breaking changes of the Dart API, which means that any changes to the class that are not backwards compatible will only be made with a major version change -of the plugin. +of the plugin. Native code other than this external API does not follow breaking change conventions, +so app or plugin clients should not use any other native APIs. -The API can be accessed by importing the native class `WebViewFlutterAndroidExternalApi`.: +The API can be accessed by importing the native class `WebViewFlutterAndroidExternalApi`: Java: diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApi.java b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApi.java index b400fc5098a6..3819d7b26f62 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApi.java +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/WebViewFlutterAndroidExternalApi.java @@ -14,6 +14,9 @@ *

This class follows the convention of breaking changes of the Dart API, which means that any * changes to the class that are not backwards compatible will only be made with a major version * change of the plugin. + * + *

Native code other than this external API does not follow breaking change conventions, so app + * or plugin clients should not use any other native APIs. */ @SuppressWarnings("unused") public interface WebViewFlutterAndroidExternalApi { diff --git a/packages/webview_flutter/webview_flutter_wkwebview/README.md b/packages/webview_flutter/webview_flutter_wkwebview/README.md index 2a20e40712fa..a393a71d2248 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/README.md +++ b/packages/webview_flutter/webview_flutter_wkwebview/README.md @@ -12,7 +12,8 @@ normally. This package will be automatically included in your app when you do. The plugin also provides a native API accessible by the native code of iOS applications or packages. This API follows the convention of breaking changes of the Dart API, which means that any changes to the class that are not backwards compatible will only be made with a major version change of the -plugin. +plugin. Native code other than this external API does not follow breaking change conventions, so +app or plugin clients should not use any other native APIs. The API can be accessed by importing the native plugin `webview_flutter_wkwebview`: diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h index 6372f986f82a..f0a6477a979f 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h @@ -13,7 +13,8 @@ App and package facing native API provided by the `webview_flutter_wkwebview` pl This class follows the convention of breaking changes of the Dart API, which means that any changes to the class that are not backwards compatible will only be made with a major version -change of the plugin. +change of the plugin. Native code other than this external API does not follow breaking change +conventions, so app or plugin clients should not use any other native APIs. */ @interface FWFWebViewFlutterWKWebViewExternalAPI : NSObject /** From b9aa957764c07d3d3ba3335d36105042abacdda6 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Fri, 10 Feb 2023 14:36:08 -0500 Subject: [PATCH 09/12] project changes --- .../example/ios/Runner.xcodeproj/project.pbxproj | 5 ++++- .../webview_flutter_wkwebview/example/ios/Runner/Info.plist | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) 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 1efee8f844ef..a1040b16e95a 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 = 50; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -379,10 +379,12 @@ /* Begin PBXShellScriptBuildPhase section */ 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", ); name = "Thin Binary"; outputPaths = ( @@ -415,6 +417,7 @@ }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner/Info.plist b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner/Info.plist index bea41604e8aa..6ee44fd0e2fd 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner/Info.plist +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner/Info.plist @@ -43,5 +43,7 @@ CADisableMinimumFrameDurationOnPhone + UIApplicationSupportsIndirectInputEvents + From ba9fb75c8380414c8e6fd241aadd606d443a3874 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 13 Feb 2023 16:01:13 -0500 Subject: [PATCH 10/12] add external api tests to project --- .../ios/Runner.xcodeproj/project.pbxproj | 38 ++++++++++++++++--- .../example/ios/Runner/Info.plist | 2 - 2 files changed, 32 insertions(+), 8 deletions(-) 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 a1040b16e95a..bcef4a879123 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 @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; + 8F4FF949299ADC2D000A6586 /* FWFWebViewFlutterWKWebViewExternalAPITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F4FF948299ADC2D000A6586 /* FWFWebViewFlutterWKWebViewExternalAPITests.m */; }; 8FA6A87928062CD000A4B183 /* FWFInstanceManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FA6A87828062CD000A4B183 /* FWFInstanceManagerTests.m */; }; 8FB79B5328134C3100C101D3 /* FWFWebViewHostApiTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FB79B5228134C3100C101D3 /* FWFWebViewHostApiTests.m */; }; 8FB79B55281B24F600C101D3 /* FWFDataConvertersTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FB79B54281B24F600C101D3 /* FWFDataConvertersTests.m */; }; @@ -76,6 +77,7 @@ 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 8F4FF948299ADC2D000A6586 /* FWFWebViewFlutterWKWebViewExternalAPITests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FWFWebViewFlutterWKWebViewExternalAPITests.m; sourceTree = ""; }; 8FA6A87828062CD000A4B183 /* FWFInstanceManagerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FWFInstanceManagerTests.m; sourceTree = ""; }; 8FB79B5228134C3100C101D3 /* FWFWebViewHostApiTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FWFWebViewHostApiTests.m; sourceTree = ""; }; 8FB79B54281B24F600C101D3 /* FWFDataConvertersTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FWFDataConvertersTests.m; sourceTree = ""; }; @@ -144,6 +146,7 @@ 68BDCAEA23C3F7CB00D9C032 /* RunnerTests */ = { isa = PBXGroup; children = ( + 8F4FF948299ADC2D000A6586 /* FWFWebViewFlutterWKWebViewExternalAPITests.m */, 68BDCAED23C3F7CB00D9C032 /* Info.plist */, 8FA6A87828062CD000A4B183 /* FWFInstanceManagerTests.m */, 8FB79B5228134C3100C101D3 /* FWFWebViewHostApiTests.m */, @@ -466,6 +469,7 @@ 8FB79B5328134C3100C101D3 /* FWFWebViewHostApiTests.m in Sources */, 8FB79B73282096B500C101D3 /* FWFScriptMessageHandlerHostApiTests.m in Sources */, 8FB79B7928209D1300C101D3 /* FWFUserContentControllerHostApiTests.m in Sources */, + 8F4FF949299ADC2D000A6586 /* FWFWebViewFlutterWKWebViewExternalAPITests.m in Sources */, 8FB79B6B28204EE500C101D3 /* FWFWebsiteDataStoreHostApiTests.m in Sources */, 8FB79B8F2820BAB300C101D3 /* FWFScrollViewHostApiTests.m in Sources */, 8FB79B912820BAC700C101D3 /* FWFUIViewHostApiTests.m in Sources */, @@ -536,7 +540,11 @@ BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; INFOPLIST_FILE = RunnerTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/Runner"; @@ -550,7 +558,11 @@ BUNDLE_LOADER = "$(TEST_HOST)"; CODE_SIGN_STYLE = Automatic; INFOPLIST_FILE = RunnerTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerTests; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/Runner"; @@ -675,7 +687,10 @@ "$(PROJECT_DIR)/Flutter", ); INFOPLIST_FILE = Runner/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Flutter", @@ -698,7 +713,10 @@ "$(PROJECT_DIR)/Flutter", ); INFOPLIST_FILE = Runner/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); LIBRARY_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Flutter", @@ -714,7 +732,11 @@ buildSettings = { CODE_SIGN_STYLE = Automatic; INFOPLIST_FILE = RunnerUITests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerUITests; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -727,7 +749,11 @@ buildSettings = { CODE_SIGN_STYLE = Automatic; INFOPLIST_FILE = RunnerUITests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerUITests; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner/Info.plist b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner/Info.plist index 6ee44fd0e2fd..bea41604e8aa 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner/Info.plist +++ b/packages/webview_flutter/webview_flutter_wkwebview/example/ios/Runner/Info.plist @@ -43,7 +43,5 @@ CADisableMinimumFrameDurationOnPhone - UIApplicationSupportsIndirectInputEvents - From f74facbb5e242fd3d3d03590e027e450b97eb045 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 13 Feb 2023 16:05:35 -0500 Subject: [PATCH 11/12] ordering --- .../example/ios/Runner.xcodeproj/project.pbxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 bcef4a879123..9e1038d08279 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 @@ -146,8 +146,8 @@ 68BDCAEA23C3F7CB00D9C032 /* RunnerTests */ = { isa = PBXGroup; children = ( - 8F4FF948299ADC2D000A6586 /* FWFWebViewFlutterWKWebViewExternalAPITests.m */, 68BDCAED23C3F7CB00D9C032 /* Info.plist */, + 8F4FF948299ADC2D000A6586 /* FWFWebViewFlutterWKWebViewExternalAPITests.m */, 8FA6A87828062CD000A4B183 /* FWFInstanceManagerTests.m */, 8FB79B5228134C3100C101D3 /* FWFWebViewHostApiTests.m */, 8FB79B54281B24F600C101D3 /* FWFDataConvertersTests.m */, From 4224d442a19d6a571854d03767d5bc9857341191 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Tue, 14 Feb 2023 11:22:28 -0500 Subject: [PATCH 12/12] fix docs and use id --- .../FWFWebViewFlutterWKWebViewExternalAPI.h | 38 +++++++++---------- .../FWFWebViewFlutterWKWebViewExternalAPI.m | 4 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h index f0a6477a979f..297f8c37ec3e 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.h @@ -9,27 +9,27 @@ NS_ASSUME_NONNULL_BEGIN /** -App and package facing native API provided by the `webview_flutter_wkwebview` plugin. - -This class follows the convention of breaking changes of the Dart API, which means that any -changes to the class that are not backwards compatible will only be made with a major version -change of the plugin. Native code other than this external API does not follow breaking change -conventions, so app or plugin clients should not use any other native APIs. -*/ + * App and package facing native API provided by the `webview_flutter_wkwebview` plugin. + * + * This class follows the convention of breaking changes of the Dart API, which means that any + * changes to the class that are not backwards compatible will only be made with a major version + * change of the plugin. Native code other than this external API does not follow breaking change + * conventions, so app or plugin clients should not use any other native APIs. + */ @interface FWFWebViewFlutterWKWebViewExternalAPI : NSObject /** -Retrieves the `WKWebView` that is associated with `identifier`. - -See the Dart method `WebKitWebViewController.webViewIdentifier` to get the identifier of an -underlying `WKWebView`. - -@param identifier The associated identifier of the `WebView`. -@param registry The plugin registry the `FLTWebViewFlutterPlugin` should belong to. If - the registry doesn't contain an attached instance of `FLTWebViewFlutterPlugin`, - this method returns nil. -@return The `WKWebView` associated with `identifier` or nil if a `WKWebView` instance associated -with `identifier` could not be found. -*/ + * Retrieves the `WKWebView` that is associated with `identifier`. + * + * See the Dart method `WebKitWebViewController.webViewIdentifier` to get the identifier of an + * underlying `WKWebView`. + * + * @param identifier The associated identifier of the `WebView`. + * @param registry The plugin registry the `FLTWebViewFlutterPlugin` should belong to. If + * the registry doesn't contain an attached instance of `FLTWebViewFlutterPlugin`, + * this method returns nil. + * @return The `WKWebView` associated with `identifier` or nil if a `WKWebView` instance associated + * with `identifier` could not be found. + */ + (nullable WKWebView *)webViewForIdentifier:(long)identifier withPluginRegistry:(id)registry; @end diff --git a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.m b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.m index b1776d818bce..4e5d6efeb129 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.m +++ b/packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFWebViewFlutterWKWebViewExternalAPI.m @@ -11,9 +11,9 @@ + (nullable WKWebView *)webViewForIdentifier:(long)identifier FWFInstanceManager *instanceManager = (FWFInstanceManager *)[registry valuePublishedByPlugin:@"FLTWebViewFlutterPlugin"]; - NSObject *instance = [instanceManager instanceForIdentifier:identifier]; + id instance = [instanceManager instanceForIdentifier:identifier]; if ([instance isKindOfClass:[WKWebView class]]) { - return (WKWebView *)instance; + return instance; } return nil;