forked from olcxjas-softworks/LarpixClient
forgot to push
This commit is contained in:
parent
6ff37cb3be
commit
4942043ae3
28 changed files with 2458 additions and 0 deletions
168
node_modules/@capacitor/status-bar/ios/Sources/StatusBarPlugin/StatusBar.swift
generated
vendored
Normal file
168
node_modules/@capacitor/status-bar/ios/Sources/StatusBarPlugin/StatusBar.swift
generated
vendored
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
import Foundation
|
||||
import Capacitor
|
||||
|
||||
public class StatusBar {
|
||||
|
||||
private var bridge: CAPBridgeProtocol
|
||||
private var isOverlayingWebview = true
|
||||
private var backgroundColor = UIColor.black
|
||||
private var backgroundView: UIView?
|
||||
private var observers: [NSObjectProtocol] = []
|
||||
|
||||
init(bridge: CAPBridgeProtocol, config: StatusBarConfig) {
|
||||
self.bridge = bridge
|
||||
setupObservers(with: config)
|
||||
}
|
||||
|
||||
deinit {
|
||||
observers.forEach { NotificationCenter.default.removeObserver($0) }
|
||||
}
|
||||
|
||||
private func setupObservers(with config: StatusBarConfig) {
|
||||
observers.append(NotificationCenter.default.addObserver(forName: .capacitorViewDidAppear, object: .none, queue: .none) { [weak self] _ in
|
||||
self?.handleViewDidAppear(config: config)
|
||||
})
|
||||
observers.append(NotificationCenter.default.addObserver(forName: .capacitorStatusBarTapped, object: .none, queue: .none) { [weak self] _ in
|
||||
self?.bridge.triggerJSEvent(eventName: "statusTap", target: "window")
|
||||
})
|
||||
observers.append(NotificationCenter.default.addObserver(forName: .capacitorViewWillTransition, object: .none, queue: .none) { [weak self] _ in
|
||||
self?.handleViewWillTransition()
|
||||
})
|
||||
}
|
||||
|
||||
private func handleViewDidAppear(config: StatusBarConfig) {
|
||||
setStyle(config.style)
|
||||
setBackgroundColor(config.backgroundColor)
|
||||
setOverlaysWebView(config.overlaysWebView)
|
||||
}
|
||||
|
||||
private func handleViewWillTransition() {
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in
|
||||
self?.resizeStatusBarBackgroundView()
|
||||
self?.resizeWebView()
|
||||
}
|
||||
}
|
||||
|
||||
func setStyle(_ style: UIStatusBarStyle) {
|
||||
bridge.statusBarStyle = style
|
||||
}
|
||||
|
||||
func setBackgroundColor(_ color: UIColor) {
|
||||
backgroundColor = color
|
||||
backgroundView?.backgroundColor = color
|
||||
}
|
||||
|
||||
func setAnimation(_ animation: String) {
|
||||
if animation == "SLIDE" {
|
||||
bridge.statusBarAnimation = .slide
|
||||
} else if animation == "NONE" {
|
||||
bridge.statusBarAnimation = .none
|
||||
} else {
|
||||
bridge.statusBarAnimation = .fade
|
||||
}
|
||||
}
|
||||
|
||||
func hide(animation: String) {
|
||||
setAnimation(animation)
|
||||
if bridge.statusBarVisible {
|
||||
bridge.statusBarVisible = false
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in
|
||||
self?.resizeWebView()
|
||||
self?.backgroundView?.removeFromSuperview()
|
||||
self?.backgroundView?.isHidden = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func show(animation: String) {
|
||||
setAnimation(animation)
|
||||
if !bridge.statusBarVisible {
|
||||
bridge.statusBarVisible = true
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [self] in
|
||||
resizeWebView()
|
||||
if !isOverlayingWebview {
|
||||
resizeStatusBarBackgroundView()
|
||||
bridge.webView?.superview?.addSubview(backgroundView!)
|
||||
}
|
||||
backgroundView?.isHidden = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getInfo() -> StatusBarInfo {
|
||||
let style: String
|
||||
switch bridge.statusBarStyle {
|
||||
case .default:
|
||||
style = "DEFAULT"
|
||||
case .lightContent:
|
||||
style = "DARK"
|
||||
case .darkContent:
|
||||
style = "LIGHT"
|
||||
@unknown default:
|
||||
style = "DEFAULT"
|
||||
}
|
||||
|
||||
return StatusBarInfo(
|
||||
overlays: isOverlayingWebview,
|
||||
visible: bridge.statusBarVisible,
|
||||
style: style,
|
||||
color: UIColor.capacitor.hex(fromColor: backgroundColor),
|
||||
height: getStatusBarFrame().size.height
|
||||
)
|
||||
}
|
||||
|
||||
func setOverlaysWebView(_ overlay: Bool) {
|
||||
if overlay == isOverlayingWebview { return }
|
||||
isOverlayingWebview = overlay
|
||||
if overlay {
|
||||
backgroundView?.removeFromSuperview()
|
||||
} else {
|
||||
initializeBackgroundViewIfNeeded()
|
||||
bridge.webView?.superview?.addSubview(backgroundView!)
|
||||
}
|
||||
resizeWebView()
|
||||
}
|
||||
|
||||
private func resizeWebView() {
|
||||
let bounds: CGRect? = bridge.viewController?.view.window?.windowScene?.keyWindow?.bounds
|
||||
|
||||
guard
|
||||
let webView = bridge.webView,
|
||||
let bounds = bounds
|
||||
else { return }
|
||||
bridge.viewController?.view.frame = bounds
|
||||
webView.frame = bounds
|
||||
let statusBarHeight = getStatusBarFrame().size.height
|
||||
var webViewFrame = webView.frame
|
||||
|
||||
if isOverlayingWebview {
|
||||
let safeAreaTop = webView.safeAreaInsets.top
|
||||
if statusBarHeight >= safeAreaTop && safeAreaTop > 0 {
|
||||
webViewFrame.origin.y = safeAreaTop == 40 ? 20 : statusBarHeight - safeAreaTop
|
||||
} else {
|
||||
webViewFrame.origin.y = 0
|
||||
}
|
||||
} else {
|
||||
webViewFrame.origin.y = statusBarHeight
|
||||
}
|
||||
webViewFrame.size.height -= webViewFrame.origin.y
|
||||
webView.frame = webViewFrame
|
||||
}
|
||||
|
||||
private func resizeStatusBarBackgroundView() {
|
||||
backgroundView?.frame = getStatusBarFrame()
|
||||
}
|
||||
|
||||
private func getStatusBarFrame() -> CGRect {
|
||||
return bridge.viewController?.view.window?.windowScene?.statusBarManager?.statusBarFrame ?? .zero
|
||||
}
|
||||
|
||||
private func initializeBackgroundViewIfNeeded() {
|
||||
if backgroundView == nil {
|
||||
backgroundView = UIView(frame: getStatusBarFrame())
|
||||
backgroundView!.backgroundColor = backgroundColor
|
||||
backgroundView!.autoresizingMask = [.flexibleWidth, .flexibleBottomMargin]
|
||||
backgroundView!.isHidden = !bridge.statusBarVisible
|
||||
}
|
||||
}
|
||||
}
|
||||
7
node_modules/@capacitor/status-bar/ios/Sources/StatusBarPlugin/StatusBarConfig.swift
generated
vendored
Normal file
7
node_modules/@capacitor/status-bar/ios/Sources/StatusBarPlugin/StatusBarConfig.swift
generated
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import UIKit
|
||||
|
||||
public struct StatusBarConfig {
|
||||
var overlaysWebView = true
|
||||
var backgroundColor: UIColor = .black
|
||||
var style: UIStatusBarStyle = .default
|
||||
}
|
||||
9
node_modules/@capacitor/status-bar/ios/Sources/StatusBarPlugin/StatusBarInfo.swift
generated
vendored
Normal file
9
node_modules/@capacitor/status-bar/ios/Sources/StatusBarPlugin/StatusBarInfo.swift
generated
vendored
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import Foundation
|
||||
|
||||
public struct StatusBarInfo {
|
||||
public var overlays: Bool?
|
||||
public var visible: Bool?
|
||||
public var style: String?
|
||||
public var color: String?
|
||||
public var height: CGFloat?
|
||||
}
|
||||
134
node_modules/@capacitor/status-bar/ios/Sources/StatusBarPlugin/StatusBarPlugin.swift
generated
vendored
Normal file
134
node_modules/@capacitor/status-bar/ios/Sources/StatusBarPlugin/StatusBarPlugin.swift
generated
vendored
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
import Foundation
|
||||
import Capacitor
|
||||
|
||||
/**
|
||||
* StatusBar plugin. Requires "View controller-based status bar appearance" to
|
||||
* be "YES" in Info.plist
|
||||
*/
|
||||
@objc(StatusBarPlugin)
|
||||
public class StatusBarPlugin: CAPPlugin, CAPBridgedPlugin {
|
||||
public let identifier = "StatusBarPlugin"
|
||||
public let jsName = "StatusBar"
|
||||
public let pluginMethods: [CAPPluginMethod] = [
|
||||
CAPPluginMethod(name: "setStyle", returnType: CAPPluginReturnPromise),
|
||||
CAPPluginMethod(name: "setBackgroundColor", returnType: CAPPluginReturnPromise),
|
||||
CAPPluginMethod(name: "show", returnType: CAPPluginReturnPromise),
|
||||
CAPPluginMethod(name: "hide", returnType: CAPPluginReturnPromise),
|
||||
CAPPluginMethod(name: "getInfo", returnType: CAPPluginReturnPromise),
|
||||
CAPPluginMethod(name: "setOverlaysWebView", returnType: CAPPluginReturnPromise)
|
||||
]
|
||||
private var statusBar: StatusBar?
|
||||
private let statusBarVisibilityChanged = "statusBarVisibilityChanged"
|
||||
private let statusBarOverlayChanged = "statusBarOverlayChanged"
|
||||
|
||||
override public func load() {
|
||||
guard let bridge = bridge else { return }
|
||||
statusBar = StatusBar(bridge: bridge, config: statusBarConfig())
|
||||
}
|
||||
|
||||
private func statusBarConfig() -> StatusBarConfig {
|
||||
var config = StatusBarConfig()
|
||||
config.overlaysWebView = getConfig().getBoolean("overlaysWebView", config.overlaysWebView)
|
||||
if let colorConfig = getConfig().getString("backgroundColor"), let color = UIColor.capacitor.color(fromHex: colorConfig) {
|
||||
config.backgroundColor = color
|
||||
}
|
||||
if let configStyle = getConfig().getString("style") {
|
||||
config.style = style(fromString: configStyle)
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
private func style(fromString: String) -> UIStatusBarStyle {
|
||||
switch fromString.lowercased() {
|
||||
case "dark", "lightcontent":
|
||||
return .lightContent
|
||||
case "light", "darkcontent":
|
||||
return .darkContent
|
||||
case "default":
|
||||
return .default
|
||||
default:
|
||||
return .default
|
||||
}
|
||||
}
|
||||
|
||||
@objc func setStyle(_ call: CAPPluginCall) {
|
||||
let options = call.options!
|
||||
if let styleString = options["style"] as? String {
|
||||
statusBar?.setStyle(style(fromString: styleString))
|
||||
}
|
||||
call.resolve([:])
|
||||
}
|
||||
|
||||
@objc func setBackgroundColor(_ call: CAPPluginCall) {
|
||||
guard
|
||||
let hexString = call.options["color"] as? String,
|
||||
let color = UIColor.capacitor.color(fromHex: hexString)
|
||||
else { return }
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
self?.statusBar?.setBackgroundColor(color)
|
||||
}
|
||||
call.resolve()
|
||||
}
|
||||
|
||||
@objc func hide(_ call: CAPPluginCall) {
|
||||
let animation = call.getString("animation", "FADE")
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
self?.statusBar?.hide(animation: animation)
|
||||
guard
|
||||
let info = self?.statusBar?.getInfo(),
|
||||
let dict = self?.toDict(info),
|
||||
let event = self?.statusBarVisibilityChanged
|
||||
else { return }
|
||||
self?.notifyListeners(event, data: dict)
|
||||
}
|
||||
call.resolve()
|
||||
}
|
||||
|
||||
@objc func show(_ call: CAPPluginCall) {
|
||||
let animation = call.getString("animation", "FADE")
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
self?.statusBar?.show(animation: animation)
|
||||
guard
|
||||
let info = self?.statusBar?.getInfo(),
|
||||
let dict = self?.toDict(info),
|
||||
let event = self?.statusBarVisibilityChanged
|
||||
else { return }
|
||||
self?.notifyListeners(event, data: dict)
|
||||
}
|
||||
call.resolve()
|
||||
}
|
||||
|
||||
@objc func getInfo(_ call: CAPPluginCall) {
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
guard
|
||||
let info = self?.statusBar?.getInfo(),
|
||||
let dict = self?.toDict(info)
|
||||
else { return }
|
||||
call.resolve(dict)
|
||||
}
|
||||
}
|
||||
|
||||
@objc func setOverlaysWebView(_ call: CAPPluginCall) {
|
||||
guard let overlay = call.options["overlay"] as? Bool else { return }
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
self?.statusBar?.setOverlaysWebView(overlay)
|
||||
guard
|
||||
let info = self?.statusBar?.getInfo(),
|
||||
let dict = self?.toDict(info),
|
||||
let event = self?.statusBarOverlayChanged
|
||||
else { return }
|
||||
self?.notifyListeners(event, data: dict)
|
||||
}
|
||||
call.resolve()
|
||||
}
|
||||
|
||||
private func toDict(_ info: StatusBarInfo) -> [String: Any] {
|
||||
return [
|
||||
"visible": info.visible!,
|
||||
"style": info.style!,
|
||||
"color": info.color!,
|
||||
"overlays": info.overlays!,
|
||||
"height": info.height!
|
||||
]
|
||||
}
|
||||
}
|
||||
40
node_modules/@capacitor/status-bar/ios/Sources/StatusBarPlugin/UIColor.swift
generated
vendored
Normal file
40
node_modules/@capacitor/status-bar/ios/Sources/StatusBarPlugin/UIColor.swift
generated
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import Capacitor
|
||||
|
||||
public extension CapacitorExtensionTypeWrapper where T: UIColor {
|
||||
|
||||
static func hex(fromColor: UIColor) -> String? {
|
||||
var red: CGFloat = 0
|
||||
var green: CGFloat = 0
|
||||
var blue: CGFloat = 0
|
||||
var alpha: CGFloat = 0
|
||||
|
||||
guard fromColor.getRed(&red, green: &green, blue: &blue, alpha: &alpha) else {
|
||||
assertionFailure("Failed to get RGBA components from UIColor")
|
||||
return nil
|
||||
}
|
||||
|
||||
red = max(0, min(1, red))
|
||||
green = max(0, min(1, green))
|
||||
blue = max(0, min(1, blue))
|
||||
alpha = max(0, min(1, alpha))
|
||||
|
||||
if alpha == 1 {
|
||||
// RGB
|
||||
return String(
|
||||
format: "#%02lX%02lX%02lX",
|
||||
Int(round(red * 255)),
|
||||
Int(round(green * 255)),
|
||||
Int(round(blue * 255))
|
||||
)
|
||||
} else {
|
||||
// RGBA
|
||||
return String(
|
||||
format: "#%02lX%02lX%02lX%02lX",
|
||||
Int(round(red * 255)),
|
||||
Int(round(green * 255)),
|
||||
Int(round(blue * 255)),
|
||||
Int(round(alpha * 255))
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
12
node_modules/@capacitor/status-bar/ios/Tests/StatusBarPluginTests/StatusBarPluginTests.swift
generated
vendored
Normal file
12
node_modules/@capacitor/status-bar/ios/Tests/StatusBarPluginTests/StatusBarPluginTests.swift
generated
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import XCTest
|
||||
@testable import StatusBarPlugin
|
||||
|
||||
final class StatusBarPluginTests: XCTestCase {
|
||||
func testExample() throws {
|
||||
// XCTest Documentation
|
||||
// https://developer.apple.com/documentation/xctest
|
||||
|
||||
// Defining Test Cases and Test Methods
|
||||
// https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue