Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
[webview_flutter_wkwebview] Change callbacks setters to anonymous fun…
Browse files Browse the repository at this point in the history
…ctions (#5921)
  • Loading branch information
bparrishMines authored Jun 7, 2022
1 parent 044f5ce commit 39d99d9
Show file tree
Hide file tree
Showing 11 changed files with 529 additions and 529 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class NSObject with Copyable {
/// This should only be used by subclasses created by this library or to
/// create copies.
NSObject({
this.observeValue,
BinaryMessenger? binaryMessenger,
InstanceManager? instanceManager,
}) : _api = NSObjectHostApiImpl(
Expand All @@ -262,6 +263,13 @@ class NSObject with Copyable {

final NSObjectHostApiImpl _api;

/// Informs the observing object when the value at the specified key path has changed.
final void Function(
String keyPath,
NSObject object,
Map<NSKeyValueChangeKey, Object?> change,
)? observeValue;

/// Registers the observer object to receive KVO notifications.
Future<void> addObserver(
NSObject observer, {
Expand All @@ -287,21 +295,10 @@ class NSObject with Copyable {
instance._api.instanceManager.removeWeakReference(instance);
}

/// Informs the observing object when the value at the specified key path has changed.
Future<void> setObserveValue(
void Function(
String keyPath,
NSObject object,
Map<NSKeyValueChangeKey, Object?> change,
)?
observeValue,
) {
throw UnimplementedError();
}

@override
Copyable copy() {
return NSObject(
observeValue: observeValue,
binaryMessenger: _api.binaryMessenger,
instanceManager: _api.instanceManager,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ class UIScrollView extends UIView {
/// Wraps [UIView](https://developer.apple.com/documentation/uikit/uiview?language=objc).
class UIView extends NSObject {
/// Constructs an [NSObject].
UIView({BinaryMessenger? binaryMessenger, InstanceManager? instanceManager})
: _viewApi = UIViewHostApiImpl(
UIView({
super.observeValue,
BinaryMessenger? binaryMessenger,
InstanceManager? instanceManager,
}) : _viewApi = UIViewHostApiImpl(
binaryMessenger: binaryMessenger,
instanceManager: instanceManager,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ class WKHttpCookieStore extends NSObject {
class WKScriptMessageHandler extends NSObject {
/// Constructs a [WKScriptMessageHandler].
WKScriptMessageHandler({
required this.didReceiveScriptMessage,
super.observeValue,
BinaryMessenger? binaryMessenger,
InstanceManager? instanceManager,
}) : _scriptMessageHandlerApi = WKScriptMessageHandlerHostApiImpl(
Expand All @@ -366,15 +368,10 @@ class WKScriptMessageHandler extends NSObject {
/// Use this method to respond to a message sent from the webpage’s
/// JavaScript code. Use the [message] parameter to get the message contents and
/// to determine the originating web view.
Future<void> setDidReceiveScriptMessage(
void Function(
WKUserContentController userContentController,
WKScriptMessage message,
)?
didReceiveScriptMessage,
) {
throw UnimplementedError();
}
final void Function(
WKUserContentController userContentController,
WKScriptMessage message,
) didReceiveScriptMessage;
}

/// Manages interactions between JavaScript code and your web view.
Expand Down Expand Up @@ -572,6 +569,8 @@ class WKWebViewConfiguration extends NSObject {
class WKUIDelegate extends NSObject {
/// Constructs a [WKUIDelegate].
WKUIDelegate({
this.onCreateWebView,
super.observeValue,
BinaryMessenger? binaryMessenger,
InstanceManager? instanceManager,
}) : _uiDelegateApi = WKUIDelegateHostApiImpl(
Expand All @@ -584,15 +583,10 @@ class WKUIDelegate extends NSObject {
final WKUIDelegateHostApiImpl _uiDelegateApi;

/// Indicates a new [WKWebView] was requested to be created with [configuration].
Future<void> setOnCreateWebView(
void Function(
WKWebViewConfiguration configuration,
WKNavigationAction navigationAction,
)?
onCreateWebView,
) {
throw UnimplementedError();
}
final void Function(
WKWebViewConfiguration configuration,
WKNavigationAction navigationAction,
)? onCreateWebView;
}

/// Methods for handling navigation changes and tracking navigation requests.
Expand All @@ -606,6 +600,12 @@ class WKNavigationDelegate extends NSObject {
/// Constructs a [WKNavigationDelegate].
WKNavigationDelegate({
this.didFinishNavigation,
this.didStartProvisionalNavigation,
this.decidePolicyForNavigationAction,
this.didFailNavigation,
this.didFailProvisionalNavigation,
this.webViewWebContentProcessDidTerminate,
super.observeValue,
super.binaryMessenger,
super.instanceManager,
}) : _navigationDelegateApi = WKNavigationDelegateHostApiImpl(
Expand All @@ -623,6 +623,12 @@ class WKNavigationDelegate extends NSObject {
/// library or to create a copy for an InstanceManager.
WKNavigationDelegate.detached({
this.didFinishNavigation,
this.didStartProvisionalNavigation,
this.decidePolicyForNavigationAction,
this.didFailNavigation,
this.didFailProvisionalNavigation,
this.webViewWebContentProcessDidTerminate,
super.observeValue,
super.binaryMessenger,
super.instanceManager,
}) : _navigationDelegateApi = WKNavigationDelegateHostApiImpl(
Expand All @@ -636,49 +642,36 @@ class WKNavigationDelegate extends NSObject {
final void Function(WKWebView webView, String? url)? didFinishNavigation;

/// Called when navigation from the main frame has started.
Future<void> setDidStartProvisionalNavigation(
void Function(WKWebView webView, String? url)?
didStartProvisionalNavigation,
) {
throw UnimplementedError();
}
final void Function(WKWebView webView, String? url)?
didStartProvisionalNavigation;

/// Called when permission is needed to navigate to new content.
Future<void> setDecidePolicyForNavigationAction(
Future<WKNavigationActionPolicy> Function(
final Future<WKNavigationActionPolicy> Function(
WKWebView webView,
WKNavigationAction navigationAction,
)?
decidePolicyForNavigationAction) {
throw UnimplementedError();
}
)? decidePolicyForNavigationAction;

/// Called when an error occurred during navigation.
Future<void> setDidFailNavigation(
void Function(WKWebView webView, NSError error)? didFailNavigation,
) {
throw UnimplementedError();
}
final void Function(WKWebView webView, NSError error)? didFailNavigation;

/// Called when an error occurred during the early navigation process.
Future<void> setDidFailProvisionalNavigation(
void Function(WKWebView webView, NSError error)?
didFailProvisionalNavigation,
) {
throw UnimplementedError();
}
final void Function(WKWebView webView, NSError error)?
didFailProvisionalNavigation;

/// Called when the web view’s content process was terminated.
Future<void> setWebViewWebContentProcessDidTerminate(
void Function(WKWebView webView)? webViewWebContentProcessDidTerminate,
) {
throw UnimplementedError();
}
final void Function(WKWebView webView)? webViewWebContentProcessDidTerminate;

@override
Copyable copy() {
return WKNavigationDelegate.detached(
didFinishNavigation: didFinishNavigation,
didStartProvisionalNavigation: didStartProvisionalNavigation,
decidePolicyForNavigationAction: decidePolicyForNavigationAction,
didFailNavigation: didFailNavigation,
didFailProvisionalNavigation: didFailProvisionalNavigation,
webViewWebContentProcessDidTerminate:
webViewWebContentProcessDidTerminate,
observeValue: observeValue,
binaryMessenger: _navigationDelegateApi.binaryMessenger,
instanceManager: _navigationDelegateApi.instanceManager,
);
Expand Down Expand Up @@ -715,6 +708,7 @@ class WKWebView extends UIView {
/// configuration object.
WKWebView(
WKWebViewConfiguration configuration, {
super.observeValue,
super.binaryMessenger,
super.instanceManager,
}) : _binaryMessenger = binaryMessenger,
Expand Down
Loading

0 comments on commit 39d99d9

Please sign in to comment.