diff --git a/dev_packages/flutter_inappwebview_internal_annotations/lib/src/exchangeable_object_property.dart b/dev_packages/flutter_inappwebview_internal_annotations/lib/src/exchangeable_object_property.dart index 14fa2eae5..9ffd83955 100644 --- a/dev_packages/flutter_inappwebview_internal_annotations/lib/src/exchangeable_object_property.dart +++ b/dev_packages/flutter_inappwebview_internal_annotations/lib/src/exchangeable_object_property.dart @@ -1,9 +1,17 @@ class ExchangeableObjectProperty { final Function? serializer; final Function? deserializer; + final bool deprecatedUseNewFieldNameInConstructor; + final bool deprecatedUseNewFieldNameInFromMapMethod; + final bool leaveDeprecatedInFromMapMethod; + final bool leaveDeprecatedInToMapMethod; const ExchangeableObjectProperty({ this.serializer, - this.deserializer + this.deserializer, + this.deprecatedUseNewFieldNameInConstructor = true, + this.deprecatedUseNewFieldNameInFromMapMethod = true, + this.leaveDeprecatedInFromMapMethod = false, + this.leaveDeprecatedInToMapMethod = false, }); } diff --git a/dev_packages/generators/lib/src/exchangeable_object_generator.dart b/dev_packages/generators/lib/src/exchangeable_object_generator.dart index 5e406787a..498c95aa9 100644 --- a/dev_packages/generators/lib/src/exchangeable_object_generator.dart +++ b/dev_packages/generators/lib/src/exchangeable_object_generator.dart @@ -225,11 +225,22 @@ class ExchangeableObjectGenerator if (!hasCustomConstructor && deprecatedFields.length > 0) { classBuffer.writeln(' {'); for (final deprecatedField in deprecatedFields) { - final deprecatedFieldName = deprecatedField.name; + final deprecatedUseNewFieldNameInConstructor = _coreCheckerObjectProperty + .firstAnnotationOf(deprecatedField) + ?.getField("deprecatedUseNewFieldNameInConstructor") + ?.toBoolValue() ?? true; + if (!deprecatedUseNewFieldNameInConstructor) { + continue; + } + final message = _coreCheckerDeprecated .firstAnnotationOfExact(deprecatedField)! .getField("message")! - .toStringValue()!; + .toStringValue()!.trim(); + if (!message.startsWith("Use ") && !message.endsWith(" instead")) { + continue; + } + final newFieldName = message .replaceFirst("Use ", "") .replaceFirst(" instead", "") @@ -238,6 +249,7 @@ class ExchangeableObjectGenerator final newFieldElement = visitor.fields[newFieldName]; final shouldUseNewFieldName = newFieldElement != null; if (shouldUseNewFieldName) { + final deprecatedFieldName = deprecatedField.name; final fieldTypeElement = newFieldElement.type.element; final deprecatedFieldTypeElement = deprecatedField.type.element; @@ -328,36 +340,57 @@ class ExchangeableObjectGenerator !(fieldElement.type.isDartCoreFunction || fieldElement.type is FunctionType)) { var value = "map['$fieldName']"; - final deprecationMessage = _coreCheckerDeprecated - .firstAnnotationOfExact(fieldElement) - ?.getField("message") - ?.toStringValue(); - if (deprecationMessage != null) { - final newFieldName = deprecationMessage - .replaceFirst("Use ", "") - .replaceFirst(" instead", "") - .trim(); - final newFieldElement = fieldElements - .firstWhereOrNull((element) => element.name == newFieldName); - final shouldUseNewFieldName = newFieldElement != null && - (newFieldElement.type == fieldElement.type || - (fieldElement.name.startsWith(RegExp(r'android|ios')) && - fieldElement.name.toLowerCase().replaceFirst( - RegExp(r'android|ioswk|ios'), "") == - newFieldName.toLowerCase()) || - (newFieldElement.type.element != null && - fieldElement.type.element != null && - ((hasFromNativeValueMethod( - newFieldElement.type.element!) && - hasFromNativeValueMethod( - fieldElement.type.element!) || - (hasFromMapMethod(newFieldElement.type.element!) && - hasFromMapMethod( - fieldElement.type.element!)))))); - if (shouldUseNewFieldName) { - value = "map['$newFieldName']"; + + if (fieldElement.hasDeprecated) { + final deprecatedUseNewFieldNameInFromMapMethod = _coreCheckerObjectProperty + .firstAnnotationOf(fieldElement) + ?.getField("deprecatedUseNewFieldNameInFromMapMethod") + ?.toBoolValue() ?? true; + + final deprecationMessage = _coreCheckerDeprecated + .firstAnnotationOfExact(fieldElement) + ?.getField("message") + ?.toStringValue()?.trim(); + if (deprecationMessage != null && + deprecationMessage.startsWith("Use ") && + deprecationMessage.endsWith(" instead") && + deprecatedUseNewFieldNameInFromMapMethod) { + final newFieldName = deprecationMessage + .replaceFirst("Use ", "") + .replaceFirst(" instead", "") + .trim(); + final newFieldElement = fieldElements + .firstWhereOrNull((element) => element.name == newFieldName); + final shouldUseNewFieldName = newFieldElement != null && + (newFieldElement.type == fieldElement.type || + (fieldElement.name.startsWith(RegExp(r'android|ios')) && + fieldElement.name.toLowerCase().replaceFirst( + RegExp(r'android|ioswk|ios'), "") == + newFieldName.toLowerCase()) || + (newFieldElement.type.element != null && + fieldElement.type.element != null && + ((hasFromNativeValueMethod( + newFieldElement.type.element!) && + hasFromNativeValueMethod( + fieldElement.type.element!) || + (hasFromMapMethod( + newFieldElement.type.element!) && + hasFromMapMethod( + fieldElement.type.element!)))))); + if (shouldUseNewFieldName) { + value = "map['$newFieldName']"; + } + } else { + final leaveDeprecatedInFromMapMethod = _coreCheckerObjectProperty + .firstAnnotationOf(fieldElement) + ?.getField("leaveDeprecatedInFromMapMethod") + ?.toBoolValue() ?? false; + if (!leaveDeprecatedInFromMapMethod) { + continue; + } } } + final mapValue = value; final customDeserializer = _coreCheckerObjectProperty @@ -442,7 +475,6 @@ class ExchangeableObjectGenerator if (superClass != null) { for (final fieldElement in superClass.element.fields) { if (!fieldElement.isPrivate && - !fieldElement.hasDeprecated && !fieldElement.isStatic && !(fieldElement.type.isDartCoreFunction || fieldElement.type is FunctionType)) { @@ -453,7 +485,6 @@ class ExchangeableObjectGenerator for (final entry in fieldEntriesSorted) { final fieldElement = entry.value; if (!fieldElement.isPrivate && - !fieldElement.hasDeprecated && !fieldElement.isStatic && !(fieldElement.type.isDartCoreFunction || fieldElement.type is FunctionType)) { @@ -462,10 +493,19 @@ class ExchangeableObjectGenerator } for (final fieldElement in fieldElements) { if (!fieldElement.isPrivate && - !fieldElement.hasDeprecated && !fieldElement.isStatic && !(fieldElement.type.isDartCoreFunction || fieldElement.type is FunctionType)) { + if (fieldElement.hasDeprecated) { + final leaveDeprecatedInToMapMethod = _coreCheckerObjectProperty + .firstAnnotationOf(fieldElement) + ?.getField("leaveDeprecatedInToMapMethod") + ?.toBoolValue() ?? false; + if (!leaveDeprecatedInToMapMethod) { + continue; + } + } + final fieldName = fieldElement.name; var mapValue = fieldName; final customSerializer = _coreCheckerObjectProperty diff --git a/flutter_inappwebview/CHANGELOG.md b/flutter_inappwebview/CHANGELOG.md index d1bd19369..879a6af74 100755 --- a/flutter_inappwebview/CHANGELOG.md +++ b/flutter_inappwebview/CHANGELOG.md @@ -14,17 +14,25 @@ - Updated `flutter_inappwebview_internal_annotations` dependency from `^1.1.1` to `^1.2.0` - Updated `fromMap` static method and `toMap` method implementations - Added `byName`, `name`, `asNameMap` custom enum classes methods -- Added `statusBarEnabled`, `browserAcceleratorKeysEnabled`, `generalAutofillEnabled`, `passwordAutosaveEnabled`, `isPinchZoomEnabled`, `hiddenPdfToolbarItems`, `reputationCheckingRequired`, `nonClientRegionSupportEnabled` property to `InAppWebViewSettings` +- Added `statusBarEnabled`, `browserAcceleratorKeysEnabled`, `generalAutofillEnabled`, `passwordAutosaveEnabled`, `isPinchZoomEnabled`, `hiddenPdfToolbarItems`, `reputationCheckingRequired`, `nonClientRegionSupportEnabled`, `alpha`, `isUserInteractionEnabled` properties to `InAppWebViewSettings` - Added `isInterfaceSupported` method to `PlatformWebViewEnvironment` class - Added `isInterfaceSupported` method to `PlatformInAppWebViewController` class +- Fixed missing PrintJobOrientation android values #### Android Platform - Implemented `hideInputMethod`, `showInputMethod` InAppWebViewController methods +- Implemented `isUserInteractionEnabled`, `alpha` properties of `InAppWebViewSettings` - Merged "Show / Hide / Disable / Enable soft Keyboard Input (Android & iOS)" [#2408](https://github.com/pichillilorenzo/flutter_inappwebview/pull/2408) (thanks to [Mecharyry](https://github.com/Mecharyry)) +- Fixed "[Android] PrintJobOrientation _TypeError (type 'Null' is not a subtype of type 'int')" [#2413](https://github.com/pichillilorenzo/flutter_inappwebview/issues/2413) #### iOS Platform - Implemented `setInputMethodEnabled`, `hideInputMethod` InAppWebViewController methods +- Implemented `isUserInteractionEnabled`, `alpha` properties of `InAppWebViewSettings` - Merged "Show / Hide / Disable / Enable soft Keyboard Input (Android & iOS)" [#2408](https://github.com/pichillilorenzo/flutter_inappwebview/pull/2408) (thanks to [Mecharyry](https://github.com/Mecharyry)) +- Fixed "In iOS version 17.2, when moving the input focus in a WebView, an unknown area appears at the top of the screen." [#1947](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1947) + +#### macOS Platform +- Implemented `alpha` property of `InAppWebViewSettings` #### Windows Platform - Updated Microsoft.Web.WebView2 SDK version from `1.0.2792.45` to `1.0.2849.39` diff --git a/flutter_inappwebview/example/lib/main.dart b/flutter_inappwebview/example/lib/main.dart index 72c82f54b..b44b82b8b 100755 --- a/flutter_inappwebview/example/lib/main.dart +++ b/flutter_inappwebview/example/lib/main.dart @@ -29,9 +29,11 @@ Future main() async { webViewEnvironment = await WebViewEnvironment.create( settings: WebViewEnvironmentSettings( - additionalBrowserArguments: kDebugMode ? '--enable-features=msEdgeDevToolsWdpRemoteDebugging' : null, - userDataFolder: 'custom_path', - )); + additionalBrowserArguments: kDebugMode + ? '--enable-features=msEdgeDevToolsWdpRemoteDebugging' + : null, + userDataFolder: 'custom_path', + )); } if (!kIsWeb && defaultTargetPlatform == TargetPlatform.android) { diff --git a/flutter_inappwebview_android/CHANGELOG.md b/flutter_inappwebview_android/CHANGELOG.md index e60b630a3..c9b8f2296 100644 --- a/flutter_inappwebview_android/CHANGELOG.md +++ b/flutter_inappwebview_android/CHANGELOG.md @@ -2,7 +2,9 @@ - Updated flutter_inappwebview_platform_interface version to ^1.4.0-beta.2 - Implemented `hideInputMethod`, `showInputMethod` InAppWebViewController methods +- Implemented `isUserInteractionEnabled`, `alpha` properties of `InAppWebViewSettings` - Merged "Show / Hide / Disable / Enable soft Keyboard Input (Android & iOS)" [#2408](https://github.com/pichillilorenzo/flutter_inappwebview/pull/2408) (thanks to [Mecharyry](https://github.com/Mecharyry)) +- Fixed "[Android] PrintJobOrientation _TypeError (type 'Null' is not a subtype of type 'int')" [#2413](https://github.com/pichillilorenzo/flutter_inappwebview/issues/2413) ## 1.2.0-beta.1 diff --git a/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/webview/in_app_webview/InAppWebView.java b/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/webview/in_app_webview/InAppWebView.java index c682bb46a..b88539bfe 100755 --- a/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/webview/in_app_webview/InAppWebView.java +++ b/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/webview/in_app_webview/InAppWebView.java @@ -241,8 +241,22 @@ public WebViewClient createWebViewClient(InAppBrowserDelegate inAppBrowserDelega } } + @Override + public void setAlpha(float alpha) { + ViewParent parent = getParent(); + if (parent instanceof PullToRefreshLayout) { + ((PullToRefreshLayout) parent).setAlpha(alpha); + } else { + super.setAlpha(alpha); + } + } + @SuppressLint("RestrictedApi") public void prepare() { + if (customSettings.alpha != null) { + setAlpha(customSettings.alpha.floatValue()); + } + javaScriptBridgeEnabled = customSettings.javaScriptBridgeEnabled; if (customSettings.javaScriptBridgeOriginAllowList != null && customSettings.javaScriptBridgeOriginAllowList.isEmpty()) { // an empty list means that the JavaScript Bridge is not allowed for any origin. @@ -1517,6 +1531,10 @@ private void sendOnCreateContextMenuEvent() { @Override public boolean onTouchEvent(MotionEvent ev) { + if (!customSettings.isUserInteractionEnabled) { + return true; + } + lastTouch = new Point((int) ev.getX(), (int) ev.getY()); ViewParent parent = getParent(); diff --git a/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/webview/in_app_webview/InAppWebViewSettings.java b/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/webview/in_app_webview/InAppWebViewSettings.java index cb8b23338..15885d134 100755 --- a/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/webview/in_app_webview/InAppWebViewSettings.java +++ b/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/webview/in_app_webview/InAppWebViewSettings.java @@ -153,6 +153,9 @@ public class InAppWebViewSettings implements ISettings { @Nullable public Set pluginScriptsOriginAllowList; public Boolean pluginScriptsForMainFrameOnly = false; + public Boolean isUserInteractionEnabled = true; + @Nullable + public Double alpha = null; @NonNull @Override @@ -459,6 +462,12 @@ public InAppWebViewSettings parse(@NonNull Map settings) { case "pluginScriptsForMainFrameOnly": pluginScriptsForMainFrameOnly = (Boolean) value; break; + case "isUserInteractionEnabled": + isUserInteractionEnabled = (Boolean) value; + break; + case "alpha": + alpha = (Double) value; + break; } } @@ -573,6 +582,8 @@ public Map toMap() { settings.put("pluginScriptsOriginAllowList", pluginScriptsOriginAllowList != null ? new ArrayList<>(pluginScriptsOriginAllowList) : null); settings.put("pluginScriptsForMainFrameOnly", pluginScriptsForMainFrameOnly); + settings.put("isUserInteractionEnabled", isUserInteractionEnabled); + settings.put("alpha", alpha); return settings; } @@ -583,6 +594,8 @@ public Map getRealSettings(@NonNull InAppWebViewInterface inAppW Map realSettings = toMap(); if (inAppWebView instanceof InAppWebView) { InAppWebView webView = (InAppWebView) inAppWebView; + realSettings.put("alpha", webView.getAlpha()); + WebSettings settings = webView.getSettings(); realSettings.put("userAgent", settings.getUserAgentString()); realSettings.put("javaScriptEnabled", settings.getJavaScriptEnabled()); diff --git a/flutter_inappwebview_ios/CHANGELOG.md b/flutter_inappwebview_ios/CHANGELOG.md index 301a6682a..caa1349bc 100644 --- a/flutter_inappwebview_ios/CHANGELOG.md +++ b/flutter_inappwebview_ios/CHANGELOG.md @@ -2,7 +2,9 @@ - Updated flutter_inappwebview_platform_interface version to ^1.4.0-beta.2 - Implemented `setInputMethodEnabled`, `hideInputMethod` InAppWebViewController methods +- Implemented `isUserInteractionEnabled`, `alpha` properties of `InAppWebViewSettings` - Merged "Show / Hide / Disable / Enable soft Keyboard Input (Android & iOS)" [#2408](https://github.com/pichillilorenzo/flutter_inappwebview/pull/2408) (thanks to [Mecharyry](https://github.com/Mecharyry)) +- Fixed "In iOS version 17.2, when moving the input focus in a WebView, an unknown area appears at the top of the screen." [#1947](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1947) ## 1.2.0-beta.1 diff --git a/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebView.swift b/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebView.swift index fde8b4b85..df9d50933 100755 --- a/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebView.swift +++ b/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebView.swift @@ -7,7 +7,7 @@ import Flutter import Foundation -import WebKit +@preconcurrency import WebKit public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler, UIGestureRecognizerDelegate, @@ -106,19 +106,32 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, set { super.frame = newValue - self.scrollView.contentInset = .zero + scrollView.contentInset = .zero if #available(iOS 11, *) { // Above iOS 11, adjust contentInset to compensate the adjustedContentInset so the sum will // always be 0. - if (scrollView.adjustedContentInset != UIEdgeInsets.zero) { - let insetToAdjust = self.scrollView.adjustedContentInset + if (scrollView.adjustedContentInset != .zero) { + let insetToAdjust = scrollView.adjustedContentInset scrollView.contentInset = UIEdgeInsets(top: -insetToAdjust.top, left: -insetToAdjust.left, - bottom: -insetToAdjust.bottom, right: -insetToAdjust.right) + bottom: -insetToAdjust.bottom, right: -insetToAdjust.right) } } } } + @objc func keyboardWillShow(notification: NSNotification) { + // Fix https://github.com/pichillilorenzo/flutter_inappwebview/issues/1947 + if (scrollView.adjustedContentInset != .zero) { + if scrollView.adjustedContentInset.bottom > 0 { + let insetToAdjust = scrollView.adjustedContentInset + scrollView.contentInset = UIEdgeInsets(top: -insetToAdjust.top, left: -insetToAdjust.left, + bottom: -insetToAdjust.bottom, right: -insetToAdjust.right) + } else { + scrollView.contentInset = .zero + } + } + } + required public init(coder aDecoder: NSCoder) { super.init(coder: aDecoder)! } @@ -348,6 +361,13 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, } public func prepare() { + if #available(iOS 17.2, *) { + // Fix https://github.com/pichillilorenzo/flutter_inappwebview/issues/1947 + NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(notification:)), + name: UIResponder.keyboardWillShowNotification, + object: nil) + } + scrollView.addGestureRecognizer(self.longPressRecognizer) scrollView.addGestureRecognizer(self.recognizerForDisablingContextMenuOnLinks) scrollView.addGestureRecognizer(self.panGestureRecognizer) @@ -417,6 +437,12 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, // } if let settings = settings { + isUserInteractionEnabled = settings.isUserInteractionEnabled + + if let viewAlpha = settings.alpha { + alpha = CGFloat(viewAlpha) + } + javaScriptBridgeEnabled = settings.javaScriptBridgeEnabled if let javaScriptBridgeOriginAllowList = settings.javaScriptBridgeOriginAllowList, javaScriptBridgeOriginAllowList.isEmpty { // an empty list means that the JavaScript Bridge is not allowed for any origin. @@ -990,6 +1016,14 @@ public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate, } } + if newSettingsMap["isUserInteractionEnabled"] != nil && settings?.isUserInteractionEnabled != newSettings.isUserInteractionEnabled { + isUserInteractionEnabled = newSettings.isUserInteractionEnabled + } + + if newSettingsMap["alpha"] != nil, settings?.alpha != newSettings.alpha, let viewAlpha = newSettings.alpha { + alpha = CGFloat(viewAlpha) + } + if newSettingsMap["transparentBackground"] != nil && settings?.transparentBackground != newSettings.transparentBackground { if newSettings.transparentBackground { isOpaque = false diff --git a/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebViewSettings.swift b/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebViewSettings.swift index 2b50084fb..94767c473 100755 --- a/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebViewSettings.swift +++ b/flutter_inappwebview_ios/ios/Classes/InAppWebView/InAppWebViewSettings.swift @@ -88,6 +88,8 @@ public class InAppWebViewSettings: ISettings { var javaScriptBridgeForMainFrameOnly = false var pluginScriptsOriginAllowList: [String]? = nil var pluginScriptsForMainFrameOnly = false + var isUserInteractionEnabled = true + var alpha: Double? = nil override init(){ super.init() @@ -103,6 +105,12 @@ public class InAppWebViewSettings: ISettings { maximumViewportInset = UIEdgeInsets.fromMap(map: maximumViewportInsetMap) settings.removeValue(forKey: "maximumViewportInset") } + // nullable values with primitive type (Int, Double, etc.) + // must be handled here as super.parse will not work + if let alphaValue = settings["alpha"] as? Double { + alpha = alphaValue + settings.removeValue(forKey: "alpha") + } let _ = super.parse(settings: settings) if #available(iOS 13.0, *) {} else { applePayAPIEnabled = false @@ -113,6 +121,8 @@ public class InAppWebViewSettings: ISettings { override func getRealSettings(obj: InAppWebView?) -> [String: Any?] { var realSettings: [String: Any?] = toMap() if let webView = obj { + realSettings["isUserInteractionEnabled"] = webView.isUserInteractionEnabled + realSettings["alpha"] = Double(webView.alpha) let configuration = webView.configuration if #available(iOS 9.0, *) { realSettings["userAgent"] = webView.customUserAgent diff --git a/flutter_inappwebview_macos/CHANGELOG.md b/flutter_inappwebview_macos/CHANGELOG.md index 3854b2134..de3af2b9c 100644 --- a/flutter_inappwebview_macos/CHANGELOG.md +++ b/flutter_inappwebview_macos/CHANGELOG.md @@ -1,6 +1,7 @@ ## 1.2.0-beta.2 - Updated flutter_inappwebview_platform_interface version to ^1.4.0-beta.2 +- Implemented `alpha` property of `InAppWebViewSettings` ## 1.2.0-beta.1 diff --git a/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebView.swift b/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebView.swift index 18c493cca..ebc3698e9 100755 --- a/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebView.swift +++ b/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebView.swift @@ -123,6 +123,10 @@ public class InAppWebView: WKWebView, WKUIDelegate, // } if let settings = settings { + if let viewAlpha = settings.alpha { + alphaValue = CGFloat(viewAlpha) + } + javaScriptBridgeEnabled = settings.javaScriptBridgeEnabled if let javaScriptBridgeOriginAllowList = settings.javaScriptBridgeOriginAllowList, javaScriptBridgeOriginAllowList.isEmpty { // an empty list means that the JavaScript Bridge is not allowed for any origin. @@ -560,6 +564,10 @@ public class InAppWebView: WKWebView, WKUIDelegate, } } + if newSettingsMap["alpha"] != nil, settings?.alpha != newSettings.alpha, let viewAlpha = newSettings.alpha { + alphaValue = CGFloat(viewAlpha) + } + if (newSettingsMap["incognito"] != nil && settings?.incognito != newSettings.incognito && newSettings.incognito) { configuration.websiteDataStore = WKWebsiteDataStore.nonPersistent() } else if (newSettingsMap["cacheEnabled"] != nil && settings?.cacheEnabled != newSettings.cacheEnabled && newSettings.cacheEnabled) { diff --git a/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebViewSettings.swift b/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebViewSettings.swift index 041e6c870..fadecf0a0 100755 --- a/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebViewSettings.swift +++ b/flutter_inappwebview_macos/macos/Classes/InAppWebView/InAppWebViewSettings.swift @@ -61,12 +61,20 @@ public class InAppWebViewSettings: ISettings { var javaScriptBridgeForMainFrameOnly = false var pluginScriptsOriginAllowList: [String]? = nil var pluginScriptsForMainFrameOnly = false + var alpha: Double? = nil override init(){ super.init() } override func parse(settings: [String: Any?]) -> InAppWebViewSettings { + var settings = settings // re-assing to be able to use removeValue + // nullable values with primitive type (Int, Double, etc.) + // must be handled here as super.parse will not work + if let alphaValue = settings["alpha"] as? Double { + alpha = alphaValue + settings.removeValue(forKey: "alpha") + } let _ = super.parse(settings: settings) if #available(macOS 10.15, *) {} else { applePayAPIEnabled = false diff --git a/flutter_inappwebview_platform_interface/CHANGELOG.md b/flutter_inappwebview_platform_interface/CHANGELOG.md index 09c993506..234604c8a 100644 --- a/flutter_inappwebview_platform_interface/CHANGELOG.md +++ b/flutter_inappwebview_platform_interface/CHANGELOG.md @@ -3,9 +3,10 @@ - Updated `flutter_inappwebview_internal_annotations` dependency from `^1.1.1` to `^1.2.0` - Updated `fromMap` static method and `toMap` method implementations - Added `byName`, `name`, `asNameMap` custom enum classes methods -- Added `statusBarEnabled`, `browserAcceleratorKeysEnabled`, `generalAutofillEnabled`, `passwordAutosaveEnabled`, `isPinchZoomEnabled`, `hiddenPdfToolbarItems`, `reputationCheckingRequired`, `nonClientRegionSupportEnabled` property to `InAppWebViewSettings` +- Added `statusBarEnabled`, `browserAcceleratorKeysEnabled`, `generalAutofillEnabled`, `passwordAutosaveEnabled`, `isPinchZoomEnabled`, `hiddenPdfToolbarItems`, `reputationCheckingRequired`, `nonClientRegionSupportEnabled`, `alpha`, `isUserInteractionEnabled` properties to `InAppWebViewSettings` - Added `isInterfaceSupported` method to `PlatformWebViewEnvironment` class - Added `isInterfaceSupported`, `setInputMethodEnabled`, `hideInputMethod`, `showInputMethod` methods to `PlatformInAppWebViewController` class +- Fixed missing PrintJobOrientation android values ## 1.4.0-beta.1 diff --git a/flutter_inappwebview_platform_interface/lib/src/in_app_webview/in_app_webview_settings.dart b/flutter_inappwebview_platform_interface/lib/src/in_app_webview/in_app_webview_settings.dart index 27de04468..73b9b96f8 100755 --- a/flutter_inappwebview_platform_interface/lib/src/in_app_webview/in_app_webview_settings.dart +++ b/flutter_inappwebview_platform_interface/lib/src/in_app_webview/in_app_webview_settings.dart @@ -1,10 +1,10 @@ +import 'dart:typed_data'; + import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart'; import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart'; -import 'dart:typed_data'; -import '../platform_webview_asset_loader.dart'; import '../types/action_mode_menu_item.dart'; import '../types/cache_mode.dart'; import '../types/data_detector_types.dart'; @@ -23,20 +23,6 @@ import '../types/scrollview_deceleration_rate.dart'; import '../types/selection_granularity.dart'; import '../types/user_preferred_content_mode.dart'; import '../types/vertical_scrollbar_position.dart'; -import '../types/user_script.dart'; -import '../web_uri.dart'; -import 'android/in_app_webview_options.dart'; -import 'apple/in_app_webview_options.dart'; -import '../content_blocker.dart'; -import '../types/main.dart'; -import '../util.dart'; -import '../in_app_browser/in_app_browser_settings.dart'; -import '../platform_webview_feature.dart'; -import '../in_app_webview/platform_inappwebview_controller.dart'; -import '../context_menu/context_menu.dart'; -import '../in_app_browser/platform_in_app_browser.dart'; -import 'platform_webview.dart'; -import '../types/enum_method.dart'; part 'in_app_webview_settings.g.dart'; @@ -48,7 +34,8 @@ List _deserializeContentBlockers( contentBlockersMapList.forEach((contentBlocker) { contentBlockers.add(ContentBlocker.fromMap( Map>.from( - Map.from(contentBlocker)), enumMethod: enumMethod)); + Map.from(contentBlocker)), + enumMethod: enumMethod)); }); } return contentBlockers; @@ -90,6 +77,7 @@ class InAppWebViewSettings_ { ///Use [PlatformInAppWebViewController.clearAllCache] instead. @Deprecated("Use InAppWebViewController.clearAllCache instead") + @ExchangeableObjectProperty(leaveDeprecatedInToMapMethod: true) @SupportedPlatforms( platforms: [AndroidPlatform(), IOSPlatform(), MacOSPlatform()]) bool? clearCache; @@ -438,6 +426,7 @@ because there isn't any way to make the website data store non-persistent for th ///Use [PlatformCookieManager.removeSessionCookies] instead. @Deprecated("Use CookieManager.removeSessionCookies instead") + @ExchangeableObjectProperty(leaveDeprecatedInToMapMethod: true) @SupportedPlatforms(platforms: [AndroidPlatform()]) bool? clearSessionCache; @@ -637,6 +626,7 @@ because there isn't any way to make the website data store non-persistent for th ///WebView will always use the dark style defined by web content authors if the app's theme is dark. ///To customize the behavior, refer to [algorithmicDarkeningAllowed]. @Deprecated("Use algorithmicDarkeningAllowed instead") + @ExchangeableObjectProperty(leaveDeprecatedInToMapMethod: true) @SupportedPlatforms(platforms: [ AndroidPlatform( available: "29", @@ -657,6 +647,7 @@ because there isn't any way to make the website data store non-persistent for th ///WebView will always use the dark style defined by web content authors if the app's theme is dark. ///To customize the behavior, refer to [algorithmicDarkeningAllowed]. @Deprecated("Use algorithmicDarkeningAllowed instead") + @ExchangeableObjectProperty(leaveDeprecatedInToMapMethod: true) @SupportedPlatforms(platforms: [ AndroidPlatform( apiName: "WebSettingsCompat.setForceDarkStrategy", @@ -786,6 +777,8 @@ because there isn't any way to make the website data store non-persistent for th ///Therefore, the Webview form data save feature is disabled. Note that the feature will continue to be supported on older versions of Android as before. ///The default value is `true`. @Deprecated('') + @ExchangeableObjectProperty( + leaveDeprecatedInToMapMethod: true, leaveDeprecatedInFromMapMethod: true) @SupportedPlatforms(platforms: [ AndroidPlatform( apiName: "WebSettings.setSaveFormData", @@ -953,8 +946,8 @@ as it can cause framerate drops on animations in Android 9 and lower (see [Hybri AndroidPlatform(), WindowsPlatform( apiName: "ICoreWebView2Settings.put_IsBuiltInErrorPageEnabled", - apiUrl: 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings?view=webview2-1.0.2849.39#put_isbuiltinerrorpageenabled' - ), + apiUrl: + 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings?view=webview2-1.0.2849.39#put_isbuiltinerrorpageenabled'), ]) bool? disableDefaultErrorPage; @@ -1115,11 +1108,10 @@ as it can cause framerate drops on animations in Android 9 and lower (see [Hybri apiUrl: "https://developer.apple.com/documentation/webkit/wkwebview/1414995-allowsbackforwardnavigationgestu"), WindowsPlatform( - available: "1.0.992.28", - apiName: "ICoreWebView2Settings6.put_IsSwipeNavigationEnabled", - apiUrl: - "https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings6?view=webview2-1.0.2849.39#put_isswipenavigationenabled" - ), + available: "1.0.992.28", + apiName: "ICoreWebView2Settings6.put_IsSwipeNavigationEnabled", + apiUrl: + "https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings6?view=webview2-1.0.2849.39#put_isswipenavigationenabled"), ]) bool? allowsBackForwardNavigationGestures; @@ -1790,8 +1782,8 @@ as it can cause framerate drops on animations in Android 9 and lower (see [Hybri @SupportedPlatforms(platforms: [ WindowsPlatform( apiName: "ICoreWebView2Settings.put_IsStatusBarEnabled", - apiUrl: 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings?view=webview2-1.0.2849.39#put_isstatusbarenabled' - ), + apiUrl: + 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings?view=webview2-1.0.2849.39#put_isstatusbarenabled'), ]) bool? statusBarEnabled; @@ -1812,10 +1804,10 @@ as it can cause framerate drops on animations in Android 9 and lower (see [Hybri ///The default value is `true`. @SupportedPlatforms(platforms: [ WindowsPlatform( - available: '1.0.864.35', + available: '1.0.864.35', apiName: "ICoreWebView2Settings3.put_IsBuiltInErrorPageEnabled", - apiUrl: 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings3?view=webview2-1.0.2849.39#put_arebrowseracceleratorkeysenabled' - ), + apiUrl: + 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings3?view=webview2-1.0.2849.39#put_arebrowseracceleratorkeysenabled'), ]) bool? browserAcceleratorKeysEnabled; @@ -1832,8 +1824,8 @@ as it can cause framerate drops on animations in Android 9 and lower (see [Hybri WindowsPlatform( available: '1.0.902.49', apiName: "ICoreWebView2Settings4.put_IsGeneralAutofillEnabled", - apiUrl: 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings4?view=webview2-1.0.2849.39#put_isgeneralautofillenabled' - ), + apiUrl: + 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings4?view=webview2-1.0.2849.39#put_isgeneralautofillenabled'), ]) bool? generalAutofillEnabled; @@ -1853,8 +1845,8 @@ as it can cause framerate drops on animations in Android 9 and lower (see [Hybri WindowsPlatform( available: '1.0.902.49', apiName: "ICoreWebView2Settings4.put_IsPasswordAutosaveEnabled", - apiUrl: 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings4?view=webview2-1.0.2849.39#put_ispasswordautosaveenabled' - ), + apiUrl: + 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings4?view=webview2-1.0.2849.39#put_ispasswordautosaveenabled'), ]) bool? passwordAutosaveEnabled; @@ -1878,8 +1870,8 @@ as it can cause framerate drops on animations in Android 9 and lower (see [Hybri WindowsPlatform( available: '1.0.902.49', apiName: "ICoreWebView2Settings5.put_IsPinchZoomEnabled", - apiUrl: 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings5?view=webview2-1.0.2849.39#put_ispinchzoomenabled' - ), + apiUrl: + 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings5?view=webview2-1.0.2849.39#put_ispinchzoomenabled'), ]) bool? pinchZoomEnabled; @@ -1892,8 +1884,8 @@ as it can cause framerate drops on animations in Android 9 and lower (see [Hybri WindowsPlatform( available: '1.0.1185.39', apiName: "ICoreWebView2Settings7.put_HiddenPdfToolbarItems", - apiUrl: 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings7?view=webview2-1.0.2849.39#put_hiddenpdftoolbaritems' - ), + apiUrl: + 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings7?view=webview2-1.0.2849.39#put_hiddenpdftoolbaritems'), ]) PdfToolbarItems_? hiddenPdfToolbarItems; @@ -1918,8 +1910,8 @@ as it can cause framerate drops on animations in Android 9 and lower (see [Hybri WindowsPlatform( available: '1.0.1722.45', apiName: "ICoreWebView2Settings8.put_IsReputationCheckingRequired", - apiUrl: 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings8?view=webview2-1.0.2849.39#put_isreputationcheckingrequired' - ), + apiUrl: + 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings8?view=webview2-1.0.2849.39#put_isreputationcheckingrequired'), ]) bool? reputationCheckingRequired; @@ -1941,11 +1933,41 @@ as it can cause framerate drops on animations in Android 9 and lower (see [Hybri WindowsPlatform( available: '1.0.2420.47', apiName: "ICoreWebView2Settings9.put_IsNonClientRegionSupportEnabled", - apiUrl: 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings9?view=webview2-1.0.2849.39#put_isnonclientregionsupportenabled' - ), + apiUrl: + 'https://learn.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings9?view=webview2-1.0.2849.39#put_isnonclientregionsupportenabled'), ]) bool? nonClientRegionSupportEnabled; + ///A Boolean value that determines whether user events are ignored and removed from the event queue. + /// + ///The default value is `true`. + @SupportedPlatforms(platforms: [ + AndroidPlatform(), + IOSPlatform( + apiName: "UIView.isUserInteractionEnabled", + apiUrl: + 'https://developer.apple.com/documentation/uikit/uiview/1622577-isuserinteractionenabled'), + ]) + bool? isUserInteractionEnabled; + + ///The view’s alpha value. The value of this property is a floating-point number + ///in the range 0.0 to 1.0, where 0.0 represents totally transparent and 1.0 represents totally opaque. + @SupportedPlatforms(platforms: [ + AndroidPlatform( + apiName: "View.setAlpha", + apiUrl: + 'https://developer.android.com/reference/android/view/View#setAlpha(float)'), + IOSPlatform( + apiName: "UIView.alpha", + apiUrl: + 'https://developer.apple.com/documentation/uikit/uiview/1622417-alpha'), + MacOSPlatform( + apiName: "NSView.alphaValue", + apiUrl: + 'https://developer.apple.com/documentation/appkit/nsview/1483560-alphavalue'), + ]) + double? alpha; + ///Specifies a feature policy for the `