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

feat(ios): set status bar animation style when showing and hiding #2587

Merged
merged 1 commit into from
Mar 19, 2020
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
26 changes: 24 additions & 2 deletions core/src/core-plugin-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1595,11 +1595,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 @@ -1621,6 +1621,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