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)
}