From 61d01653685d8e3594d2d8a6bd870fa9643ba95c Mon Sep 17 00:00:00 2001 From: Joey Pender Date: Wed, 18 Dec 2024 04:00:38 -0600 Subject: [PATCH] feat: Add global initialFocus configuration (#7775) Co-authored-by: jcesarmobile --- .../src/main/java/com/getcapacitor/CapConfig.java | 6 +++++- cli/src/declarations.ts | 12 ++++++++++++ ios/Capacitor/Capacitor/CAPInstanceDescriptor.swift | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/android/capacitor/src/main/java/com/getcapacitor/CapConfig.java b/android/capacitor/src/main/java/com/getcapacitor/CapConfig.java index c621a9b69..5b0e22a6e 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/CapConfig.java +++ b/android/capacitor/src/main/java/com/getcapacitor/CapConfig.java @@ -299,7 +299,11 @@ private void deserializeConfig(@Nullable Context context) { loggingEnabled = isDebug; } - initialFocus = JSONUtils.getBoolean(configJSON, "android.initialFocus", initialFocus); + initialFocus = JSONUtils.getBoolean( + configJSON, + "android.initialFocus", + JSONUtils.getBoolean(configJSON, "initialFocus", initialFocus) + ); // Plugins pluginsConfiguration = deserializePluginsConfig(JSONUtils.getObject(configJSON, "plugins")); diff --git a/cli/src/declarations.ts b/cli/src/declarations.ts index a0975a6be..1199463d6 100644 --- a/cli/src/declarations.ts +++ b/cli/src/declarations.ts @@ -77,6 +77,14 @@ export interface CapacitorConfig { */ zoomEnabled?: boolean; + /** + * Whether to give the webview initial focus. + * + * @since 7.0.0 + * @default true + */ + initialFocus?: boolean; + android?: { /** * Specify a custom path to the native Android project. @@ -191,6 +199,8 @@ export interface CapacitorConfig { /** * Whether to give the webview initial focus. * + * Overrides global `initialFocus` option. + * * @since 3.5.1 * @default true */ @@ -453,6 +463,8 @@ export interface CapacitorConfig { /** * Whether to give the webview initial focus. * + * Overrides global `initialFocus` option. + * * @since 7.0.0 * @default true */ diff --git a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.swift b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.swift index 75b990b72..68344d194 100644 --- a/ios/Capacitor/Capacitor/CAPInstanceDescriptor.swift +++ b/ios/Capacitor/Capacitor/CAPInstanceDescriptor.swift @@ -141,7 +141,7 @@ internal extension InstanceDescriptor { isWebDebuggable = true #endif } - if let initialFocus = config[keyPath: "ios.initialFocus"] as? Bool { + if let initialFocus = (config[keyPath: "ios.initialFocus"] as? Bool) ?? (config[keyPath: "initialFocus"] as? Bool) { hasInitialFocus = initialFocus } }