-
Notifications
You must be signed in to change notification settings - Fork 607
/
Copy pathEKAttributes+StatusBar.swift
91 lines (76 loc) · 2.88 KB
/
EKAttributes+StatusBar.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// EKAttributes+StatusBar.swift
// SwiftEntryKit
//
// Created by Daniel Huri on 5/25/18.
// Copyright (c) 2018 [email protected]. All rights reserved.
//
import UIKit
public extension EKAttributes {
/** Status bar appearance */
enum StatusBar {
/** The appearance of the status bar */
public typealias Appearance = (visible: Bool, style: UIStatusBarStyle)
/** Ignored. Status bar is ignored by entries with this apperance value*/
case ignored
/** Hidden. Doesn't apply to iPhone X */
case hidden
/** Visible with explicit dark style */
case dark
/** Visible with explicit light style */
case light
/** Keep previous state of status bar.
In case there is an already displayed entry, keep its status bar appearance.
In case the app is already displaying a status bar, keep its appearance */
case inferred
/** Returns the status bar appearance.
Note: See *Appearance* */
public var appearance: Appearance {
switch self {
case .dark:
if #available(iOS 13, *) {
return (true, .darkContent)
} else {
return (true, .default)
}
case .light:
return (true, .lightContent)
case .inferred:
return StatusBar.currentAppearance
case .hidden:
return (false, StatusBar.currentStyle)
case .ignored:
fatalError("There is no defined appearance for an ignored status bar")
}
}
/** Returns the status bar according to a given appearance */
public static func statusBar(by appearance: Appearance) -> StatusBar {
guard appearance.visible else {
return .hidden
}
switch appearance.style {
case .lightContent:
return .light
default:
return .dark
}
}
/** Returns the current appearance */
public static var currentAppearance: Appearance {
return (StatusBar.isCurrentVisible, StatusBar.currentStyle)
}
/** Returns the current status bar */
public static var currentStatusBar: StatusBar {
return statusBar(by: currentAppearance)
}
// Accessors
// TODO: Use `statusBarManager` of the window scene on iOS 13
private static var currentStyle: UIStatusBarStyle {
return UIApplication.shared.statusBarStyle
}
// TODO: Use `statusBarManager` of the window scene on iOS 13
private static var isCurrentVisible: Bool {
return !UIApplication.shared.isStatusBarHidden
}
}
}