Skip to content

Commit e8bbbb5

Browse files
bparrishMinesmvanbeusekom
authored andcommitted
[webview_flutter_wkwebview] Change callbacks setters to anonymous functions (flutter#5921)
1 parent e9676f9 commit e8bbbb5

11 files changed

+529
-529
lines changed

packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ class NSObject with Copyable {
244244
/// This should only be used by subclasses created by this library or to
245245
/// create copies.
246246
NSObject({
247+
this.observeValue,
247248
BinaryMessenger? binaryMessenger,
248249
InstanceManager? instanceManager,
249250
}) : _api = NSObjectHostApiImpl(
@@ -262,6 +263,13 @@ class NSObject with Copyable {
262263

263264
final NSObjectHostApiImpl _api;
264265

266+
/// Informs the observing object when the value at the specified key path has changed.
267+
final void Function(
268+
String keyPath,
269+
NSObject object,
270+
Map<NSKeyValueChangeKey, Object?> change,
271+
)? observeValue;
272+
265273
/// Registers the observer object to receive KVO notifications.
266274
Future<void> addObserver(
267275
NSObject observer, {
@@ -287,21 +295,10 @@ class NSObject with Copyable {
287295
instance._api.instanceManager.removeWeakReference(instance);
288296
}
289297

290-
/// Informs the observing object when the value at the specified key path has changed.
291-
Future<void> setObserveValue(
292-
void Function(
293-
String keyPath,
294-
NSObject object,
295-
Map<NSKeyValueChangeKey, Object?> change,
296-
)?
297-
observeValue,
298-
) {
299-
throw UnimplementedError();
300-
}
301-
302298
@override
303299
Copyable copy() {
304300
return NSObject(
301+
observeValue: observeValue,
305302
binaryMessenger: _api.binaryMessenger,
306303
instanceManager: _api.instanceManager,
307304
);

packages/webview_flutter/webview_flutter_wkwebview/lib/src/ui_kit/ui_kit.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ class UIScrollView extends UIView {
6464
/// Wraps [UIView](https://developer.apple.com/documentation/uikit/uiview?language=objc).
6565
class UIView extends NSObject {
6666
/// Constructs an [NSObject].
67-
UIView({BinaryMessenger? binaryMessenger, InstanceManager? instanceManager})
68-
: _viewApi = UIViewHostApiImpl(
67+
UIView({
68+
super.observeValue,
69+
BinaryMessenger? binaryMessenger,
70+
InstanceManager? instanceManager,
71+
}) : _viewApi = UIViewHostApiImpl(
6972
binaryMessenger: binaryMessenger,
7073
instanceManager: instanceManager,
7174
);

packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ class WKHttpCookieStore extends NSObject {
350350
class WKScriptMessageHandler extends NSObject {
351351
/// Constructs a [WKScriptMessageHandler].
352352
WKScriptMessageHandler({
353+
required this.didReceiveScriptMessage,
354+
super.observeValue,
353355
BinaryMessenger? binaryMessenger,
354356
InstanceManager? instanceManager,
355357
}) : _scriptMessageHandlerApi = WKScriptMessageHandlerHostApiImpl(
@@ -366,15 +368,10 @@ class WKScriptMessageHandler extends NSObject {
366368
/// Use this method to respond to a message sent from the webpage’s
367369
/// JavaScript code. Use the [message] parameter to get the message contents and
368370
/// to determine the originating web view.
369-
Future<void> setDidReceiveScriptMessage(
370-
void Function(
371-
WKUserContentController userContentController,
372-
WKScriptMessage message,
373-
)?
374-
didReceiveScriptMessage,
375-
) {
376-
throw UnimplementedError();
377-
}
371+
final void Function(
372+
WKUserContentController userContentController,
373+
WKScriptMessage message,
374+
) didReceiveScriptMessage;
378375
}
379376

380377
/// Manages interactions between JavaScript code and your web view.
@@ -572,6 +569,8 @@ class WKWebViewConfiguration extends NSObject {
572569
class WKUIDelegate extends NSObject {
573570
/// Constructs a [WKUIDelegate].
574571
WKUIDelegate({
572+
this.onCreateWebView,
573+
super.observeValue,
575574
BinaryMessenger? binaryMessenger,
576575
InstanceManager? instanceManager,
577576
}) : _uiDelegateApi = WKUIDelegateHostApiImpl(
@@ -584,15 +583,10 @@ class WKUIDelegate extends NSObject {
584583
final WKUIDelegateHostApiImpl _uiDelegateApi;
585584

586585
/// Indicates a new [WKWebView] was requested to be created with [configuration].
587-
Future<void> setOnCreateWebView(
588-
void Function(
589-
WKWebViewConfiguration configuration,
590-
WKNavigationAction navigationAction,
591-
)?
592-
onCreateWebView,
593-
) {
594-
throw UnimplementedError();
595-
}
586+
final void Function(
587+
WKWebViewConfiguration configuration,
588+
WKNavigationAction navigationAction,
589+
)? onCreateWebView;
596590
}
597591

598592
/// Methods for handling navigation changes and tracking navigation requests.
@@ -606,6 +600,12 @@ class WKNavigationDelegate extends NSObject {
606600
/// Constructs a [WKNavigationDelegate].
607601
WKNavigationDelegate({
608602
this.didFinishNavigation,
603+
this.didStartProvisionalNavigation,
604+
this.decidePolicyForNavigationAction,
605+
this.didFailNavigation,
606+
this.didFailProvisionalNavigation,
607+
this.webViewWebContentProcessDidTerminate,
608+
super.observeValue,
609609
super.binaryMessenger,
610610
super.instanceManager,
611611
}) : _navigationDelegateApi = WKNavigationDelegateHostApiImpl(
@@ -623,6 +623,12 @@ class WKNavigationDelegate extends NSObject {
623623
/// library or to create a copy for an InstanceManager.
624624
WKNavigationDelegate.detached({
625625
this.didFinishNavigation,
626+
this.didStartProvisionalNavigation,
627+
this.decidePolicyForNavigationAction,
628+
this.didFailNavigation,
629+
this.didFailProvisionalNavigation,
630+
this.webViewWebContentProcessDidTerminate,
631+
super.observeValue,
626632
super.binaryMessenger,
627633
super.instanceManager,
628634
}) : _navigationDelegateApi = WKNavigationDelegateHostApiImpl(
@@ -636,49 +642,36 @@ class WKNavigationDelegate extends NSObject {
636642
final void Function(WKWebView webView, String? url)? didFinishNavigation;
637643

638644
/// Called when navigation from the main frame has started.
639-
Future<void> setDidStartProvisionalNavigation(
640-
void Function(WKWebView webView, String? url)?
641-
didStartProvisionalNavigation,
642-
) {
643-
throw UnimplementedError();
644-
}
645+
final void Function(WKWebView webView, String? url)?
646+
didStartProvisionalNavigation;
645647

646648
/// Called when permission is needed to navigate to new content.
647-
Future<void> setDecidePolicyForNavigationAction(
648-
Future<WKNavigationActionPolicy> Function(
649+
final Future<WKNavigationActionPolicy> Function(
649650
WKWebView webView,
650651
WKNavigationAction navigationAction,
651-
)?
652-
decidePolicyForNavigationAction) {
653-
throw UnimplementedError();
654-
}
652+
)? decidePolicyForNavigationAction;
655653

656654
/// Called when an error occurred during navigation.
657-
Future<void> setDidFailNavigation(
658-
void Function(WKWebView webView, NSError error)? didFailNavigation,
659-
) {
660-
throw UnimplementedError();
661-
}
655+
final void Function(WKWebView webView, NSError error)? didFailNavigation;
662656

663657
/// Called when an error occurred during the early navigation process.
664-
Future<void> setDidFailProvisionalNavigation(
665-
void Function(WKWebView webView, NSError error)?
666-
didFailProvisionalNavigation,
667-
) {
668-
throw UnimplementedError();
669-
}
658+
final void Function(WKWebView webView, NSError error)?
659+
didFailProvisionalNavigation;
670660

671661
/// Called when the web view’s content process was terminated.
672-
Future<void> setWebViewWebContentProcessDidTerminate(
673-
void Function(WKWebView webView)? webViewWebContentProcessDidTerminate,
674-
) {
675-
throw UnimplementedError();
676-
}
662+
final void Function(WKWebView webView)? webViewWebContentProcessDidTerminate;
677663

678664
@override
679665
Copyable copy() {
680666
return WKNavigationDelegate.detached(
681667
didFinishNavigation: didFinishNavigation,
668+
didStartProvisionalNavigation: didStartProvisionalNavigation,
669+
decidePolicyForNavigationAction: decidePolicyForNavigationAction,
670+
didFailNavigation: didFailNavigation,
671+
didFailProvisionalNavigation: didFailProvisionalNavigation,
672+
webViewWebContentProcessDidTerminate:
673+
webViewWebContentProcessDidTerminate,
674+
observeValue: observeValue,
682675
binaryMessenger: _navigationDelegateApi.binaryMessenger,
683676
instanceManager: _navigationDelegateApi.instanceManager,
684677
);
@@ -715,6 +708,7 @@ class WKWebView extends UIView {
715708
/// configuration object.
716709
WKWebView(
717710
WKWebViewConfiguration configuration, {
711+
super.observeValue,
718712
super.binaryMessenger,
719713
super.instanceManager,
720714
}) : _binaryMessenger = binaryMessenger,

0 commit comments

Comments
 (0)