Skip to content

[webview_flutter_wkwebview] Expose the allowsLinkPreview property in WKWebView for iOS #5029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c1de6e2
Expose the allowsLinkPreview property in WKWebView for iOS
camfrandsen Sep 27, 2023
9590857
Merge remote-tracking branch 'origin/main' into linkPreview
camfrandsen Nov 1, 2023
fe5ee5a
Resolve merge conflicts with origin/main
camfrandsen Nov 1, 2023
0d6a675
override dependencies
camfrandsen Nov 1, 2023
9889288
Merge remote-tracking branch 'origin/main' into linkPreview
camfrandsen Nov 8, 2023
31f034e
Revert changing the legacy files as they are no longer supported
camfrandsen Nov 8, 2023
ffc780f
Fix versions in Changelog and pubspec.yml. I had incorrectly fixed th…
camfrandsen Nov 9, 2023
90c93fc
Missed on legacy file that needed to be reverted
camfrandsen Nov 9, 2023
938f8e5
Fix generated files by running: flutter pub upgrade (fixes Error: Me…
camfrandsen Nov 9, 2023
0ed787d
Fix last merge conflict in FWFWebViewHostApi.m
camfrandsen Nov 9, 2023
d7ab020
update webview_flutter
bparrishMines Mar 31, 2025
3730994
update platform interface
bparrishMines Mar 31, 2025
23dde3b
remove old files
bparrishMines Mar 31, 2025
ef29572
try
bparrishMines Mar 31, 2025
045a1ee
remove change
bparrishMines Mar 31, 2025
15af7c4
add impl
bparrishMines Mar 31, 2025
45c6905
Merge branch 'main' of github.com:flutter/packages into linkPreview
bparrishMines Mar 31, 2025
1a577af
remove override and update changelog
bparrishMines Mar 31, 2025
62594dd
Revert unrelated Runner.xcodeproj change
stuartmorgan-g Apr 1, 2025
76c53c5
update location and docs
bparrishMines Apr 2, 2025
44b8475
Merge branch 'main' of github.com:flutter/packages into linkPreview
bparrishMines Apr 2, 2025
a9903d9
Merge branch 'linkPreview' of github.com:camfrandsen/packages into li…
bparrishMines Apr 2, 2025
7a46f04
update docs
bparrishMines Apr 17, 2025
34a41d9
Merge branch 'main' of github.com:flutter/packages into linkPreview
bparrishMines Apr 17, 2025
532ce62
organize methods to put platform specific near top
bparrishMines Apr 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 3.20.0

* Adds support to disable a preview of the destination for a link. See
`WebKitWebViewController.setAllowsLinkPreview`.

## 3.19.0

* Adds support to set the over-scroll mode for the WebView. See `WebKitWebViewController.setOverScrollMode`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@ class WebViewProxyAPITests: XCTestCase {
XCTAssertFalse(instance.isInspectable)
}

@MainActor func testSetAllowsLinkPreview() {
let registrar = TestProxyApiRegistrar()
let api = webViewProxyAPI(forRegistrar: registrar)

let instance = TestViewWKWebView()
let allow: Bool = true
try? api.pigeonDelegate.setAllowsLinkPreview(
pigeonApi: api, pigeonInstance: instance, allow: allow)

XCTAssertEqual(instance.allowsLinkPreview, allow)
}

@MainActor func testGetCustomUserAgent() {
let registrar = TestProxyApiRegistrar()
let api = webViewProxyAPI(forRegistrar: registrar)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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.
// Autogenerated from Pigeon (v25.2.0), do not edit directly.
// Autogenerated from Pigeon (v25.3.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon

import Foundation
Expand Down Expand Up @@ -77,6 +77,7 @@ private func nilOrValue<T>(_ value: Any?) -> T? {
if value is NSNull { return nil }
return value as! T?
}

/// Handles the callback when an object is deallocated.
protocol WebKitLibraryPigeonInternalFinalizerDelegate: AnyObject {
/// Invoked when the strong reference of an object is deallocated in an `InstanceManager`.
Expand Down Expand Up @@ -4774,6 +4775,14 @@ protocol PigeonApiDelegateUIViewWKWebView {
func getCustomUserAgent(pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView) throws
-> String?
#endif
#if !os(macOS)
/// Whether to allow previews for link destinations and detected data such as
/// addresses and phone numbers.
///
/// Defaults to true.
func setAllowsLinkPreview(
pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, allow: Bool) throws
#endif
}

protocol PigeonApiProtocolUIViewWKWebView {
Expand Down Expand Up @@ -5272,6 +5281,27 @@ final class PigeonApiUIViewWKWebView: PigeonApiProtocolUIViewWKWebView {
getCustomUserAgentChannel.setMessageHandler(nil)
}
#endif
#if !os(macOS)
let setAllowsLinkPreviewChannel = FlutterBasicMessageChannel(
name: "dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.setAllowsLinkPreview",
binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
setAllowsLinkPreviewChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let pigeonInstanceArg = args[0] as! WKWebView
let allowArg = args[1] as! Bool
do {
try api.pigeonDelegate.setAllowsLinkPreview(
pigeonApi: api, pigeonInstance: pigeonInstanceArg, allow: allowArg)
reply(wrapResult(nil))
} catch {
reply(wrapError(error))
}
}
} else {
setAllowsLinkPreviewChannel.setMessageHandler(nil)
}
#endif
}

#if !os(macOS)
Expand Down Expand Up @@ -5424,6 +5454,14 @@ protocol PigeonApiDelegateNSViewWKWebView {
func getCustomUserAgent(pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView) throws
-> String?
#endif
#if !os(iOS)
/// Whether to allow previews for link destinations and detected data such as
/// addresses and phone numbers.
///
/// Defaults to true.
func setAllowsLinkPreview(
pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, allow: Bool) throws
#endif
}

protocol PigeonApiProtocolNSViewWKWebView {
Expand Down Expand Up @@ -5900,6 +5938,27 @@ final class PigeonApiNSViewWKWebView: PigeonApiProtocolNSViewWKWebView {
getCustomUserAgentChannel.setMessageHandler(nil)
}
#endif
#if !os(iOS)
let setAllowsLinkPreviewChannel = FlutterBasicMessageChannel(
name: "dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.setAllowsLinkPreview",
binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
setAllowsLinkPreviewChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let pigeonInstanceArg = args[0] as! WKWebView
let allowArg = args[1] as! Bool
do {
try api.pigeonDelegate.setAllowsLinkPreview(
pigeonApi: api, pigeonInstance: pigeonInstanceArg, allow: allowArg)
reply(wrapResult(nil))
} catch {
reply(wrapError(error))
}
}
} else {
setAllowsLinkPreviewChannel.setMessageHandler(nil)
}
#endif
}

#if !os(iOS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,4 +380,17 @@ class WebViewProxyAPIDelegate: PigeonApiDelegateWKWebView, PigeonApiDelegateUIVi
return try getCustomUserAgent(
pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance)
}

