Skip to content

Commit

Permalink
fix(android): move initialFocus on webview into config (#5579)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlpoole authored May 4, 2022
1 parent f35d96b commit 8b4e861
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion android/capacitor/src/main/java/com/getcapacitor/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
14 changes: 14 additions & 0 deletions android/capacitor/src/main/java/com/getcapacitor/CapConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -496,5 +505,10 @@ public Builder setLoggingEnabled(boolean enabled) {
this.loggingEnabled = enabled;
return this;
}

public Builder setInitialFocus(boolean focus) {
this.initialFocus = focus;
return this;
}
}
}
8 changes: 8 additions & 0 deletions cli/src/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ export interface CapacitorConfig {
* @since 3.1.0
*/
flavor?: string;

/**
* Whether to give the webview initial focus.
*
* @since 3.5.1
* @default true
*/
initialFocus?: boolean;
};

ios?: {
Expand Down

0 comments on commit 8b4e861

Please sign in to comment.