Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
1d9efe87
Commit
1d9efe87
authored
Jul 01, 2021
by
Demid Merzlyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IOS-72: refactor small widget to extract views shared with bigger widgets.
parent
4de104bf
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
120 additions
and
46 deletions
+120
-46
1Weather.xcodeproj/project.pbxproj
+0
-0
OneWeatherWidget/Assets.xcassets/Colors/Contents.json
+6
-0
OneWeatherWidget/Assets.xcassets/Colors/HighLowTemperatureColor.colorset/Contents.json
+20
-0
OneWeatherWidget/OneWeatherWidgetsBundle.swift
+15
-0
OneWeatherWidget/UI/WidgetPlaceholderView.swift
+2
-2
OneWeatherWidget/UI/WidgetViews/CityNameView.swift
+29
-0
OneWeatherWidget/UI/WidgetViews/HighLowTemperatureView.swift
+24
-0
OneWeatherWidget/UI/WidgetViews/SmallTemperatureWidgetView.swift
+19
-38
OneWeatherWidget/ViewModels/ForecastWidgetViewModel.swift
+2
-2
OneWeatherWidget/Widgets/SmallTemperatureWidget.swift
+3
-4
No files found.
1Weather.xcodeproj/project.pbxproj
View file @
1d9efe87
This diff is collapsed.
Click to expand it.
OneWeatherWidget/Assets.xcassets/Colors/Contents.json
0 → 100644
View file @
1d9efe87
{
"info"
:
{
"author"
:
"xcode"
,
"version"
:
1
}
}
OneWeatherWidget/Assets.xcassets/Colors/HighLowTemperatureColor.colorset/Contents.json
0 → 100644
View file @
1d9efe87
{
"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
}
}
OneWeatherWidget/OneWeatherWidgetsBundle.swift
0 → 100644
View file @
1d9efe87
//
// OneWeatherWidgetsBundle.swift
// OneWeatherWidgetExtension
//
// Created by Demid Merzlyakov on 28.06.2021.
//
import
SwiftUI
@main
struct
OneWeatherWidgets
:
WidgetBundle
{
var
body
:
some
Widget
{
SmallTemperatureWidget
()
}
}
OneWeatherWidget/UI/WidgetPlaceholderView.swift
View file @
1d9efe87
...
...
@@ -14,10 +14,10 @@ struct WidgetPlaceholderView: View {
var
body
:
some
View
{
switch
family
{
case
.
systemSmall
:
SmallWidgetView
(
widgetViewModel
:
.
init
(
location
:
WeatherEntry
.
defaultLocation
))
Small
Temperature
WidgetView
(
widgetViewModel
:
.
init
(
location
:
WeatherEntry
.
defaultLocation
))
.
redacted
(
reason
:
.
placeholder
)
default
:
SmallWidgetView
(
widgetViewModel
:
.
init
(
location
:
WeatherEntry
.
defaultLocation
))
Small
Temperature
WidgetView
(
widgetViewModel
:
.
init
(
location
:
WeatherEntry
.
defaultLocation
))
.
redacted
(
reason
:
.
placeholder
)
}
}
...
...
OneWeatherWidget/UI/WidgetViews/CityNameView.swift
0 → 100644
View file @
1d9efe87
//
// 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
)
}
}
}
OneWeatherWidget/UI/WidgetViews/HighLowTemperatureView.swift
0 → 100644
View file @
1d9efe87
//
// 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"
))
}
}
}
OneWeatherWidget/UI/
Small
WidgetView.swift
→
OneWeatherWidget/UI/
WidgetViews/SmallTemperature
WidgetView.swift
View file @
1d9efe87
...
...
@@ -9,9 +9,9 @@ import SwiftUI
import
WidgetKit
import
OneWeatherCore
struct
SmallWidgetView
:
View
{
struct
Small
Temperature
WidgetView
:
View
{
//Public
let
widgetViewModel
:
Small
WidgetViewModel
let
widgetViewModel
:
Forecast
WidgetViewModel
//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
:
interfaceStyl
e
)
.
textColor
(
for
:
colorSchem
e
)
Text
(
widgetViewModel
.
weatherType
)
.
font
(
AppFont
.
SFProDisplay
.
regular
(
size
:
12
)
.
font
)
.
padding
(
.
leading
,
10
)
.
padding
(
.
trailing
,
4
)
.
textColor
(
for
:
interfaceStyl
e
)
.
textColor
(
for
:
colorSchem
e
)
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
:
interfaceStyl
e
)
.
shadow
(
for
:
colorSchem
e
)
.
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
:
AppInterfaceStyl
e
)
->
some
View
{
switch
interfaceStyl
e
{
func
shadow
(
for
colorScheme
:
ColorSchem
e
)
->
some
View
{
switch
colorSchem
e
{
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
:
AppInterfaceStyl
e
)
->
some
View
{
switch
interfaceStyl
e
{
func
textColor
(
for
colorScheme
:
ColorSchem
e
)
->
some
View
{
switch
colorSchem
e
{
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
Small
Widget
_Preview
:
PreviewProvider
{
struct
Small
TemperatureWidgetView
_Preview
:
PreviewProvider
{
static
var
previews
:
some
View
{
SmallWidgetView
(
widgetViewModel
:
.
init
(
location
:
WeatherEntry
.
defaultLocation
))
Small
Temperature
WidgetView
(
widgetViewModel
:
.
init
(
location
:
WeatherEntry
.
defaultLocation
))
.
previewContext
(
WidgetPreviewContext
(
family
:
.
systemSmall
))
}
}
OneWeatherWidget/ViewModels/
Small
WidgetViewModel.swift
→
OneWeatherWidget/ViewModels/
Forecast
WidgetViewModel.swift
View file @
1d9efe87
...
...
@@ -8,7 +8,7 @@
import
SwiftUI
import
OneWeatherCore
struct
Small
WidgetViewModel
{
struct
Forecast
WidgetViewModel
{
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
)
??
"--"
...
...
OneWeatherWidget/
OneWeather
Widget.swift
→
OneWeatherWidget/
Widgets/SmallTemperature
Widget.swift
View file @
1d9efe87
...
...
@@ -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
))
Small
Temperature
WidgetView
(
widgetViewModel
:
.
init
(
location
:
weatherEntry
.
location
))
}
.
supportedFamilies
([
.
systemSmall
])
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment