Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ struct WeatherOverviewView: View {
var showSecondaryFields: Bool = false
let noDataText: LocalizableString
var lastUpdatedText: String?
var dataViewBackground: ColorEnum = .top
var secondaryFieldsViewBackground: ColorEnum = .layer1
var buttonTitle: String?
var isButtonEnabled: Bool = true
var buttonAction: (() -> Void)?
Expand Down Expand Up @@ -41,14 +43,14 @@ struct WeatherOverviewView: View {
noDataView
}
}
.WXMCardStyle(backgroundColor: Color(colorEnum: .top),
.WXMCardStyle(backgroundColor: Color(colorEnum: dataViewBackground),
insideHorizontalPadding: CGFloat(.defaultSidePadding),
insideVerticalPadding: mainViewVerticalPadding,
cornerRadius: CGFloat(.cardCornerRadius))

if showSecondaryFields {
secondaryFieldsView
.WXMCardStyle(backgroundColor: Color(colorEnum: .layer1),
.WXMCardStyle(backgroundColor: Color(colorEnum: secondaryFieldsViewBackground),
insideHorizontalPadding: CGFloat(.defaultSidePadding),
insideVerticalPadding: 0.0,
cornerRadius: CGFloat(.cardCornerRadius))
Expand Down
68 changes: 46 additions & 22 deletions station-widget/Views/StationWidgetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,37 @@ import WidgetKit
struct StationWidgetView: View {
let entry: StationTimelineEntry
@Environment(\.widgetFamily) var family: WidgetFamily

var body: some View {
Group {
switch entry.timelineCase {
case .station(let device, let followState):
stationView(device: device, followState: followState, uiMode: entry.weatherOverViewMode)
case .loggedOut:
LoggedOutView()
case .empty:
emptyView
case .error(let info):
errorView(info: info)
case .selectStation:
selectStationView
}
}
.widgetURL(entry.timelineCase.widgetUrl)
}
@Environment(\.widgetRenderingMode) var renderingMode
private var isTinted: Bool {
renderingMode == .accented
}

var body: some View {
Group {
switch entry.timelineCase {
case .station(let device, let followState):
stationView(device: device, followState: followState, uiMode: entry.weatherOverViewMode)
.modify { view in
if isTinted {
view
.luminanceToAlpha()
.widgetAccentable()
} else {
view
}
}
case .loggedOut:
LoggedOutView()
case .empty:
emptyView
case .error(let info):
errorView(info: info)
case .selectStation:
selectStationView
}
}
.widgetURL(entry.timelineCase.widgetUrl)
}
}

private extension StationWidgetView {
Expand Down Expand Up @@ -111,7 +124,10 @@ private extension StationWidgetView {

Spacer()

WeatherOverviewView(mode: .minimal, weather: device.weather, noDataText: followState.weatherNoDataText)
WeatherOverviewView(mode: .minimal,
weather: device.weather,
noDataText: followState.weatherNoDataText,
dataViewBackground: isTinted ? .noColor : .top)
}
.padding(.vertical, CGFloat(.smallSidePadding))
.widgetBackground {
Expand All @@ -127,7 +143,10 @@ private extension StationWidgetView {
titleView(device: device, followState: followState)
.padding(.horizontal, CGFloat(.mediumSidePadding))

WeatherOverviewView(mode: uiMode, weather: device.weather, noDataText: followState.weatherNoDataText)
WeatherOverviewView(mode: uiMode,
weather: device.weather,
noDataText: followState.weatherNoDataText,
dataViewBackground: isTinted ? .noColor : .top)

Spacer(minLength: 0.0)
}
Expand All @@ -143,7 +162,12 @@ private extension StationWidgetView {
titleView(device: device, followState: followState)
.padding(.horizontal, CGFloat(.mediumSidePadding))

WeatherOverviewView(mode: .large, weather: device.weather, showSecondaryFields: true, noDataText: followState.weatherNoDataText)
WeatherOverviewView(mode: .large,
weather: device.weather,
showSecondaryFields: true,
noDataText: followState.weatherNoDataText,
dataViewBackground: isTinted ? .noColor : .top,
secondaryFieldsViewBackground: isTinted ? .noColor : .layer1)
.cornerRadius(CGFloat(.cardCornerRadius))

}
Expand Down Expand Up @@ -290,7 +314,7 @@ struct StationWidgetView_Preview: PreviewProvider {
errorInfo: nil, // .init(title: "This is an error title",
// description: LocalizableString.Error.noInternetAccess.localized),
isLoggedIn: true))
.previewContext(WidgetPreviewContext(family: .systemMedium))
.previewContext(WidgetPreviewContext(family: .systemLarge))
}
.containerBackground(for: .widget) {
Color(colorEnum: .top)
Expand Down