added minimumViewportInset and maximumViewportInset iOS webview settings

This commit is contained in:
Lorenzo Pichilli 2022-10-08 15:20:09 +02:00
parent 3f8b1591c8
commit 432e882e8f
4 changed files with 65 additions and 4 deletions

View File

@ -7,7 +7,7 @@
- Added `WebAuthenticationSession` for iOS
- Added `FindInteractionController` for Android and iOS
- Added `pauseAllMediaPlayback`, `setAllMediaPlaybackSuspended`, `closeAllMediaPresentations`, `requestMediaPlaybackState`, `isInFullscreen`, `getCameraCaptureState`, `setCameraCaptureState`, `getMicrophoneCaptureState`, `setMicrophoneCaptureState` WebView controller methods
- Added `underPageBackgroundColor`, `isTextInteractionEnabled`, `isSiteSpecificQuirksModeEnabled`, `upgradeKnownHostsToHTTPS`, `forceDarkStrategy`, `willSuppressErrorPage`, `algorithmicDarkeningAllowed`, `requestedWithHeaderMode`, `enterpriseAuthenticationAppLinkPolicyEnabled`, `isElementFullscreenEnabled`, `isFindInteractionEnabled` WebView settings
- Added `underPageBackgroundColor`, `isTextInteractionEnabled`, `isSiteSpecificQuirksModeEnabled`, `upgradeKnownHostsToHTTPS`, `forceDarkStrategy`, `willSuppressErrorPage`, `algorithmicDarkeningAllowed`, `requestedWithHeaderMode`, `enterpriseAuthenticationAppLinkPolicyEnabled`, `isElementFullscreenEnabled`, `isFindInteractionEnabled`, `minimumViewportInset`, `maximumViewportInset` WebView settings
- Added `onCameraCaptureStateChanged`, `onMicrophoneCaptureStateChanged` WebView events
- Added support for `onPermissionRequest` event on iOS 15.0+
- Added `debugLoggingSettings` static property for WebView and ChromeSafariBrowser

View File

@ -416,6 +416,12 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate,
}
}
if #available(iOS 15.5, *) {
if let minViewportInset = settings.minimumViewportInset, let maxViewportInset = settings.maximumViewportInset {
setMinimumViewportInset(minViewportInset, maximumViewportInset: maxViewportInset)
}
}
if #available(iOS 16.0, *) {
isFindInteractionEnabled = settings.isFindInteractionEnabled
}
@ -1188,11 +1194,17 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate,
}
}
if #available(iOS 15.4, *) {
if newSettingsMap["isSiteSpecificQuirksModeEnabled"] != nil &&
settings?.isSiteSpecificQuirksModeEnabled != newSettings.isSiteSpecificQuirksModeEnabled {
if newSettingsMap["isSiteSpecificQuirksModeEnabled"] != nil, settings?.isSiteSpecificQuirksModeEnabled != newSettings.isSiteSpecificQuirksModeEnabled {
configuration.preferences.isSiteSpecificQuirksModeEnabled = newSettings.isSiteSpecificQuirksModeEnabled
}
}
if #available(iOS 15.5, *) {
if ((newSettingsMap["minimumViewportInset"] != nil && settings?.minimumViewportInset != newSettings.minimumViewportInset) ||
(newSettingsMap["maximumViewportInset"] != nil && settings?.maximumViewportInset != newSettings.maximumViewportInset)),
let minViewportInset = newSettings.minimumViewportInset, let maxViewportInset = newSettings.maximumViewportInset {
setMinimumViewportInset(minViewportInset, maximumViewportInset: maxViewportInset)
}
}
scrollView.isScrollEnabled = !(newSettings.disableVerticalScroll && newSettings.disableHorizontalScroll)

View File

@ -76,12 +76,23 @@ public class InAppWebViewSettings: ISettings<InAppWebView> {
var upgradeKnownHostsToHTTPS = true
var isElementFullscreenEnabled = true
var isFindInteractionEnabled = false
var minimumViewportInset: UIEdgeInsets? = nil
var maximumViewportInset: UIEdgeInsets? = nil
override init(){
super.init()
}
override func parse(settings: [String: Any?]) -> InAppWebViewSettings {
var settings = settings // re-assing to be able to use removeValue
if let minimumViewportInsetMap = settings["minimumViewportInset"] as? [String : Double] {
minimumViewportInset = UIEdgeInsets.fromMap(map: minimumViewportInsetMap)
settings.removeValue(forKey: "minimumViewportInset")
}
if let maximumViewportInsetMap = settings["maximumViewportInset"] as? [String : Double] {
maximumViewportInset = UIEdgeInsets.fromMap(map: maximumViewportInsetMap)
settings.removeValue(forKey: "maximumViewportInset")
}
let _ = super.parse(settings: settings)
if #available(iOS 13.0, *) {} else {
applePayAPIEnabled = false
@ -150,6 +161,10 @@ public class InAppWebViewSettings: ISettings<InAppWebView> {
realSettings["isSiteSpecificQuirksModeEnabled"] = configuration.preferences.isSiteSpecificQuirksModeEnabled
realSettings["isElementFullscreenEnabled"] = configuration.preferences.isElementFullscreenEnabled
}
if #available(iOS 15.5, *) {
realSettings["minimumViewportInset"] = webView.minimumViewportInset.toMap()
realSettings["maximumViewportInset"] = webView.maximumViewportInset.toMap()
}
if #available(iOS 16.0, *) {
realSettings["isFindInteractionEnabled"] = webView.isFindInteractionEnabled
}

