Skip to content

Commit

Permalink
feat(ios): allow to set status bar animation style on show and hide (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sbannigan authored Mar 19, 2020
1 parent 9997b3e commit fa6bb3e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
26 changes: 24 additions & 2 deletions core/src/core-plugin-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1599,11 +1599,11 @@ export interface StatusBarPlugin extends Plugin {
/**
* Show the status bar
*/
show(): Promise<void>;
show(options?: StatusBarAnimationOptions): Promise<void>;
/**
* Hide the status bar
*/
hide(): Promise<void>;
hide(options?: StatusBarAnimationOptions): Promise<void>;
/**
* Get info about the current state of the status bar
*/
Expand All @@ -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;
}
Expand Down
9 changes: 9 additions & 0 deletions ios/Capacitor/Capacitor/CAPBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion ios/Capacitor/Capacitor/CAPBridgeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int> = []

@objc public var startDir = ""
Expand Down Expand Up @@ -405,7 +406,7 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKScr

override public var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
get {
return .slide
return statusBarAnimation
}
}

Expand All @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions ios/Capacitor/Capacitor/Plugins/StatusBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit fa6bb3e

Please sign in to comment.