Add Sunrise widget and update the icons

This commit is contained in:
Hariharan Mudaliar 2025-12-24 00:12:45 +05:30
commit eddca8b4dd
No known key found for this signature in database
GPG key ID: 025583EB0BE5640E
5 changed files with 138 additions and 9 deletions

View file

@ -12,6 +12,13 @@ struct LockScreenWeatherWidget: View {
private let inlinePrimaryFont = Font.system(size: 22, weight: .semibold, design: .rounded)
private let inlineSecondaryFont = Font.system(size: 13, weight: .medium, design: .rounded)
private let secondaryLabelColor = Color.white.opacity(0.7)
private static let sunriseFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .none
formatter.timeStyle = .short
formatter.locale = .current
return formatter
}()
private var isInline: Bool { snapshot.widgetStyle == .inline }
private var stackAlignment: VerticalAlignment { isInline ? .firstTextBaseline : .top }
@ -62,12 +69,21 @@ struct LockScreenWeatherWidget: View {
weatherSegment
if snapshot.showsSunrise, let sunriseText = sunriseTimeText {
sunriseSegment(text: sunriseText)
}
if shouldShowLocation {
locationSegment
}
}
}
private var sunriseTimeText: String? {
guard let sunrise = snapshot.sunCycle?.sunrise else { return nil }
return Self.sunriseFormatter.string(from: sunrise)
}
@ViewBuilder
private var weatherSegment: some View {
switch snapshot.widgetStyle {
@ -346,6 +362,20 @@ struct LockScreenWeatherWidget: View {
.layoutPriority(0.7)
}
private func sunriseSegment(text: String) -> some View {
HStack(alignment: .firstTextBaseline, spacing: 4) {
Image(systemName: "sunrise.fill")
.font(.system(size: 20, weight: .semibold))
.symbolRenderingMode(.hierarchical)
Text(text)
.font(inlinePrimaryFont)
.lineLimit(1)
.minimumScaleFactor(0.85)
}
.layoutPriority(0.8)
.accessibilityLabel("Sunrise at \(text)")
}
private var shouldShowLocation: Bool {
snapshot.showsLocation && (snapshot.locationName?.isEmpty == false)
}

View file

@ -2974,6 +2974,7 @@ struct LockScreenSettings: View {
@Default(.lockScreenWeatherShowsCharging) private var lockScreenWeatherShowsCharging
@Default(.lockScreenWeatherShowsBatteryGauge) private var lockScreenWeatherShowsBatteryGauge
@Default(.lockScreenWeatherShowsAQI) private var lockScreenWeatherShowsAQI
@Default(.lockScreenWeatherShowsSunrise) private var lockScreenWeatherShowsSunrise
@Default(.lockScreenWeatherAQIScale) private var lockScreenWeatherAQIScale
private func highlightID(_ title: String) -> String {
@ -3089,6 +3090,10 @@ struct LockScreenSettings: View {
.settingsHighlight(id: highlightID("Show charging percentage"))
}
Defaults.Toggle("Show sunrise time", key: .lockScreenWeatherShowsSunrise)
.disabled(lockScreenWeatherWidgetStyle != .inline)
.settingsHighlight(id: highlightID("Show sunrise time"))
Defaults.Toggle("Show battery indicator", key: .lockScreenWeatherShowsBatteryGauge)
.settingsHighlight(id: highlightID("Show battery indicator"))