Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
0188d681a9
commit
b3615c8117
@ -20,9 +20,11 @@ struct BatteryOverlayView: View {
|
|||||||
// MARK: - Body
|
// MARK: - Body
|
||||||
var body: some View {
|
var body: some View {
|
||||||
let clamped = ColorUtils.clampOpacity(opacity)
|
let clamped = ColorUtils.clampOpacity(opacity)
|
||||||
|
let batteryIcon = getBatteryIcon()
|
||||||
|
let batteryColor = getBatteryColor()
|
||||||
|
|
||||||
Label("\(batteryLevel)%", systemImage: "bolt.circle")
|
Label("\(batteryLevel)%", systemImage: batteryIcon)
|
||||||
.foregroundColor(color)
|
.foregroundColor(batteryColor)
|
||||||
.opacity(clamped)
|
.opacity(clamped)
|
||||||
.font(.callout.weight(.semibold))
|
.font(.callout.weight(.semibold))
|
||||||
.onAppear {
|
.onAppear {
|
||||||
@ -36,6 +38,54 @@ struct BatteryOverlayView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Private Methods
|
// MARK: - Private Methods
|
||||||
|
private func getBatteryIcon() -> String {
|
||||||
|
#if canImport(UIKit)
|
||||||
|
let batteryState = UIDevice.current.batteryState
|
||||||
|
|
||||||
|
// Check if device is charging
|
||||||
|
if batteryState == .charging {
|
||||||
|
return "bolt.circle.fill"
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Return battery icon based on level
|
||||||
|
switch batteryLevel {
|
||||||
|
case 75...100:
|
||||||
|
return "battery.100"
|
||||||
|
case 50..<75:
|
||||||
|
return "battery.75"
|
||||||
|
case 25..<50:
|
||||||
|
return "battery.50"
|
||||||
|
case 10..<25:
|
||||||
|
return "battery.25"
|
||||||
|
default:
|
||||||
|
return "battery.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func getBatteryColor() -> Color {
|
||||||
|
#if canImport(UIKit)
|
||||||
|
let batteryState = UIDevice.current.batteryState
|
||||||
|
|
||||||
|
// Green when charging
|
||||||
|
if batteryState == .charging {
|
||||||
|
return .green
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Color based on battery level
|
||||||
|
switch batteryLevel {
|
||||||
|
case 50...100:
|
||||||
|
return .green
|
||||||
|
case 20..<50:
|
||||||
|
return .yellow
|
||||||
|
case 10..<20:
|
||||||
|
return .orange
|
||||||
|
default:
|
||||||
|
return .red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func enableBatteryMonitoring() {
|
private func enableBatteryMonitoring() {
|
||||||
#if canImport(UIKit)
|
#if canImport(UIKit)
|
||||||
UIDevice.current.isBatteryMonitoringEnabled = true
|
UIDevice.current.isBatteryMonitoringEnabled = true
|
||||||
|
|||||||
@ -18,16 +18,16 @@ struct TopOverlayView: View {
|
|||||||
|
|
||||||
// MARK: - Body
|
// MARK: - Body
|
||||||
var body: some View {
|
var body: some View {
|
||||||
HStack(spacing: UIConstants.Spacing.large) {
|
HStack {
|
||||||
if showBattery {
|
|
||||||
BatteryOverlayView(color: color, opacity: opacity)
|
|
||||||
}
|
|
||||||
|
|
||||||
if showDate {
|
if showDate {
|
||||||
DateOverlayView(color: color, opacity: opacity)
|
DateOverlayView(color: color, opacity: opacity)
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
|
if showBattery {
|
||||||
|
BatteryOverlayView(color: color, opacity: opacity)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.padding(.horizontal, UIConstants.Spacing.medium)
|
.padding(.horizontal, UIConstants.Spacing.medium)
|
||||||
.padding(.vertical, UIConstants.Spacing.small)
|
.padding(.vertical, UIConstants.Spacing.small)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user