capacitor-plugin-status-bar 2.0.13 → 2.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -21
- package/android/src/main/java/com/cap/plugins/statusbar/CapacitorStatusBar.java +308 -457
- package/android/src/main/java/com/cap/plugins/statusbar/CapacitorStatusBarPlugin.java +1 -21
- package/dist/docs.json +0 -40
- package/dist/esm/definitions.d.ts +0 -9
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +1 -2
- package/dist/esm/web.js +0 -3
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +0 -3
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +0 -3
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapacitorStatusBarPlugin/CapacitorStatusBar.swift +173 -78
- package/ios/Sources/CapacitorStatusBarPlugin/CapacitorStatusBarPlugin.swift +18 -21
- package/package.json +1 -1
|
@@ -9,6 +9,12 @@ import Capacitor
|
|
|
9
9
|
private var currentBackgroundColor: UIColor?
|
|
10
10
|
// Track whether overlays web view mode is active
|
|
11
11
|
private var isOverlayMode = false
|
|
12
|
+
// Keep a weak reference to the Capacitor WKWebView for layout updates
|
|
13
|
+
private weak var webView: UIView?
|
|
14
|
+
|
|
15
|
+
@objc public func setWebView(_ webView: UIView?) {
|
|
16
|
+
self.webView = webView
|
|
17
|
+
}
|
|
12
18
|
|
|
13
19
|
@objc public func applyDefaultStyle() {
|
|
14
20
|
DispatchQueue.main.async {
|
|
@@ -19,11 +25,14 @@ import Capacitor
|
|
|
19
25
|
}
|
|
20
26
|
}
|
|
21
27
|
|
|
22
|
-
@objc public func setStyle(style: String, colorHex: String?) {
|
|
28
|
+
@objc public func setStyle(style: String, colorHex: String?, completion: (() -> Void)? = nil) {
|
|
23
29
|
DispatchQueue.main.async {
|
|
30
|
+
defer { completion?() }
|
|
31
|
+
|
|
24
32
|
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene else { return }
|
|
25
33
|
guard let window = windowScene.windows.first else { return }
|
|
26
34
|
guard let statusBarManager = windowScene.statusBarManager else { return }
|
|
35
|
+
guard let rootVC = window.rootViewController else { return }
|
|
27
36
|
|
|
28
37
|
let upperStyle = style.uppercased()
|
|
29
38
|
var backgroundColor: UIColor?
|
|
@@ -31,33 +40,29 @@ import Capacitor
|
|
|
31
40
|
|
|
32
41
|
// Determine the status bar style and background color
|
|
33
42
|
if upperStyle == "LIGHT" {
|
|
34
|
-
// Light style: light background with dark content
|
|
35
43
|
statusBarStyle = .darkContent
|
|
36
44
|
backgroundColor = .white
|
|
37
45
|
} else if upperStyle == "DARK" {
|
|
38
|
-
// Dark style: dark background with light content
|
|
39
46
|
statusBarStyle = .lightContent
|
|
40
47
|
backgroundColor = .black
|
|
41
48
|
} else if upperStyle == "CUSTOM" {
|
|
42
|
-
// Custom style: use provided color and determine content style based on brightness
|
|
43
49
|
if let colorHex = colorHex, let color = self.colorFromHex(colorHex) {
|
|
44
50
|
backgroundColor = color
|
|
45
51
|
let brightness = self.getColorBrightness(color)
|
|
46
|
-
// If background is light, use dark content; if dark, use light content
|
|
47
52
|
statusBarStyle = brightness > 0.5 ? .darkContent : .lightContent
|
|
48
53
|
} else {
|
|
49
|
-
// No color provided, use system default
|
|
50
54
|
statusBarStyle = .default
|
|
51
55
|
backgroundColor = nil
|
|
52
56
|
}
|
|
53
57
|
} else {
|
|
54
|
-
// Default: use system default
|
|
55
58
|
statusBarStyle = .default
|
|
56
59
|
backgroundColor = nil
|
|
57
60
|
}
|
|
58
61
|
|
|
59
|
-
// Set the status bar style
|
|
60
|
-
|
|
62
|
+
// Set the status bar style via swizzled preferredStatusBarStyle
|
|
63
|
+
CapacitorStatusBar.swizzleStatusBarStyleIfNeeded()
|
|
64
|
+
CapacitorStatusBar.currentStatusBarStyle = statusBarStyle
|
|
65
|
+
rootVC.setNeedsStatusBarAppearanceUpdate()
|
|
61
66
|
|
|
62
67
|
// Store the background color for later restoration
|
|
63
68
|
self.currentBackgroundColor = backgroundColor
|
|
@@ -66,7 +71,6 @@ import Capacitor
|
|
|
66
71
|
if self.isOverlayMode {
|
|
67
72
|
print("CapacitorStatusBar: setStyle - overlay mode active, skipping background color")
|
|
68
73
|
} else {
|
|
69
|
-
// Create or update the status bar background view
|
|
70
74
|
self.updateStatusBarBackgroundView(in: window,
|
|
71
75
|
height: statusBarManager.statusBarFrame.height,
|
|
72
76
|
color: backgroundColor)
|
|
@@ -76,78 +80,78 @@ import Capacitor
|
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
82
|
|
|
79
|
-
@objc public func show(animated: Bool) {
|
|
83
|
+
@objc public func show(animated: Bool, completion: (() -> Void)? = nil) {
|
|
80
84
|
DispatchQueue.main.async {
|
|
81
|
-
|
|
82
|
-
// This plugin requires UIViewControllerBasedStatusBarAppearance to be set to NO
|
|
83
|
-
// in the app's Info.plist for programmatic show/hide to work.
|
|
85
|
+
defer { completion?() }
|
|
84
86
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
|
88
|
+
let window = windowScene.windows.first,
|
|
89
|
+
let rootVC = window.rootViewController else { return }
|
|
90
|
+
|
|
91
|
+
if let statusBarManager = windowScene.statusBarManager {
|
|
88
92
|
print("CapacitorStatusBar: show() - Current hidden state: \(statusBarManager.isStatusBarHidden)")
|
|
89
93
|
}
|
|
90
94
|
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
// Show status bar via swizzled prefersStatusBarHidden
|
|
96
|
+
CapacitorStatusBar.swizzleStatusBarVisibilityIfNeeded()
|
|
97
|
+
CapacitorStatusBar.currentStatusBarHidden = false
|
|
98
|
+
rootVC.setNeedsStatusBarAppearanceUpdate()
|
|
94
99
|
|
|
95
100
|
// Restore the background view color when showing (unless overlay mode is active)
|
|
96
101
|
if !self.isOverlayMode {
|
|
97
102
|
self.restoreStatusBarBackgroundColor()
|
|
98
103
|
}
|
|
99
104
|
|
|
100
|
-
|
|
101
|
-
|
|
105
|
+
self.updateWebViewLayout()
|
|
106
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
|
107
|
+
self.updateWebViewLayout()
|
|
108
|
+
}
|
|
102
109
|
}
|
|
103
110
|
}
|
|
104
111
|
|
|
105
|
-
@objc public func hide(animation: String) {
|
|
112
|
+
@objc public func hide(animation: String, completion: (() -> Void)? = nil) {
|
|
106
113
|
DispatchQueue.main.async {
|
|
114
|
+
defer { completion?() }
|
|
115
|
+
|
|
107
116
|
let animationType = animation.lowercased()
|
|
108
117
|
|
|
109
|
-
// Log current status bar state via status bar manager
|
|
110
118
|
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
|
111
119
|
let statusBarManager = windowScene.statusBarManager {
|
|
112
120
|
print("CapacitorStatusBar: hide() - animation=\(animationType), Current hidden state: \(statusBarManager.isStatusBarHidden)")
|
|
113
121
|
}
|
|
114
122
|
|
|
115
123
|
if animationType == "fade" {
|
|
116
|
-
// Fade mode: Make background transparent without
|
|
124
|
+
// Fade mode: Make background transparent without hiding status bar
|
|
117
125
|
print("CapacitorStatusBar: hide() - fade mode: making background transparent")
|
|
118
126
|
self.makeStatusBarBackgroundTransparent()
|
|
119
|
-
self.hideNavigationBar(animation: "fade")
|
|
120
|
-
} else if animationType == "slide" {
|
|
121
|
-
// Slide mode: Hide the status bar completely (current behavior)
|
|
122
|
-
print("CapacitorStatusBar: hide() - slide mode: hiding bars completely")
|
|
123
|
-
// Note: Status bar visibility is controlled through view controllers in modern iOS.
|
|
124
|
-
// This plugin requires UIViewControllerBasedStatusBarAppearance to be set to NO
|
|
125
|
-
// in the app's Info.plist for programmatic show/hide to work.
|
|
126
|
-
self.setStatusBarVisibility(hidden: true, animated: true)
|
|
127
|
-
// Also make the background view transparent when hiding
|
|
128
|
-
self.makeStatusBarBackgroundTransparent()
|
|
129
|
-
self.hideNavigationBar(animation: "slide")
|
|
130
127
|
} else {
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
// Slide mode (default): Hide the status bar completely
|
|
129
|
+
if animationType != "slide" {
|
|
130
|
+
print("CapacitorStatusBar: hide() - unknown animation '\(animationType)', defaulting to slide")
|
|
131
|
+
} else {
|
|
132
|
+
print("CapacitorStatusBar: hide() - slide mode: hiding status bar")
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
|
136
|
+
let window = windowScene.windows.first,
|
|
137
|
+
let rootVC = window.rootViewController else { return }
|
|
138
|
+
|
|
139
|
+
CapacitorStatusBar.swizzleStatusBarVisibilityIfNeeded()
|
|
140
|
+
CapacitorStatusBar.currentStatusBarHidden = true
|
|
141
|
+
rootVC.setNeedsStatusBarAppearanceUpdate()
|
|
142
|
+
|
|
133
143
|
self.makeStatusBarBackgroundTransparent()
|
|
134
|
-
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
self.updateWebViewLayout()
|
|
147
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
|
148
|
+
self.updateWebViewLayout()
|
|
135
149
|
}
|
|
136
150
|
}
|
|
137
151
|
}
|
|
138
152
|
|
|
139
153
|
// MARK: - Private Methods
|
|
140
154
|
|
|
141
|
-
/// Sets the status bar visibility.
|
|
142
|
-
/// - Parameters:
|
|
143
|
-
/// - hidden: Whether the status bar should be hidden
|
|
144
|
-
/// - animated: Whether the change should be animated
|
|
145
|
-
private func setStatusBarVisibility(hidden: Bool, animated: Bool) {
|
|
146
|
-
// Use KVC to set status bar state without triggering deprecation warnings
|
|
147
|
-
// This approach is necessary when UIViewControllerBasedStatusBarAppearance is NO
|
|
148
|
-
UIApplication.shared.setValue(hidden, forKey: "statusBarHidden")
|
|
149
|
-
}
|
|
150
|
-
|
|
151
155
|
/// Updates or creates the status bar background view with the specified color.
|
|
152
156
|
/// - Parameters:
|
|
153
157
|
/// - window: The window where the status bar view will be added
|
|
@@ -182,8 +186,10 @@ import Capacitor
|
|
|
182
186
|
}
|
|
183
187
|
}
|
|
184
188
|
|
|
185
|
-
@objc public func setOverlaysWebView(value: Bool) {
|
|
189
|
+
@objc public func setOverlaysWebView(value: Bool, completion: (() -> Void)? = nil) {
|
|
186
190
|
DispatchQueue.main.async {
|
|
191
|
+
defer { completion?() }
|
|
192
|
+
|
|
187
193
|
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
|
188
194
|
let window = windowScene.windows.first,
|
|
189
195
|
let statusBarManager = windowScene.statusBarManager else {
|
|
@@ -194,41 +200,25 @@ import Capacitor
|
|
|
194
200
|
self.isOverlayMode = value
|
|
195
201
|
|
|
196
202
|
if value {
|
|
197
|
-
// Overlay mode: make the status bar background transparent so web content shows through
|
|
198
203
|
let statusBarView = window.viewWithTag(CapacitorStatusBar.statusBarViewTag)
|
|
199
204
|
statusBarView?.backgroundColor = .clear
|
|
200
205
|
print("CapacitorStatusBar: setOverlaysWebView(true) - content extends behind status bar")
|
|
201
206
|
} else {
|
|
202
|
-
// Non-overlay mode: restore the status bar background from the current style
|
|
203
207
|
if let color = self.currentBackgroundColor {
|
|
204
208
|
self.updateStatusBarBackgroundView(in: window,
|
|
205
209
|
height: statusBarManager.statusBarFrame.height,
|
|
206
210
|
color: color)
|
|
207
211
|
print("CapacitorStatusBar: setOverlaysWebView(false) - restored background color")
|
|
208
212
|
} else {
|
|
209
|
-
// No style was set; apply default style based on system theme
|
|
210
213
|
self.applyDefaultStyle()
|
|
211
214
|
print("CapacitorStatusBar: setOverlaysWebView(false) - applied default style from config")
|
|
212
215
|
}
|
|
213
216
|
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
@objc public func setBackground(colorHex: String?) {
|
|
218
|
-
DispatchQueue.main.async {
|
|
219
|
-
guard let colorHex = colorHex, let color = self.colorFromHex(colorHex) else {
|
|
220
|
-
print("CapacitorStatusBar: setBackground - Invalid color or nil")
|
|
221
|
-
return
|
|
222
|
-
}
|
|
223
217
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
return
|
|
218
|
+
self.updateWebViewLayout()
|
|
219
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
|
220
|
+
self.updateWebViewLayout()
|
|
228
221
|
}
|
|
229
|
-
|
|
230
|
-
window.backgroundColor = .clear
|
|
231
|
-
print("CapacitorStatusBar: setBackground - Body is always transparent; status/nav bars use overlays/native APIs")
|
|
232
222
|
}
|
|
233
223
|
}
|
|
234
224
|
|
|
@@ -262,8 +252,10 @@ import Capacitor
|
|
|
262
252
|
/// Shared flag read by the swizzled `prefersHomeIndicatorAutoHidden` override.
|
|
263
253
|
static var homeIndicatorHidden = false
|
|
264
254
|
|
|
265
|
-
@objc public func showNavigationBar(animated: Bool) {
|
|
255
|
+
@objc public func showNavigationBar(animated: Bool, completion: (() -> Void)? = nil) {
|
|
266
256
|
DispatchQueue.main.async {
|
|
257
|
+
defer { completion?() }
|
|
258
|
+
|
|
267
259
|
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
|
268
260
|
let window = windowScene.windows.first,
|
|
269
261
|
let rootVC = window.rootViewController else {
|
|
@@ -276,11 +268,17 @@ import Capacitor
|
|
|
276
268
|
rootVC.setNeedsUpdateOfHomeIndicatorAutoHidden()
|
|
277
269
|
|
|
278
270
|
print("CapacitorStatusBar: showNavigationBar - animated=\(animated)")
|
|
271
|
+
self.updateWebViewLayout()
|
|
272
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
|
273
|
+
self.updateWebViewLayout()
|
|
274
|
+
}
|
|
279
275
|
}
|
|
280
276
|
}
|
|
281
277
|
|
|
282
|
-
@objc public func hideNavigationBar(animation: String) {
|
|
278
|
+
@objc public func hideNavigationBar(animation: String, completion: (() -> Void)? = nil) {
|
|
283
279
|
DispatchQueue.main.async {
|
|
280
|
+
defer { completion?() }
|
|
281
|
+
|
|
284
282
|
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
|
285
283
|
let window = windowScene.windows.first,
|
|
286
284
|
let rootVC = window.rootViewController else {
|
|
@@ -294,24 +292,82 @@ import Capacitor
|
|
|
294
292
|
rootVC.setNeedsUpdateOfHomeIndicatorAutoHidden()
|
|
295
293
|
|
|
296
294
|
print("CapacitorStatusBar: hideNavigationBar - animation=\(animationType)")
|
|
295
|
+
self.updateWebViewLayout()
|
|
296
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|
|
297
|
+
self.updateWebViewLayout()
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// MARK: - Swizzling
|
|
303
|
+
|
|
304
|
+
private static var hasSwizzledHomeIndicator = false
|
|
305
|
+
private static var hasSwizzledStatusBarStyle = false
|
|
306
|
+
private static var hasSwizzledStatusBarVisibility = false
|
|
307
|
+
|
|
308
|
+
/// Current status bar style, read by the swizzled `preferredStatusBarStyle` override.
|
|
309
|
+
static var currentStatusBarStyle: UIStatusBarStyle = .default
|
|
310
|
+
|
|
311
|
+
/// Current status bar hidden state, read by the swizzled `prefersStatusBarHidden` override.
|
|
312
|
+
static var currentStatusBarHidden = false
|
|
313
|
+
|
|
314
|
+
/// Swizzle `preferredStatusBarStyle` so we can control status bar appearance
|
|
315
|
+
/// without using private KVC APIs. Requires UIViewControllerBasedStatusBarAppearance = YES (default).
|
|
316
|
+
static func swizzleStatusBarStyleIfNeeded() {
|
|
317
|
+
guard !hasSwizzledStatusBarStyle else { return }
|
|
318
|
+
hasSwizzledStatusBarStyle = true
|
|
319
|
+
|
|
320
|
+
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
|
321
|
+
let window = windowScene.windows.first,
|
|
322
|
+
let rootVC = window.rootViewController else { return }
|
|
323
|
+
|
|
324
|
+
let vcClass: AnyClass = type(of: rootVC)
|
|
325
|
+
let originalSelector = #selector(getter: UIViewController.preferredStatusBarStyle)
|
|
326
|
+
let swizzledSelector = #selector(UIViewController.capsb_preferredStatusBarStyle)
|
|
327
|
+
|
|
328
|
+
guard let originalMethod = class_getInstanceMethod(vcClass, originalSelector),
|
|
329
|
+
let swizzledMethod = class_getInstanceMethod(UIViewController.self, swizzledSelector) else {
|
|
330
|
+
print("CapacitorStatusBar: Failed to swizzle preferredStatusBarStyle")
|
|
331
|
+
return
|
|
297
332
|
}
|
|
333
|
+
|
|
334
|
+
method_exchangeImplementations(originalMethod, swizzledMethod)
|
|
335
|
+
print("CapacitorStatusBar: Swizzled preferredStatusBarStyle on \(vcClass)")
|
|
298
336
|
}
|
|
299
337
|
|
|
300
|
-
|
|
338
|
+
/// Swizzle `prefersStatusBarHidden` so we can control status bar visibility
|
|
339
|
+
/// without using private KVC APIs. Requires UIViewControllerBasedStatusBarAppearance = YES (default).
|
|
340
|
+
static func swizzleStatusBarVisibilityIfNeeded() {
|
|
341
|
+
guard !hasSwizzledStatusBarVisibility else { return }
|
|
342
|
+
hasSwizzledStatusBarVisibility = true
|
|
343
|
+
|
|
344
|
+
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
|
345
|
+
let window = windowScene.windows.first,
|
|
346
|
+
let rootVC = window.rootViewController else { return }
|
|
347
|
+
|
|
348
|
+
let vcClass: AnyClass = type(of: rootVC)
|
|
349
|
+
let originalSelector = #selector(getter: UIViewController.prefersStatusBarHidden)
|
|
350
|
+
let swizzledSelector = #selector(UIViewController.capsb_prefersStatusBarHidden)
|
|
301
351
|
|
|
302
|
-
|
|
352
|
+
guard let originalMethod = class_getInstanceMethod(vcClass, originalSelector),
|
|
353
|
+
let swizzledMethod = class_getInstanceMethod(UIViewController.self, swizzledSelector) else {
|
|
354
|
+
print("CapacitorStatusBar: Failed to swizzle prefersStatusBarHidden")
|
|
355
|
+
return
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
method_exchangeImplementations(originalMethod, swizzledMethod)
|
|
359
|
+
print("CapacitorStatusBar: Swizzled prefersStatusBarHidden on \(vcClass)")
|
|
360
|
+
}
|
|
303
361
|
|
|
304
362
|
/// Swizzle `prefersHomeIndicatorAutoHidden` on the root view controller so we
|
|
305
363
|
/// can control the home indicator visibility from the plugin.
|
|
306
364
|
static func swizzleHomeIndicatorIfNeeded() {
|
|
307
|
-
guard !
|
|
308
|
-
|
|
365
|
+
guard !hasSwizzledHomeIndicator else { return }
|
|
366
|
+
hasSwizzledHomeIndicator = true
|
|
309
367
|
|
|
310
368
|
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
|
311
369
|
let window = windowScene.windows.first,
|
|
312
|
-
let rootVC = window.rootViewController else {
|
|
313
|
-
return
|
|
314
|
-
}
|
|
370
|
+
let rootVC = window.rootViewController else { return }
|
|
315
371
|
|
|
316
372
|
let vcClass: AnyClass = type(of: rootVC)
|
|
317
373
|
let originalSelector = #selector(getter: UIViewController.prefersHomeIndicatorAutoHidden)
|
|
@@ -339,6 +395,37 @@ import Capacitor
|
|
|
339
395
|
print("CapacitorStatusBar: Made background transparent")
|
|
340
396
|
}
|
|
341
397
|
|
|
398
|
+
/// Updates WebView frame to respect overlay mode behavior.
|
|
399
|
+
/// - overlay mode true: content extends edge-to-edge (no reserved top/bottom)
|
|
400
|
+
/// - overlay mode false: content is inset away from status/home-indicator areas
|
|
401
|
+
private func updateWebViewLayout() {
|
|
402
|
+
guard let webView = self.webView else {
|
|
403
|
+
print("CapacitorStatusBar: updateWebViewLayout - WebView unavailable")
|
|
404
|
+
return
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
guard let window = webView.window
|
|
408
|
+
?? (UIApplication.shared.connectedScenes.first as? UIWindowScene)?
|
|
409
|
+
.windows.first(where: { $0.isKeyWindow })
|
|
410
|
+
?? (UIApplication.shared.connectedScenes.first as? UIWindowScene)?.windows.first else {
|
|
411
|
+
print("CapacitorStatusBar: updateWebViewLayout - Unable to resolve window")
|
|
412
|
+
return
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
let safeAreaInsets = window.safeAreaInsets
|
|
416
|
+
let topInset: CGFloat = isOverlayMode ? 0 : sanitizedInsetValue(safeAreaInsets.top)
|
|
417
|
+
let bottomInset: CGFloat = isOverlayMode ? 0 : sanitizedInsetValue(safeAreaInsets.bottom)
|
|
418
|
+
|
|
419
|
+
var frame = window.bounds
|
|
420
|
+
frame.origin.y = topInset
|
|
421
|
+
frame.size.height = max(0, frame.size.height - topInset - bottomInset)
|
|
422
|
+
|
|
423
|
+
if webView.frame != frame {
|
|
424
|
+
webView.frame = frame
|
|
425
|
+
print("CapacitorStatusBar: updateWebViewLayout - topInset=\(topInset), bottomInset=\(bottomInset), frame=\(frame)")
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
342
429
|
/// Restores the status bar background view to its original color
|
|
343
430
|
private func restoreStatusBarBackgroundColor() {
|
|
344
431
|
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
|
|
@@ -415,6 +502,14 @@ import Capacitor
|
|
|
415
502
|
// MARK: - UIViewController extension for home indicator swizzling
|
|
416
503
|
|
|
417
504
|
extension UIViewController {
|
|
505
|
+
@objc func capsb_preferredStatusBarStyle() -> UIStatusBarStyle {
|
|
506
|
+
return CapacitorStatusBar.currentStatusBarStyle
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
@objc func capsb_prefersStatusBarHidden() -> Bool {
|
|
510
|
+
return CapacitorStatusBar.currentStatusBarHidden
|
|
511
|
+
}
|
|
512
|
+
|
|
418
513
|
@objc func capsb_prefersHomeIndicatorAutoHidden() -> Bool {
|
|
419
514
|
return CapacitorStatusBar.homeIndicatorHidden
|
|
420
515
|
}
|
|
@@ -14,7 +14,6 @@ public class CapacitorStatusBarPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
14
14
|
CAPPluginMethod(name: "show", returnType: CAPPluginReturnPromise),
|
|
15
15
|
CAPPluginMethod(name: "hide", returnType: CAPPluginReturnPromise),
|
|
16
16
|
CAPPluginMethod(name: "setOverlaysWebView", returnType: CAPPluginReturnPromise),
|
|
17
|
-
CAPPluginMethod(name: "setBackground", returnType: CAPPluginReturnPromise),
|
|
18
17
|
CAPPluginMethod(name: "showNavigationBar", returnType: CAPPluginReturnPromise),
|
|
19
18
|
CAPPluginMethod(name: "hideNavigationBar", returnType: CAPPluginReturnPromise),
|
|
20
19
|
CAPPluginMethod(name: "getSafeAreaInsets", returnType: CAPPluginReturnPromise)
|
|
@@ -23,6 +22,7 @@ public class CapacitorStatusBarPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
23
22
|
|
|
24
23
|
override public func load() {
|
|
25
24
|
super.load()
|
|
25
|
+
implementation.setWebView(bridge?.webView)
|
|
26
26
|
// Apply default style based on system theme on plugin load
|
|
27
27
|
implementation.applyDefaultStyle()
|
|
28
28
|
}
|
|
@@ -33,18 +33,21 @@ public class CapacitorStatusBarPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
33
33
|
return
|
|
34
34
|
}
|
|
35
35
|
let color = call.getString("color")
|
|
36
|
-
implementation.setStyle(style: style, colorHex: color)
|
|
37
|
-
|
|
36
|
+
implementation.setStyle(style: style, colorHex: color) {
|
|
37
|
+
call.resolve()
|
|
38
|
+
}
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
@objc func show(_ call: CAPPluginCall) {
|
|
41
|
-
implementation.show(animated: true)
|
|
42
|
-
|
|
42
|
+
implementation.show(animated: true) {
|
|
43
|
+
call.resolve()
|
|
44
|
+
}
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
@objc func hide(_ call: CAPPluginCall) {
|
|
46
|
-
implementation.hide(animation: "slide")
|
|
47
|
-
|
|
48
|
+
implementation.hide(animation: "slide") {
|
|
49
|
+
call.resolve()
|
|
50
|
+
}
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
@objc func setOverlaysWebView(_ call: CAPPluginCall) {
|
|
@@ -52,27 +55,21 @@ public class CapacitorStatusBarPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
52
55
|
call.reject("value is required")
|
|
53
56
|
return
|
|
54
57
|
}
|
|
55
|
-
implementation.setOverlaysWebView(value: value)
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
@objc func setBackground(_ call: CAPPluginCall) {
|
|
60
|
-
guard let color = call.getString("color") else {
|
|
61
|
-
call.reject("color is required")
|
|
62
|
-
return
|
|
58
|
+
implementation.setOverlaysWebView(value: value) {
|
|
59
|
+
call.resolve()
|
|
63
60
|
}
|
|
64
|
-
implementation.setBackground(colorHex: color)
|
|
65
|
-
call.resolve()
|
|
66
61
|
}
|
|
67
62
|
|
|
68
63
|
@objc func showNavigationBar(_ call: CAPPluginCall) {
|
|
69
|
-
implementation.showNavigationBar(animated: true)
|
|
70
|
-
|
|
64
|
+
implementation.showNavigationBar(animated: true) {
|
|
65
|
+
call.resolve()
|
|
66
|
+
}
|
|
71
67
|
}
|
|
72
68
|
|
|
73
69
|
@objc func hideNavigationBar(_ call: CAPPluginCall) {
|
|
74
|
-
implementation.hideNavigationBar(animation: "slide")
|
|
75
|
-
|
|
70
|
+
implementation.hideNavigationBar(animation: "slide") {
|
|
71
|
+
call.resolve()
|
|
72
|
+
}
|
|
76
73
|
}
|
|
77
74
|
|
|
78
75
|
@objc func getSafeAreaInsets(_ call: CAPPluginCall) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "capacitor-plugin-status-bar",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.15",
|
|
4
4
|
"description": "Capacitor plugin for managing the status bar style, visibility, and color on iOS and Android. Control overlay modes, background colors, and appearance for native mobile applications.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|