Skip to content

Commit

Permalink
manual copy of the PR
Browse files Browse the repository at this point in the history
pichillilorenzo#2168

it is not yet implemented so lets change it until this get the main repo
  • Loading branch information
fhdeodato committed Jun 17, 2024
1 parent b0dbccc commit 6145f25
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ class InAppWebViewController {
Future<InAppWebViewHitTestResult?> getHitTestResult() =>
platform.getHitTestResult();

///{@macro flutter_inappwebview_platform_interface.PlatformInAppWebViewController.requestFocus}
Future<void> requestFocus() => platform.requestFocus();

///{@macro flutter_inappwebview_platform_interface.PlatformInAppWebViewController.clearFocus}
Future<void> clearFocus() => platform.clearFocus();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,12 @@ public void onReceiveValue(String value) {
}
result.success(true);
break;
case requestFocus:
if (webView != null) {
webView.requestFocus();
}
result.success(true);
break;
case setContextMenu:
if (webView != null) {
Map<String, Object> contextMenu = (Map<String, Object>) call.argument("contextMenu");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public enum WebViewChannelDelegateMethods {
saveWebArchive,
zoomIn,
zoomOut,
requestFocus,
clearFocus,
setContextMenu,
requestFocusNodeHref,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2241,6 +2241,12 @@ class AndroidInAppWebViewController extends PlatformInAppWebViewController
return InAppWebViewHitTestResult(type: type, extra: extra);
}

@override
Future<void> requestFocus() async {
Map<String, dynamic> args = <String, dynamic>{};
return await channel?.invokeMethod('requestFocus', args);
}

@override
Future<void> clearFocus() async {
Map<String, dynamic> args = <String, dynamic>{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3129,6 +3129,10 @@ if(window.\(JAVASCRIPT_BRIDGE_NAME)[\(_callHandlerID)] != null) {
public func clearFocus() {
self.scrollView.subviews.first?.resignFirstResponder()
}

public func requestFocus() {
self.scrollView.subviews.first?.becomeFirstResponder()
}

public func getCertificate() -> SslCertificate? {
guard let scheme = url?.scheme,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ public class WebViewChannelDelegate: ChannelDelegate {
webView?.clearFocus()
result(true)
break
case .requestFocus:
webView?.requestFocus()
result(true)
break
case .setContextMenu:
if let webView = webView {
let contextMenu = arguments!["contextMenu"] as? [String: Any]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public enum WebViewChannelDelegateMethods: String {
case getSelectedText = "getSelectedText"
case getHitTestResult = "getHitTestResult"
case clearFocus = "clearFocus"
case requestFocus = "requestFocus"
case setContextMenu = "setContextMenu"
case requestFocusNodeHref = "requestFocusNodeHref"
case requestImageRef = "requestImageRef"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2234,6 +2234,12 @@ class IOSInAppWebViewController extends PlatformInAppWebViewController
return await channel?.invokeMethod('clearFocus', args);
}

@override
Future<void> requestFocus() async {
Map<String, dynamic> args = <String, dynamic>{};
return await channel?.invokeMethod('requestFocus', args);
}

@override
Future<void> setContextMenu(ContextMenu? contextMenu) async {
Map<String, dynamic> args = <String, dynamic>{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,11 @@ abstract class PlatformInAppWebViewController extends PlatformInterface
'getHitTestResult is not implemented on the current platform');
}

Future<void> requestFocus() {
throw UnimplementedError(
'requestFocus is not implemented on the current platform');
}

///{@template flutter_inappwebview_platform_interface.PlatformInAppWebViewController.clearFocus}
///Clears the current focus. On iOS and Android native WebView, it will clear also, for example, the current text selection.
///
Expand Down

0 comments on commit 6145f25

Please sign in to comment.