From aa0f8be8f67653ec6e512579df5d60ae6b733e2d Mon Sep 17 00:00:00 2001 From: Carl Poole Date: Fri, 22 Apr 2022 15:24:04 -0500 Subject: [PATCH 1/3] fix(android): move initialFocus on webview into config --- .../src/main/java/com/getcapacitor/Bridge.java | 5 ++++- .../src/main/java/com/getcapacitor/CapConfig.java | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java index 50d961f2a6..e2816d82b1 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java +++ b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java @@ -447,7 +447,10 @@ private void initWebView() { Logger.debug("WebView background color not applied"); } - webView.requestFocusFromTouch(); + if (config.isInitialFocus()) { + webView.requestFocusFromTouch(); + } + WebView.setWebContentsDebuggingEnabled(this.config.isWebContentsDebuggingEnabled()); } diff --git a/android/capacitor/src/main/java/com/getcapacitor/CapConfig.java b/android/capacitor/src/main/java/com/getcapacitor/CapConfig.java index 2e44503342..22f3db1a3c 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/CapConfig.java +++ b/android/capacitor/src/main/java/com/getcapacitor/CapConfig.java @@ -40,6 +40,7 @@ public class CapConfig { private boolean captureInput = false; private boolean webContentsDebuggingEnabled = false; private boolean loggingEnabled = true; + private boolean initialFocus = true; // Embedded private String startPath; @@ -116,6 +117,7 @@ private CapConfig(Builder builder) { this.captureInput = builder.captureInput; this.webContentsDebuggingEnabled = builder.webContentsDebuggingEnabled; this.loggingEnabled = builder.loggingEnabled; + this.initialFocus = builder.initialFocus; // Embedded this.startPath = builder.startPath; @@ -187,6 +189,8 @@ private void deserializeConfig(@Nullable Context context) { loggingEnabled = isDebug; } + initialFocus = JSONUtils.getBoolean(configJSON, "android.initialFocus", initialFocus); + // Plugins pluginsConfiguration = deserializePluginsConfig(JSONUtils.getObject(configJSON, "plugins")); } @@ -243,6 +247,10 @@ public boolean isLoggingEnabled() { return loggingEnabled; } + public boolean isInitialFocus() { + return initialFocus; + } + public PluginConfig getPluginConfiguration(String pluginId) { PluginConfig pluginConfig = pluginsConfiguration.get(pluginId); if (pluginConfig == null) { @@ -398,6 +406,7 @@ public static class Builder { private boolean captureInput = false; private Boolean webContentsDebuggingEnabled = null; private boolean loggingEnabled = true; + private boolean initialFocus = false; // Embedded private String startPath = null; @@ -496,5 +505,10 @@ public Builder setLoggingEnabled(boolean enabled) { this.loggingEnabled = enabled; return this; } + + public Builder setInitialFocus(boolean focus) { + this.initialFocus = focus; + return this; + } } } From f473c9d8c4383a466a9ee86126b4469b552fa764 Mon Sep 17 00:00:00 2001 From: Carl Poole Date: Fri, 29 Apr 2022 13:11:22 -0500 Subject: [PATCH 2/3] Added initialFocus for Android to the cli declarations --- cli/src/declarations.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cli/src/declarations.ts b/cli/src/declarations.ts index dc17d5befb..3d6be02f9d 100644 --- a/cli/src/declarations.ts +++ b/cli/src/declarations.ts @@ -203,6 +203,14 @@ export interface CapacitorConfig { * @since 3.1.0 */ flavor?: string; + + /** + * Wether to give the webview initial focus. + * + * @since 3.5.1 + * @default true + */ + initialFocus?: boolean; }; ios?: { From b43a84ff57f2d272a8772afd521cb95cc15ff770 Mon Sep 17 00:00:00 2001 From: Carl Poole Date: Fri, 29 Apr 2022 14:11:11 -0500 Subject: [PATCH 3/3] Weather typo --- cli/src/declarations.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/declarations.ts b/cli/src/declarations.ts index 3d6be02f9d..0c12bbb761 100644 --- a/cli/src/declarations.ts +++ b/cli/src/declarations.ts @@ -205,7 +205,7 @@ export interface CapacitorConfig { flavor?: string; /** - * Wether to give the webview initial focus. + * Whether to give the webview initial focus. * * @since 3.5.1 * @default true