diff --git a/ios/App/App/Echo.swift b/ios/App/App/PluginSafeAreasColor.swift similarity index 87% rename from ios/App/App/Echo.swift rename to ios/App/App/PluginSafeAreasColor.swift index 1d8ba2a29..726bb0c62 100644 --- a/ios/App/App/Echo.swift +++ b/ios/App/App/PluginSafeAreasColor.swift @@ -1,15 +1,15 @@ import Capacitor import UIKit -@objc(EchoPlugin) -public class EchoPlugin: CAPPlugin, CAPBridgedPlugin { - public let identifier = "EchoPlugin" - public let jsName = "Echo" +@objc(SafeAreasColorPlugin) +public class SafeAreasColorPlugin: CAPPlugin, CAPBridgedPlugin { + public let identifier = "SafeAreasColorPlugin" + public let jsName = "SafeAreasColor" public let pluginMethods: [CAPPluginMethod] = [ - CAPPluginMethod(name: "echo", returnType: CAPPluginReturnPromise) + CAPPluginMethod(name: "changeSafeAreasColorOniOS", returnType: CAPPluginReturnPromise) ] - @objc func echo(_ call: CAPPluginCall) { + @objc func changeSafeAreasColorOniOS(_ call: CAPPluginCall) { let value = call.getString("color") ?? "" guard let uiColor = UIColor(hex: value) else { call.reject("Invalid color format") diff --git a/ios/App/PluginViewController.swift b/ios/App/PluginViewController.swift index 7d7925d19..a9445195a 100644 --- a/ios/App/PluginViewController.swift +++ b/ios/App/PluginViewController.swift @@ -3,7 +3,7 @@ import Capacitor class PluginViewController: CAPBridgeViewController { override open func capacitorDidLoad() { - bridge?.registerPluginInstance(EchoPlugin()) + bridge?.registerPluginInstance(SafeAreasColorPlugin()) } override open func viewDidLoad() { diff --git a/src/lib/plugins/safeAreaColorAndroid.ts b/src/lib/plugins/safeAreaColorAndroid.ts index 02730a278..2439883b7 100644 --- a/src/lib/plugins/safeAreaColorAndroid.ts +++ b/src/lib/plugins/safeAreaColorAndroid.ts @@ -1,5 +1,6 @@ import { log } from "$lib/utils/Logger" import { registerPlugin } from "@capacitor/core" +import { StatusBar, Style } from "@capacitor/status-bar" interface ISafeAreaColorPlugin { setStatusBarColor(options: { color: string }): Promise<{ value: string }> @@ -11,6 +12,16 @@ const SafeAreaColorPlugin = registerPlugin("SafeAreaColorP async function setStatusBarColor(color: string) { try { log.info("Calling native android function to change status bar color") + if (color.toLowerCase() === "white") { + color = "#FFFFFF" + log.info(`Converted color "white" to hexadecimal: ${color}`) + await StatusBar.setStyle({ style: Style.Light }) + log.debug("Change status bar style to light") + } else { + await StatusBar.setStyle({ style: Style.Dark }) + log.debug("Change status bar style to dark") + } + await SafeAreaColorPlugin.setStatusBarColor({ color }) } catch (error) { log.error("Error setting status bar color:", error) diff --git a/src/lib/plugins/safeAreaColoriOS.ts b/src/lib/plugins/safeAreaColoriOS.ts index 249955e04..606799c45 100644 --- a/src/lib/plugins/safeAreaColoriOS.ts +++ b/src/lib/plugins/safeAreaColoriOS.ts @@ -2,11 +2,11 @@ import { log } from "$lib/utils/Logger" import { registerPlugin } from "@capacitor/core" import { StatusBar, Style } from "@capacitor/status-bar" -interface IEchoPlugin { - echo(options: { color: string }): Promise<{ value: string }> +interface ISafeAreasColorPlugin { + changeSafeAreasColorOniOS(options: { color: string }): Promise<{ value: string }> } -const Echo = registerPlugin("Echo") +const Echo = registerPlugin("SafeAreasColor") async function setNewSafeAreasColorOniOS(color: string) { try { @@ -23,7 +23,7 @@ async function setNewSafeAreasColorOniOS(color: string) { log.debug("Change status bar style to dark") } - await Echo.echo({ color }) + await Echo.changeSafeAreasColorOniOS({ color }) } catch (error) { log.error("Error trying to call swift function:", error) }