Skip to content

Commit 3545dd5

Browse files
committed
Feat: Android suuport requestFocus function
1 parent 4c650b8 commit 3545dd5

File tree

8 files changed

+30
-0
lines changed

8 files changed

+30
-0
lines changed

android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/InAppWebViewInterface.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ void loadDataWithBaseURL(String baseUrl, String data,
8181
boolean zoomIn();
8282
boolean zoomOut();
8383
void clearFocus();
84+
void requestFocusView(); // For requestFocus
8485
Map<String, Object> requestFocusNodeHref();
8586
Map<String, Object> requestImageRef();
8687
int getScrollX();

android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/WebViewChannelDelegate.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,13 @@ public void onReceiveValue(String value) {
483483
}
484484
result.success(true);
485485
break;
486+
case requestFocus:
487+
if (webView != null) {
488+
webView.requestFocusView();
489+
} else {
490+
result.success(true);
491+
}
492+
break;
486493
case requestFocusNodeHref:
487494
if (webView != null) {
488495
result.success(webView.requestFocusNodeHref());

android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/WebViewChannelDelegateMethods.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public enum WebViewChannelDelegateMethods {
6060
zoomOut,
6161
clearFocus,
6262
setContextMenu,
63+
requestFocus,
6364
requestFocusNodeHref,
6465
requestImageRef,
6566
getScrollX,

android/src/main/java/com/pichillilorenzo/flutter_inappwebview/webview/in_app_webview/InAppWebView.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,16 @@ public void onReceiveValue(String value) {
17191719
});
17201720
}
17211721

1722+
public void requestFocusView() {
1723+
requestFocus();
1724+
InputMethodManager inputManager =
1725+
(InputMethodManager) this.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
1726+
if (inputManager != null) {
1727+
inputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED,
1728+
InputMethodManager.HIDE_IMPLICIT_ONLY);
1729+
}
1730+
}
1731+
17221732
public Map<String, Object> requestFocusNodeHref() {
17231733
Message msg = InAppWebView.mHandler.obtainMessage();
17241734
requestFocusNodeHref(msg);

lib/src/in_app_webview/apple/in_app_webview_options.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class IOSInAppWebViewOptions
181181
///- [InAppWebViewController.pauseTimers]
182182
///- [InAppWebViewController.getSelectedText]
183183
///- [InAppWebViewController.getHitTestResult]
184+
///- [InAppWebViewController.requestFocus]
184185
///- [InAppWebViewController.requestFocusNodeHref]
185186
///- [InAppWebViewController.requestImageRef]
186187
///- [InAppWebViewController.postWebMessage]

lib/src/in_app_webview/in_app_webview_controller.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2606,6 +2606,14 @@ class InAppWebViewController {
26062606
_inAppBrowser?.contextMenu = contextMenu;
26072607
}
26082608

2609+
/// Only support android.
2610+
///
2611+
///- Android issue: https://www.pudn.com/news/6228d8129ddf223e1ad224f8.html
2612+
Future<void> requestFocus() async {
2613+
Map<String, dynamic> args = <String, dynamic>{};
2614+
return await _channel.invokeMethod('requestFocus', args);
2615+
}
2616+
26092617
///Requests the anchor or image element URL at the last tapped point.
26102618
///
26112619
///**NOTE**: On iOS, it is implemented using JavaScript.

lib/src/in_app_webview/in_app_webview_settings.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,7 @@ class InAppWebViewSettings_ {
10991099
///- [InAppWebViewController.pauseTimers]
11001100
///- [InAppWebViewController.getSelectedText]
11011101
///- [InAppWebViewController.getHitTestResult]
1102+
///- [InAppWebViewController.requestFocus]
11021103
///- [InAppWebViewController.requestFocusNodeHref]
11031104
///- [InAppWebViewController.requestImageRef]
11041105
///- [InAppWebViewController.postWebMessage]

lib/src/in_app_webview/in_app_webview_settings.g.dart

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)