mirror of
https://github.com/status-im/react-native-webview.git
synced 2026-08-31 03:31:05 +00:00
feat(focus): Add functionality to imperatively focus webview (#567)
* - add focus functionality for devices without touch screen (faced problem while developing for android TV, cause there only remote controller for device) * Reimplement as a ref method. * - remove redundant requestFocus
This commit is contained in:
committed by
Thibault Malbranche
parent
9db55a5769
commit
6f053bad7b
@@ -110,6 +110,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
public static final int COMMAND_POST_MESSAGE = 5;
|
||||
public static final int COMMAND_INJECT_JAVASCRIPT = 6;
|
||||
public static final int COMMAND_LOAD_URL = 7;
|
||||
public static final int COMMAND_FOCUS = 8;
|
||||
protected static final String REACT_CLASS = "RNCWebView";
|
||||
protected static final String HTML_ENCODING = "UTF-8";
|
||||
protected static final String HTML_MIME_TYPE = "text/html";
|
||||
@@ -511,7 +512,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
@Override
|
||||
public @Nullable
|
||||
Map<String, Integer> getCommandsMap() {
|
||||
return MapBuilder.of(
|
||||
Map map = MapBuilder.of(
|
||||
"goBack", COMMAND_GO_BACK,
|
||||
"goForward", COMMAND_GO_FORWARD,
|
||||
"reload", COMMAND_RELOAD,
|
||||
@@ -520,6 +521,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
"injectJavaScript", COMMAND_INJECT_JAVASCRIPT,
|
||||
"loadUrl", COMMAND_LOAD_URL
|
||||
);
|
||||
map.put("requestFocus", COMMAND_FOCUS);
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -567,6 +570,9 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
}
|
||||
root.loadUrl(args.getString(0));
|
||||
break;
|
||||
case COMMAND_FOCUS:
|
||||
root.requestFocus();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user