diff --git a/core/src/core-plugin-definitions.ts b/core/src/core-plugin-definitions.ts index 9d6fbd0095..01b915f37d 100644 --- a/core/src/core-plugin-definitions.ts +++ b/core/src/core-plugin-definitions.ts @@ -1599,11 +1599,11 @@ export interface StatusBarPlugin extends Plugin { /** * Show the status bar */ - show(): Promise; + show(options?: StatusBarAnimationOptions): Promise; /** * Hide the status bar */ - hide(): Promise; + hide(options?: StatusBarAnimationOptions): Promise; /** * Get info about the current state of the status bar */ @@ -1625,6 +1625,28 @@ export enum StatusBarStyle { Light = 'LIGHT' } +export interface StatusBarAnimationOptions { + /** + * iOS only. The type of status bar animation used when showing or hiding. + */ + animation: StatusBarAnimation; +} + +export enum StatusBarAnimation { + /** + * No animation during show/hide. + */ + None = 'NONE', + /** + * Slide animation during show/hide. + */ + Slide = 'SLIDE', + /** + * Fade animation during show/hide. + */ + Fade = 'FADE' +} + export interface StatusBarBackgroundColorOptions { color: string; } diff --git a/ios/Capacitor/Capacitor/CAPBridge.swift b/ios/Capacitor/Capacitor/CAPBridge.swift index ccc2d42ab1..b0bdd4b361 100644 --- a/ios/Capacitor/Capacitor/CAPBridge.swift +++ b/ios/Capacitor/Capacitor/CAPBridge.swift @@ -83,6 +83,15 @@ enum BridgeError: Error { } } + public func setStatusBarAnimation(_ statusBarAnimation: UIStatusBarAnimation) { + guard let bridgeVC = self.viewController as? CAPBridgeViewController else { + return + } + DispatchQueue.main.async { + bridgeVC.setStatusBarAnimation(statusBarAnimation) + } + } + public func getStatusBarVisible() -> Bool { guard let bridgeVC = self.viewController as? CAPBridgeViewController else { return false diff --git a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift index 50bb6399c9..b09b3b5ee3 100644 --- a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift +++ b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift @@ -26,6 +26,7 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr private var isStatusBarVisible = true private var statusBarStyle: UIStatusBarStyle = .default + private var statusBarAnimation: UIStatusBarAnimation = .slide @objc public var supportedOrientations: Array = [] @objc public var startDir = "" @@ -405,7 +406,7 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr override public var preferredStatusBarUpdateAnimation: UIStatusBarAnimation { get { - return .slide + return statusBarAnimation } } @@ -423,6 +424,10 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr }) } + public func setStatusBarAnimation(_ statusBarAnimation: UIStatusBarAnimation) { + self.statusBarAnimation = statusBarAnimation + } + public func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) { let alertController = UIAlertController(title: nil, message: message, preferredStyle: .alert) diff --git a/ios/Capacitor/Capacitor/Plugins/StatusBar.swift b/ios/Capacitor/Capacitor/Plugins/StatusBar.swift index f13fb98c2e..97a13d5a9f 100644 --- a/ios/Capacitor/Capacitor/Plugins/StatusBar.swift +++ b/ios/Capacitor/Capacitor/Plugins/StatusBar.swift @@ -35,12 +35,25 @@ public class CAPStatusBarPlugin: CAPPlugin { call.unimplemented() } + func setAnimation(_ call: CAPPluginCall) { + let animation = call.getString("animation", "SLIDE") + if animation == "FADE" { + bridge.setStatusBarAnimation(.fade) + } else if animation == "NONE" { + bridge.setStatusBarAnimation(.none) + } else { + bridge.setStatusBarAnimation(.slide) + } + } + @objc func hide(_ call: CAPPluginCall) { + setAnimation(call) bridge.setStatusBarVisible(false) call.success() } @objc func show(_ call: CAPPluginCall) { + setAnimation(call) bridge.setStatusBarVisible(true) call.success() }