Skip to content

Commit

Permalink
Merge branch 'v6.2.0-beta.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
pichillilorenzo committed Nov 12, 2024
2 parents fe5949f + dd7d2df commit 6c5ed7b
Show file tree
Hide file tree
Showing 22 changed files with 497 additions and 255 deletions.
Original file line number Diff line number Diff line change
@@ -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,
});
}
106 changes: 73 additions & 33 deletions dev_packages/generators/lib/src/exchangeable_object_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand All @@ -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)) {
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion flutter_inappwebview/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
8 changes: 5 additions & 3 deletions flutter_inappwebview/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions flutter_inappwebview_android/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ public class InAppWebViewSettings implements ISettings<InAppWebViewInterface> {
@Nullable
public Set<String> pluginScriptsOriginAllowList;
public Boolean pluginScriptsForMainFrameOnly = false;
public Boolean isUserInteractionEnabled = true;
@Nullable
public Double alpha = null;

@NonNull
@Override
Expand Down Expand Up @@ -459,6 +462,12 @@ public InAppWebViewSettings parse(@NonNull Map<String, Object> settings) {
case "pluginScriptsForMainFrameOnly":
pluginScriptsForMainFrameOnly = (Boolean) value;
break;
case "isUserInteractionEnabled":
isUserInteractionEnabled = (Boolean) value;
break;
case "alpha":
alpha = (Double) value;
break;
}
}

Expand Down Expand Up @@ -573,6 +582,8 @@ public Map<String, Object> toMap() {
settings.put("pluginScriptsOriginAllowList",
pluginScriptsOriginAllowList != null ? new ArrayList<>(pluginScriptsOriginAllowList) : null);
settings.put("pluginScriptsForMainFrameOnly", pluginScriptsForMainFrameOnly);
settings.put("isUserInteractionEnabled", isUserInteractionEnabled);
settings.put("alpha", alpha);
return settings;
}

Expand All @@ -583,6 +594,8 @@ public Map<String, Object> getRealSettings(@NonNull InAppWebViewInterface inAppW
Map<String, Object> 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());
Expand Down
2 changes: 2 additions & 0 deletions flutter_inappwebview_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Flutter
import Foundation
import WebKit
@preconcurrency import WebKit

public class InAppWebView: WKWebView, UIScrollViewDelegate, WKUIDelegate,
WKNavigationDelegate, WKScriptMessageHandler, UIGestureRecognizerDelegate,
Expand Down Expand Up @@ -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)!
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 6c5ed7b

Please sign in to comment.