View File

@ -1,6 +1,7 @@
import 'dart:ui';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import '../types/requested_with_header_mode.dart';
import 'android/in_app_webview_options.dart';
@ -11,6 +12,9 @@ import '../util.dart';
import '../in_app_browser/in_app_browser_settings.dart';
import 'webview.dart';
import '../android/webview_feature.dart';
import '../in_app_webview/in_app_webview_controller.dart';
import '../context_menu.dart';
///This class represents all the WebView settings available.
class InAppWebViewSettings {
@ -555,7 +559,7 @@ class InAppWebViewSettings {
///Sets the WebView's over-scroll mode.
///Setting the over-scroll mode of a WebView will have an effect only if the WebView is capable of scrolling.
///The default value is [OverScrollMode.OVER_SCROLL_IF_CONTENT_SCROLLS].
///The default value is [OverScrollMode.IF_CONTENT_SCROLLS].
///
///**Supported Platforms/Implementations**:
///- Android native WebView
@ -1077,6 +1081,24 @@ class InAppWebViewSettings {
///- iOS
bool isFindInteractionEnabled;
///Set minimum viewport inset to the smallest inset a webpage may experience in your app's maximally collapsed UI configuration.
///Values must be either zero or positive. It must be smaller than [maximumViewportInset].
///
///**NOTE**: available on iOS 15.5+.
///
///**Supported Platforms/Implementations**:
///- iOS
EdgeInsets? minimumViewportInset;
///Set maximum viewport inset to the largest inset a webpage may experience in your app's maximally expanded UI configuration.
///Values must be either zero or positive. It must be larger than [minimumViewportInset].
///
///**NOTE**: available on iOS 15.5+.
///
///**Supported Platforms/Implementations**:
///- iOS
EdgeInsets? maximumViewportInset;
///Specifies a feature policy for the `<iframe>`.
///The policy defines what features are available to the `<iframe>` based on the origin of the request
///(e.g. access to the microphone, camera, battery, web-share API, etc.).
@ -1242,6 +1264,8 @@ class InAppWebViewSettings {
this.upgradeKnownHostsToHTTPS = true,
this.isElementFullscreenEnabled = true,
this.isFindInteractionEnabled = false,
this.minimumViewportInset,
this.maximumViewportInset,
this.iframeAllow,
this.iframeAllowFullscreen,
this.iframeSandbox,
@ -1256,6 +1280,12 @@ class InAppWebViewSettings {
!this.resourceCustomSchemes.contains("https"));
assert(
allowingReadAccessTo == null || allowingReadAccessTo!.isScheme("file"));
assert((minimumViewportInset == null && maximumViewportInset == null) ||
minimumViewportInset != null && maximumViewportInset != null &&
minimumViewportInset!.isNonNegative && maximumViewportInset!.isNonNegative &&
minimumViewportInset!.vertical <= maximumViewportInset!.vertical &&
minimumViewportInset!.horizontal <= maximumViewportInset!.horizontal,
"minimumViewportInset cannot be larger than maximumViewportInset");
}
Map<String, dynamic> toMap() {
@ -1397,6 +1427,8 @@ class InAppWebViewSettings {
"upgradeKnownHostsToHTTPS": upgradeKnownHostsToHTTPS,
"isElementFullscreenEnabled": isElementFullscreenEnabled,
"isFindInteractionEnabled": isFindInteractionEnabled,
"minimumViewportInset": minimumViewportInset?.toMap(),
"maximumViewportInset": maximumViewportInset?.toMap(),
"iframeAllow": iframeAllow,
"iframeAllowFullscreen": iframeAllowFullscreen,
"iframeSandbox": iframeSandbox?.map((e) => e.toNativeValue()).toList(),
@ -1602,6 +1634,8 @@ class InAppWebViewSettings {
settings.upgradeKnownHostsToHTTPS = map["upgradeKnownHostsToHTTPS"];
settings.isElementFullscreenEnabled = map["isElementFullscreenEnabled"];
settings.isFindInteractionEnabled = map["isFindInteractionEnabled"];
settings.minimumViewportInset = MapEdgeInsets.fromMap(map["minimumViewportInset"]?.cast<String, double>());
settings.maximumViewportInset = MapEdgeInsets.fromMap(map["maximumViewportInset"]?.cast<String, double>());
}
}
return settings;