func setAllowsLinkPreview(
pigeonApi: PigeonApiUIViewWKWebView, pigeonInstance: WKWebView, allow: Bool
) throws {
pigeonInstance.allowsLinkPreview = allow
}

func setAllowsLinkPreview(
pigeonApi: PigeonApiNSViewWKWebView, pigeonInstance: WKWebView, allow: Bool
) throws {
try setAllowsLinkPreview(
pigeonApi: getUIViewWKWebViewAPI(pigeonApi), pigeonInstance: pigeonInstance, allow: allow)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,20 @@ class PlatformWebView {

throw UnimplementedError('${webView.runtimeType} is not supported.');
}

/// Whether to allow previews for link destinations and detected data such as
/// addresses and phone numbers.
///
/// Defaults to true.
Future<void> setAllowsLinkPreview(bool allow) {
final WKWebView webView = nativeWebView;
switch (webView) {
case UIViewWKWebView():
return webView.setAllowsLinkPreview(allow);
case NSViewWKWebView():
return webView.setAllowsLinkPreview(allow);
}

throw UnimplementedError('${webView.runtimeType} is not supported.');
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// 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.
// Autogenerated from Pigeon (v25.2.0), do not edit directly.
// Autogenerated from Pigeon (v25.3.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers

Expand Down Expand Up @@ -5822,6 +5822,39 @@ class UIViewWKWebView extends UIView implements WKWebView {
}
}

/// Whether to allow previews for link destinations and detected data such as
/// addresses and phone numbers.
///
/// Defaults to true.
Future<void> setAllowsLinkPreview(bool allow) async {
final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec =
_pigeonVar_codecUIViewWKWebView;
final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger;
const String pigeonVar_channelName =
'dev.flutter.pigeon.webview_flutter_wkwebview.UIViewWKWebView.setAllowsLinkPreview';
final BasicMessageChannel<Object?> pigeonVar_channel =
BasicMessageChannel<Object?>(
pigeonVar_channelName,
pigeonChannelCodec,
binaryMessenger: pigeonVar_binaryMessenger,
);
final Future<Object?> pigeonVar_sendFuture =
pigeonVar_channel.send(<Object?>[this, allow]);
final List<Object?>? pigeonVar_replyList =
await pigeonVar_sendFuture as List<Object?>?;
if (pigeonVar_replyList == null) {
throw _createConnectionError(pigeonVar_channelName);
} else if (pigeonVar_replyList.length > 1) {
throw PlatformException(
code: pigeonVar_replyList[0]! as String,
message: pigeonVar_replyList[1] as String?,
details: pigeonVar_replyList[2],
);
} else {
return;
}
}

@override
UIViewWKWebView pigeon_copy() {
return UIViewWKWebView.pigeon_detached(
Expand Down Expand Up @@ -6577,6 +6610,39 @@ class NSViewWKWebView extends NSObject implements WKWebView {
}
}

/// Whether to allow previews for link destinations and detected data such as
/// addresses and phone numbers.
///
/// Defaults to true.
Future<void> setAllowsLinkPreview(bool allow) async {
final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec =
_pigeonVar_codecNSViewWKWebView;
final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger;
const String pigeonVar_channelName =
'dev.flutter.pigeon.webview_flutter_wkwebview.NSViewWKWebView.setAllowsLinkPreview';
final BasicMessageChannel<Object?> pigeonVar_channel =
BasicMessageChannel<Object?>(
pigeonVar_channelName,
pigeonChannelCodec,
binaryMessenger: pigeonVar_binaryMessenger,
);
final Future<Object?> pigeonVar_sendFuture =
pigeonVar_channel.send(<Object?>[this, allow]);
final List<Object?>? pigeonVar_replyList =
await pigeonVar_sendFuture as List<Object?>?;
if (pigeonVar_replyList == null) {
throw _createConnectionError(pigeonVar_channelName);
} else if (pigeonVar_replyList.length > 1) {
throw PlatformException(
code: pigeonVar_replyList[0]! as String,
message: pigeonVar_replyList[1] as String?,
details: pigeonVar_replyList[2],
);
} else {
return;
}
}

@override
NSViewWKWebView pigeon_copy() {
return NSViewWKWebView.pigeon_detached(
Expand Down
Loading