Skip to content

Commit

Permalink
Re-introduce content margins to widgets and make some other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
daneden committed Jun 20, 2024
1 parent b0aab5f commit 0964fc0
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 45 deletions.
8 changes: 7 additions & 1 deletion Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1387,9 +1387,15 @@
},
"Remove daylight gain/loss" : {
"localizations" : {
"it" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Remove daylight loss"
}
},
"it" : {
"stringUnit" : {
"state" : "needs_review",
"value" : "Rimuovere il guadagno/perdita della luce diurna"
}
}
Expand Down
17 changes: 8 additions & 9 deletions Solstice/Charts/AnnualDaylightChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ struct AnnualDaylightChart<Location: AnyLocation>: View {
var body: some View {
Chart {
ForEach(monthlySolars, id: \.date) { solar in
let sunrise = solar.safeSunrise
let sunset = solar.safeSunset
let sunrise = solar.safeSunrise.withTimeZoneAdjustment(for: location.timeZone)
let sunset = solar.safeSunset.withTimeZoneAdjustment(for: location.timeZone)

if let astronomicalSunrise = solar.astronomicalSunrise,
let astronomicalSunset = solar.astronomicalSunset {
if let astronomicalSunrise = solar.astronomicalSunrise?.withTimeZoneAdjustment(for: location.timeZone),
let astronomicalSunset = solar.astronomicalSunset?.withTimeZoneAdjustment(for: location.timeZone) {
BarMark(
x: .value("Astronomical Twilight", solar.date, unit: .month),
yStart: .value("Astronomical Sunrise", max(0, solar.startOfDay.distance(to: astronomicalSunrise))),
Expand All @@ -38,8 +38,8 @@ struct AnnualDaylightChart<Location: AnyLocation>: View {
.foregroundStyle(by: .value("Phase", Solar.Phase.astronomical))
}

if let nauticalSunrise = solar.nauticalSunrise,
let nauticalSunset = solar.nauticalSunset {
if let nauticalSunrise = solar.nauticalSunrise?.withTimeZoneAdjustment(for: location.timeZone),
let nauticalSunset = solar.nauticalSunset?.withTimeZoneAdjustment(for: location.timeZone) {
BarMark(
x: .value("Nautical Twilight", solar.date, unit: .month),
yStart: .value("Nautical Sunrise", max(0, solar.startOfDay.distance(to: nauticalSunrise))),
Expand All @@ -48,8 +48,8 @@ struct AnnualDaylightChart<Location: AnyLocation>: View {
.foregroundStyle(by: .value("Phase", Solar.Phase.nautical))
}

if let civilSunrise = solar.civilSunrise,
let civilSunset = solar.civilSunset {
if let civilSunrise = solar.civilSunrise?.withTimeZoneAdjustment(for: location.timeZone),
let civilSunset = solar.civilSunset?.withTimeZoneAdjustment(for: location.timeZone) {
BarMark(
x: .value("Civil Twilight", solar.date, unit: .month),
yStart: .value("Civil Sunrise", max(0, solar.startOfDay.distance(to: civilSunrise))),
Expand Down Expand Up @@ -88,7 +88,6 @@ struct AnnualDaylightChart<Location: AnyLocation>: View {
}
}
}
.environment(\.timeZone, location.timeZone)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Solstice/Charts/DaylightChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ extension DaylightChart {
func scrub(to point: CGPoint, in geo: GeometryProxy, proxy: ChartProxy) {
var start: Double = 0

if #available(iOS 17, macOS 13, watchOS 10, *) {
if #available(iOS 17, macOS 14, watchOS 10, visionOS 1.0, *) {
if let plotFrame = proxy.plotFrame {
start = geo[plotFrame].origin.x
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ fileprivate struct Selection: Codable, Hashable {
}
}

#if os(iOS)
extension NSBundleResourceRequest: @unchecked Sendable {}
#endif

struct EquinoxAndSolsticeInfoView: View {
@State private var selection: Selection = Selection()
#if os(iOS)
Expand Down
4 changes: 2 additions & 2 deletions Solstice/Helper Views/ContentToggle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct ContentToggle<Content: View>: View {
HStack {
content(showToggledContent)
.modify { content in
if #available(iOS 17, macOS 13, watchOS 10, *) {
if #available(iOS 17, macOS 14, watchOS 10, *) {
content.transition(.blurReplace)
} else {
content
Expand All @@ -32,7 +32,7 @@ struct ContentToggle<Content: View>: View {
#Preview {
ContentToggle(showToggledContent: true) { showContent in
if showContent {
Text("Content #1")
Text(verbatim: "Content #1")
.font(.headline)
} else {
Text("Content #2")
Expand Down
10 changes: 4 additions & 6 deletions Solstice/Helpers/CurrentLocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,10 @@ extension CurrentLocation {

let reverseGeocoded = try? await geocoder.reverseGeocodeLocation(location)
if let firstResult = reverseGeocoded?.first {
withAnimation {
placemark = firstResult
title = firstResult.locality
subtitle = firstResult.country
timeZoneIdentifier = firstResult.timeZone?.identifier
}
placemark = firstResult
title = firstResult.locality
subtitle = firstResult.country
timeZoneIdentifier = firstResult.timeZone?.identifier
}
}

Expand Down
29 changes: 19 additions & 10 deletions Solstice/List View/DaylightSummaryRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,31 +78,40 @@ struct DaylightSummaryRow<Location: ObservableLocation>: View {
.symbolVariant(.fill)
}

Text(location.title ?? "Current location")
.modify { content in
if #available(iOS 17, macOS 13, watchOS 10, *) {
content.transition(.blurReplace)
} else {
content
}
Group {
if let title = location.title {
Text(verbatim: title)
.id(location.title)
} else {
Text("Current location")
}
.lineLimit(2)
}
.modify { content in
if #available(iOS 17, macOS 14, watchOS 10, *) {
content.transition(.blurReplace)
} else {
content.transition(.scale)
}
}
.lineLimit(2)
}

if let subtitle,
!subtitle.isEmpty {
Text(subtitle)
.id(subtitle)
.foregroundStyle(.secondary)
.font(.footnote)
.modify { content in
if #available(iOS 17, macOS 13, watchOS 10, *) {
if #available(iOS 17, macOS 14, watchOS 10, *) {
content.transition(.blurReplace)
} else {
content
content.transition(.scale)
}
}
}
}
.animation(.default, value: location.title)

Spacer()

Expand Down
2 changes: 2 additions & 0 deletions Solstice/Settings/NotificationSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ struct NotificationPreview: View {
Text(bodyContent).font(.footnote.leading(.tight))
.fixedSize(horizontal: false, vertical: true)
.lineLimit(4)
.contentTransition(.interpolate)
}

Spacer(minLength: 0)
Expand All @@ -198,6 +199,7 @@ struct NotificationPreview: View {
.padding(.horizontal, 12)
.background(.regularMaterial)
.cornerRadius(12)
.animation(.default, value: bodyContent)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Widget/Countdown Widget/CountdownWidgetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ extension CountdownWidgetView {
}
}

#if !os(watchOS)
#if os(iOS)
#Preview(
"Countdown (System Small)",
as: WidgetFamily.systemSmall,
Expand Down
1 change: 0 additions & 1 deletion Widget/Overview Widget/OverviewWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ struct OverviewWidget: Widget {
.configurationDisplayName("Daylight Today")
.description("See today’s daylight length, how it compares to yesterday, and sunrise/sunset times.")
.supportedFamilies(OverviewWidget.supportedFamilies)
.contentMarginsDisabled()
}
}
4 changes: 1 addition & 3 deletions Widget/Overview Widget/OverviewWidgetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,18 @@ struct OverviewWidgetView: View {
.symbolRenderingMode(.hierarchical)
#endif
}
.padding()
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
}
} else {
WidgetMissingLocationView()
.padding()
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
}
}
.backwardCompatibleContainerBackground(.background)
}
}

#if !os(watchOS)
#if os(iOS)
#Preview(
"Overview (System Small)",
as: WidgetFamily.systemSmall,
Expand Down
1 change: 0 additions & 1 deletion Widget/Solar Chart Widget/SolarChartWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ struct SolarChartWidget: Widget {
.configurationDisplayName("Solar Chart")
.description("Follow the sun's journey throughout the day")
.supportedFamilies(Self.supportedFamilies)
.contentMarginsDisabled()
}
}
6 changes: 1 addition & 5 deletions Widget/Solar Chart Widget/SolarChartWidgetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import WidgetKit
import Solar

struct SolarChartWidgetView: View {
@Environment(\.widgetContentMargins) var contentMargins

var entry: SolsticeWidgetTimelineEntry

var solar: Solar? {
Expand Down Expand Up @@ -50,21 +48,19 @@ struct SolarChartWidgetView: View {
.font(.caption)
.widgetAccentable()
.contentTransition(.numericText())
.padding(contentMargins)

DaylightChart(
solar: solar,
timeZone: location.timeZone,
eventTypes: [],
includesSummaryTitle: false,
markSize: 3,
yScale: -1.0...2.0
yScale: -1.0...1.5
)
.padding(.horizontal, -1)
}
} else {
WidgetMissingLocationView()
.padding(contentMargins)
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
Expand Down
8 changes: 3 additions & 5 deletions Widget/Widget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
// Created by Daniel Eden on 19/02/2023.
//

import WidgetKit
import SwiftUI
import Intents
import Solar
import Foundation
import CoreLocation

struct SolsticeWidgetLocation: AnyLocation {
var title: String?
Expand All @@ -29,7 +27,7 @@ struct SolsticeWidgetLocation: AnyLocation {

static let defaultLocation = SolsticeWidgetLocation(title: "London",
subtitle: "United Kingdom",
timeZoneIdentifier: "GMT",
timeZoneIdentifier: "Europe/London",
latitude: 51.5072,
longitude: -0.1276)
}
Expand Down

0 comments on commit 0964fc0

Please sign in to comment.