Commit 1d9efe87 by Demid Merzlyakov

IOS-72: refactor small widget to extract views shared with bigger widgets.

parent 4de104bf
......@@ -27,7 +27,7 @@
CD18728B2624763000AFEDAA /* MapLegendView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD18728A2624763000AFEDAA /* MapLegendView.swift */; };
CD1B713B2660F95000916E71 /* WidgetKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD1B713A2660F95000916E71 /* WidgetKit.framework */; };
CD1B713D2660F95000916E71 /* SwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD1B713C2660F95000916E71 /* SwiftUI.framework */; };
CD1B71402660F95000916E71 /* OneWeatherWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1B713F2660F95000916E71 /* OneWeatherWidget.swift */; };
CD1B71402660F95000916E71 /* SmallTemperatureWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1B713F2660F95000916E71 /* SmallTemperatureWidget.swift */; };
CD1B71422660F95300916E71 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CD1B71412660F95300916E71 /* Assets.xcassets */; };
CD1B71462660F95300916E71 /* OneWeatherWidgetExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = CD1B71392660F95000916E71 /* OneWeatherWidgetExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
CD1DDD30260218AE00AC62B2 /* DaysControlView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD1DDD2F260218AE00AC62B2 /* DaysControlView.swift */; };
......@@ -63,7 +63,7 @@
CD39F2F525DE9571009FE398 /* ArrowButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD39F2F425DE9571009FE398 /* ArrowButton.swift */; };
CD3F6E6925FA59D4002DB99B /* ForecastDetailPeriodButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3F6E6825FA59D4002DB99B /* ForecastDetailPeriodButton.swift */; };
CD3F6E6C25FA5A90002DB99B /* PeriodButtonProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD3F6E6B25FA5A90002DB99B /* PeriodButtonProtocol.swift */; };
CD415D9D2668FDB400177515 /* SmallWidgetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD415D9C2668FDB400177515 /* SmallWidgetView.swift */; };
CD415D9D2668FDB400177515 /* SmallTemperatureWidgetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD415D9C2668FDB400177515 /* SmallTemperatureWidgetView.swift */; };
CD415DA32668FFF300177515 /* WeatherProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD415DA22668FFF300177515 /* WeatherProvider.swift */; };
CD4742D0261200500061AC95 /* TodayAlertCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD4742CF261200500061AC95 /* TodayAlertCell.swift */; };
CD483A942664D64A00CA53AB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CD1237CB255D5C5C00C98139 /* Assets.xcassets */; };
......@@ -74,7 +74,7 @@
CD483A9E2664E08200CA53AB /* SF-Pro-Display-Regular.otf in Resources */ = {isa = PBXBuildFile; fileRef = CD483A9C2664E08200CA53AB /* SF-Pro-Display-Regular.otf */; };
CD5293D8266908DB009547C8 /* WidgetPlaceholderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD5293D7266908DB009547C8 /* WidgetPlaceholderView.swift */; };
CD5293DA2669094E009547C8 /* WeatherEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD5293D92669094E009547C8 /* WeatherEntry.swift */; };
CD5293DF266A235F009547C8 /* SmallWidgetViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD5293DE266A235F009547C8 /* SmallWidgetViewModel.swift */; };
CD5293DF266A235F009547C8 /* ForecastWidgetViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD5293DE266A235F009547C8 /* ForecastWidgetViewModel.swift */; };
CD5293E0266A30EE009547C8 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = CDD75F0F25DE68B10099ACDB /* Localizable.strings */; };
CD5293E1266A4258009547C8 /* AppFont.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDD0F1E72572429E00CF5017 /* AppFont.swift */; };
CD5293E3266A4340009547C8 /* UIFont+Font.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD5293E2266A4340009547C8 /* UIFont+Font.swift */; };
......@@ -196,10 +196,14 @@
CE14445F2638B6CF008E2162 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE14445E2638B6CF008E2162 /* StoreKit.framework */; };
CE30E37F2668FBE3006DF5CD /* OneWeatherAnalytics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE30E37E2668FBE3006DF5CD /* OneWeatherAnalytics.framework */; };
CE30E3802668FBE3006DF5CD /* OneWeatherAnalytics.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = CE30E37E2668FBE3006DF5CD /* OneWeatherAnalytics.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
CE367270268DB88100D8B69E /* HighLowTemperatureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE36726F268DB88100D8B69E /* HighLowTemperatureView.swift */; };
CE367272268DCD6000D8B69E /* CityNameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE367271268DCD6000D8B69E /* CityNameView.swift */; };
CE376C98261EE484000B1159 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE376C97261EE484000B1159 /* LaunchScreen.storyboard */; };
CE578FE525FB415F00E8B85D /* CityCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE578FE225FB415F00E8B85D /* CityCell.swift */; };
CE578FE625FB415F00E8B85D /* LocationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE578FE325FB415F00E8B85D /* LocationViewController.swift */; };
CE578FE725FB415F00E8B85D /* LocationsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE578FE425FB415F00E8B85D /* LocationsViewModel.swift */; };
CE5F0CBA268A02C100B99572 /* OneWeatherMediumTemperatureWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE5F0CB9268A02C100B99572 /* OneWeatherMediumTemperatureWidget.swift */; };
CE5F0CBC268A031800B99572 /* OneWeatherWidgetsBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE5F0CBB268A031800B99572 /* OneWeatherWidgetsBundle.swift */; };
CE6BE4942634170800626822 /* USStateCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE6BE4932634170800626822 /* USStateCode.swift */; };
CE6F5F0C263C8B3D00973137 /* SmartTextProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE6F5F0B263C8B3C00973137 /* SmartTextProvider.swift */; };
CE7298C9267A34F3002745D0 /* BlendFIPSSource.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEEF40FF265E47FF00425D8F /* BlendFIPSSource.framework */; };
......@@ -336,7 +340,7 @@
CD1B71392660F95000916E71 /* OneWeatherWidgetExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = OneWeatherWidgetExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
CD1B713A2660F95000916E71 /* WidgetKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WidgetKit.framework; path = System/Library/Frameworks/WidgetKit.framework; sourceTree = SDKROOT; };
CD1B713C2660F95000916E71 /* SwiftUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftUI.framework; path = System/Library/Frameworks/SwiftUI.framework; sourceTree = SDKROOT; };
CD1B713F2660F95000916E71 /* OneWeatherWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OneWeatherWidget.swift; sourceTree = "<group>"; };
CD1B713F2660F95000916E71 /* SmallTemperatureWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmallTemperatureWidget.swift; sourceTree = "<group>"; };
CD1B71412660F95300916E71 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
CD1B71432660F95300916E71 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
CD1DDD2F260218AE00AC62B2 /* DaysControlView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DaysControlView.swift; sourceTree = "<group>"; };
......@@ -370,14 +374,14 @@
CD39F2F425DE9571009FE398 /* ArrowButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrowButton.swift; sourceTree = "<group>"; };
CD3F6E6825FA59D4002DB99B /* ForecastDetailPeriodButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForecastDetailPeriodButton.swift; sourceTree = "<group>"; };
CD3F6E6B25FA5A90002DB99B /* PeriodButtonProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PeriodButtonProtocol.swift; sourceTree = "<group>"; };
CD415D9C2668FDB400177515 /* SmallWidgetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmallWidgetView.swift; sourceTree = "<group>"; };
CD415D9C2668FDB400177515 /* SmallTemperatureWidgetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmallTemperatureWidgetView.swift; sourceTree = "<group>"; };
CD415DA22668FFF300177515 /* WeatherProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherProvider.swift; sourceTree = "<group>"; };
CD4742CF261200500061AC95 /* TodayAlertCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodayAlertCell.swift; sourceTree = "<group>"; };
CD483A992664DF7300CA53AB /* SF-Pro-Display-Light.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "SF-Pro-Display-Light.otf"; sourceTree = "<group>"; };
CD483A9C2664E08200CA53AB /* SF-Pro-Display-Regular.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "SF-Pro-Display-Regular.otf"; sourceTree = "<group>"; };
CD5293D7266908DB009547C8 /* WidgetPlaceholderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetPlaceholderView.swift; sourceTree = "<group>"; };
CD5293D92669094E009547C8 /* WeatherEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherEntry.swift; sourceTree = "<group>"; };
CD5293DE266A235F009547C8 /* SmallWidgetViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmallWidgetViewModel.swift; sourceTree = "<group>"; };
CD5293DE266A235F009547C8 /* ForecastWidgetViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForecastWidgetViewModel.swift; sourceTree = "<group>"; };
CD5293E2266A4340009547C8 /* UIFont+Font.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIFont+Font.swift"; sourceTree = "<group>"; };
CD5293EB266A5BC2009547C8 /* UIColor+Color.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Color.swift"; sourceTree = "<group>"; };
CD55E0BA2615EE2400CC4DC7 /* PollutantView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PollutantView.swift; sourceTree = "<group>"; };
......@@ -492,10 +496,13 @@
CE14445E2638B6CF008E2162 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; };
CE30E37E2668FBE3006DF5CD /* OneWeatherAnalytics.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = OneWeatherAnalytics.framework; sourceTree = BUILT_PRODUCTS_DIR; };
CE35F60E2681FA27008D507E /* OneWeatherWidgetExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = OneWeatherWidgetExtension.entitlements; sourceTree = "<group>"; };
CE36726F268DB88100D8B69E /* HighLowTemperatureView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HighLowTemperatureView.swift; sourceTree = "<group>"; };
CE367271268DCD6000D8B69E /* CityNameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CityNameView.swift; sourceTree = "<group>"; };
CE376C97261EE484000B1159 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
CE578FE225FB415F00E8B85D /* CityCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CityCell.swift; sourceTree = "<group>"; };
CE578FE325FB415F00E8B85D /* LocationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationViewController.swift; sourceTree = "<group>"; };
CE578FE425FB415F00E8B85D /* LocationsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationsViewModel.swift; sourceTree = "<group>"; };
CE5F0CBB268A031800B99572 /* OneWeatherWidgetsBundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OneWeatherWidgetsBundle.swift; sourceTree = "<group>"; };
CE6BE4932634170800626822 /* USStateCode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = USStateCode.swift; sourceTree = "<group>"; };
CE6F5F0B263C8B3C00973137 /* SmartTextProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartTextProvider.swift; sourceTree = "<group>"; };
CE81A421266E289E00800EFF /* NativeAdView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeAdView.swift; sourceTree = "<group>"; };
......@@ -684,9 +691,10 @@
CD5293DD266A2345009547C8 /* ViewModels */,
CD5293DC266909B0009547C8 /* Data */,
CD5293DB2669099B009547C8 /* UI */,
CD1B713F2660F95000916E71 /* OneWeatherWidget.swift */,
CE5F0CBD268A058700B99572 /* Widgets */,
CD1B71412660F95300916E71 /* Assets.xcassets */,
CD1B71432660F95300916E71 /* Info.plist */,
CE5F0CBB268A031800B99572 /* OneWeatherWidgetsBundle.swift */,
);
path = OneWeatherWidget;
sourceTree = "<group>";
......@@ -772,9 +780,9 @@
CD5293DB2669099B009547C8 /* UI */ = {
isa = PBXGroup;
children = (
CE5F0CBE268A059700B99572 /* WidgetViews */,
CD5293E2266A4340009547C8 /* UIFont+Font.swift */,
CD5293D7266908DB009547C8 /* WidgetPlaceholderView.swift */,
CD415D9C2668FDB400177515 /* SmallWidgetView.swift */,
CD5293EB266A5BC2009547C8 /* UIColor+Color.swift */,
CDEF70F5266E25E400BA40D6 /* VectorImage.swift */,
);
......@@ -793,7 +801,7 @@
CD5293DD266A2345009547C8 /* ViewModels */ = {
isa = PBXGroup;
children = (
CD5293DE266A235F009547C8 /* SmallWidgetViewModel.swift */,
CD5293DE266A235F009547C8 /* ForecastWidgetViewModel.swift */,
);
path = ViewModels;
sourceTree = "<group>";
......@@ -1237,6 +1245,24 @@
path = Cells;
sourceTree = "<group>";
};
CE5F0CBD268A058700B99572 /* Widgets */ = {
isa = PBXGroup;
children = (
CD1B713F2660F95000916E71 /* SmallTemperatureWidget.swift */,
);
path = Widgets;
sourceTree = "<group>";
};
CE5F0CBE268A059700B99572 /* WidgetViews */ = {
isa = PBXGroup;
children = (
CD415D9C2668FDB400177515 /* SmallTemperatureWidgetView.swift */,
CE36726F268DB88100D8B69E /* HighLowTemperatureView.swift */,
CE367271268DCD6000D8B69E /* CityNameView.swift */,
);
path = WidgetViews;
sourceTree = "<group>";
};
CE81A420266E288C00800EFF /* NativeAdViews */ = {
isa = PBXGroup;
children = (
......@@ -1807,15 +1833,18 @@
buildActionMask = 2147483647;
files = (
CD5293E1266A4258009547C8 /* AppFont.swift in Sources */,
CD5293DF266A235F009547C8 /* SmallWidgetViewModel.swift in Sources */,
CD5293DF266A235F009547C8 /* ForecastWidgetViewModel.swift in Sources */,
CD5293D8266908DB009547C8 /* WidgetPlaceholderView.swift in Sources */,
CD5293E3266A4340009547C8 /* UIFont+Font.swift in Sources */,
CD5293EA266A564E009547C8 /* ThemeProtocol.swift in Sources */,
CD1B71402660F95000916E71 /* OneWeatherWidget.swift in Sources */,
CE367270268DB88100D8B69E /* HighLowTemperatureView.swift in Sources */,
CD1B71402660F95000916E71 /* SmallTemperatureWidget.swift in Sources */,
CD5293E8266A561F009547C8 /* DefaultTheme.swift in Sources */,
CD5293E7266A560C009547C8 /* ThemeManager.swift in Sources */,
CD415D9D2668FDB400177515 /* SmallWidgetView.swift in Sources */,
CD415D9D2668FDB400177515 /* SmallTemperatureWidgetView.swift in Sources */,
CE5F0CBC268A031800B99572 /* OneWeatherWidgetsBundle.swift in Sources */,
CD5293EC266A5BC2009547C8 /* UIColor+Color.swift in Sources */,
CE367272268DCD6000D8B69E /* CityNameView.swift in Sources */,
CD415DA32668FFF300177515 /* WeatherProvider.swift in Sources */,
CD5293DA2669094E009547C8 /* WeatherEntry.swift in Sources */,
CDEF70F6266E25E400BA40D6 /* VectorImage.swift in Sources */,
......
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"colors" : [
{
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "1.000",
"blue" : "0.741",
"green" : "0.673",
"red" : "0.656"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
//
// OneWeatherWidgetsBundle.swift
// OneWeatherWidgetExtension
//
// Created by Demid Merzlyakov on 28.06.2021.
//
import SwiftUI
@main
struct OneWeatherWidgets: WidgetBundle {
var body: some Widget {
SmallTemperatureWidget()
}
}
......@@ -14,10 +14,10 @@ struct WidgetPlaceholderView: View {
var body: some View {
switch family {
case .systemSmall:
SmallWidgetView(widgetViewModel: .init(location: WeatherEntry.defaultLocation))
SmallTemperatureWidgetView(widgetViewModel: .init(location: WeatherEntry.defaultLocation))
.redacted(reason: .placeholder)
default:
SmallWidgetView(widgetViewModel: .init(location: WeatherEntry.defaultLocation))
SmallTemperatureWidgetView(widgetViewModel: .init(location: WeatherEntry.defaultLocation))
.redacted(reason: .placeholder)
}
}
......
//
// CityNameView.swift
// OneWeatherWidgetExtension
//
// Created by Demid Merzlyakov on 01.07.2021.
//
import SwiftUI
struct CityNameView: View {
@State public var cityName: String
@State public var isDeviceLocation: Bool
var body: some View {
HStack(spacing: 4) {
Text(cityName)
.multilineTextAlignment(.leading)
.font(AppFont.SFProDisplay.regular(size: 12).font)
.foregroundColor(ThemeManager.currentTheme.graphTintColor.color)
Image("location_arrow")
.resizable()
.renderingMode(.template)
.frame(width: 8, height: 8, alignment: .center)
.aspectRatio(contentMode: .fit)
.foregroundColor(Color(ThemeManager.currentTheme.graphTintColor.cgColor))
.opacity(isDeviceLocation ? 1 : 0)
}
}
}
//
// HighLowTemperatureView.swift
// OneWeatherWidgetExtension
//
// Created by Demid Merzlyakov on 01.07.2021.
//
import SwiftUI
struct HighLowTemperatureView: View {
@State public var highTemperature: String
@State public var lowTemperature: String
var body: some View {
HStack {
Text("H \(highTemperature)")
.font(AppFont.SFProDisplay.regular(size: 12).font)
.foregroundColor(Color("HighLowTemperatureColor"))
Text("L \(lowTemperature)")
.font(AppFont.SFProDisplay.regular(size: 12).font)
.foregroundColor(Color("HighLowTemperatureColor"))
}
}
}
......@@ -9,9 +9,9 @@ import SwiftUI
import WidgetKit
import OneWeatherCore
struct SmallWidgetView: View {
struct SmallTemperatureWidgetView: View {
//Public
let widgetViewModel: SmallWidgetViewModel
let widgetViewModel: ForecastWidgetViewModel
//Private
@Environment(\.colorScheme) private var colorScheme
......@@ -29,17 +29,8 @@ struct SmallWidgetView: View {
GeometryReader { geometry in
VStack {
HStack(spacing: 4) {
Text(widgetViewModel.cityName)
.multilineTextAlignment(.leading)
.font(AppFont.SFProDisplay.regular(size: 12).font)
.foregroundColor(ThemeManager.currentTheme.graphTintColor.color)
Image("location_arrow")
.resizable()
.renderingMode(.template)
.frame(width: 8, height: 8, alignment: .center)
.aspectRatio(contentMode: .fit)
.foregroundColor(Color(ThemeManager.currentTheme.graphTintColor.cgColor))
.opacity(widgetViewModel.isDeviceLocation ? 1 : 0)
CityNameView(cityName: widgetViewModel.cityName,
isDeviceLocation: widgetViewModel.isDeviceLocation)
Spacer()
}
.padding(.top, 12)
......@@ -51,12 +42,12 @@ struct SmallWidgetView: View {
.font(AppFont.SFProDisplay.light(size: 32).font)
.padding(.leading, 10)
.padding(.trailing, 4)
.textColor(for: interfaceStyle)
.textColor(for: colorScheme)
Text(widgetViewModel.weatherType)
.font(AppFont.SFProDisplay.regular(size: 12).font)
.padding(.leading, 10)
.padding(.trailing, 4)
.textColor(for: interfaceStyle)
.textColor(for: colorScheme)
Spacer(minLength: 0)
}
.frame(height: 70)
......@@ -66,20 +57,15 @@ struct SmallWidgetView: View {
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 70, height: 70, alignment: .center)
.shadow(for: interfaceStyle)
.shadow(for: colorScheme)
.padding(.trailing, 4)
}
HStack {
Text("H \(widgetViewModel.highTemperature)")
.font(AppFont.SFProDisplay.regular(size: 12).font)
.footerTextColor(for: interfaceStyle)
Text("L \(widgetViewModel.lowTemperature)")
.font(AppFont.SFProDisplay.regular(size: 12).font)
.footerTextColor(for: interfaceStyle)
HighLowTemperatureView(highTemperature: widgetViewModel.highTemperature,
lowTemperature: widgetViewModel.lowTemperature)
Spacer()
}
// .padding(.top, 20)
.padding(.bottom, 21)
.padding(.leading, 10)
}
......@@ -89,38 +75,33 @@ struct SmallWidgetView: View {
//MARK: Appearence extension
private extension View {
func shadow(for interfaceStyle:AppInterfaceStyle) -> some View {
switch interfaceStyle {
func shadow(for colorScheme: ColorScheme) -> some View {
switch colorScheme {
case .light:
return self.shadow(color: Color.black.opacity(0.5), radius: 16, x: 2, y: 0)
case .dark:
return self.shadow(color: Color.white.opacity(0.24), radius: 16, x: 2, y: 0)
@unknown default:
return self.shadow(color: Color.black.opacity(0.5), radius: 16, x: 2, y: 0)
}
}
func textColor(for interfaceStyle:AppInterfaceStyle) -> some View {
switch interfaceStyle {
func textColor(for colorScheme: ColorScheme) -> some View {
switch colorScheme {
case .light:
return self.foregroundColor(ThemeManager.currentTheme.secondaryTextColor.color)
case .dark:
return self.foregroundColor(ThemeManager.currentTheme.primaryTextColor.color)
}
}
func footerTextColor(for interfaceStyle:AppInterfaceStyle) -> some View {
switch interfaceStyle {
case .light:
return self.foregroundColor(UIColor(hex: 0xA6ACbe).color)
case .dark:
return self.foregroundColor(UIColor(hex: 0xA9BAC5).color)
@unknown default:
return self.foregroundColor(ThemeManager.currentTheme.secondaryTextColor.color)
}
}
}
struct SmallWidget_Preview: PreviewProvider {
struct SmallTemperatureWidgetView_Preview: PreviewProvider {
static var previews: some View {
SmallWidgetView(widgetViewModel: .init(location: WeatherEntry.defaultLocation))
SmallTemperatureWidgetView(widgetViewModel: .init(location: WeatherEntry.defaultLocation))
.previewContext(WidgetPreviewContext(family: .systemSmall))
}
}
......@@ -8,7 +8,7 @@
import SwiftUI
import OneWeatherCore
struct SmallWidgetViewModel {
struct ForecastWidgetViewModel {
let cityName: String
let temperature: String
let weatherType: String
......@@ -17,7 +17,7 @@ struct SmallWidgetViewModel {
let lowTemperature: String
let isDeviceLocation: Bool
init(location:Location) {
init(location: Location) {
self.cityName = location.cityName ?? "--"
self.temperature = "\(location.today?.temp?.shortString ?? "--")"
self.weatherType = location.today?.type.localized(isDay: location.today?.isDay ?? true) ?? "--"
......
......@@ -8,14 +8,13 @@
import WidgetKit
import SwiftUI
@main
struct OneWeatherWidget: Widget {
private let kind = "com.onelouder.oneweather.widget"
struct SmallTemperatureWidget: Widget {
private let kind = "com.onelouder.oneweather.widget.small"
var body: some WidgetConfiguration {
// We currently display selectedLocation, so it's not really configurable, but we'll probably need to switch to an IntentConfiguration at some point.
StaticConfiguration(kind: kind, provider: WeatherProvider()) { weatherEntry in
SmallWidgetView(widgetViewModel: .init(location: weatherEntry.location))
SmallTemperatureWidgetView(widgetViewModel: .init(location: weatherEntry.location))
}
.supportedFamilies([.systemSmall])
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment