Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): move initialFocus on webview into config #5579

Merged
merged 4 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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