Skip to content

Commit 428eba9

Browse files
committed
Lockscreen Widgets
1 parent f3cf371 commit 428eba9

File tree

5 files changed

+72
-19
lines changed

5 files changed

+72
-19
lines changed

Loop Widget Extension/Components/SystemStatusActionView.swift renamed to Loop Widget Extension/Components/SystemActionLink.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// SystemStatusActionView.swift
2+
// SystemActionLink.swift
33
// Loop Widget Extension
44
//
55
// Created by Cameron Ingham on 6/26/23.
@@ -9,8 +9,8 @@
99
import Foundation
1010
import SwiftUI
1111

12-
struct SystemStatusActionView: View {
13-
enum ActionType: String, CaseIterable {
12+
struct SystemActionLink: View {
13+
enum Destination: String, CaseIterable {
1414
case carbEntry = "carb-entry"
1515
case bolus = "manual-bolus"
1616
case preMeal = "pre-meal-preset"
@@ -21,16 +21,16 @@ struct SystemStatusActionView: View {
2121
}
2222
}
2323

24-
let actionType: ActionType
24+
let destination: Destination
2525
let active: Bool
2626

27-
init(for actionType: ActionType, active: Bool = false) {
28-
self.actionType = actionType
27+
init(to destination: Destination, active: Bool = false) {
28+
self.destination = destination
2929
self.active = active
3030
}
3131

3232
private func foregroundColor(active: Bool) -> Color {
33-
switch actionType {
33+
switch destination {
3434
case .carbEntry:
3535
return Color("fresh")
3636
case .bolus:
@@ -43,7 +43,7 @@ struct SystemStatusActionView: View {
4343
}
4444

4545
private func backgroundColor(active: Bool) -> Color {
46-
switch actionType {
46+
switch destination {
4747
case .carbEntry:
4848
return active ? Color("fresh") : Color("WidgetSecondaryBackground")
4949
case .bolus:
@@ -56,7 +56,7 @@ struct SystemStatusActionView: View {
5656
}
5757

5858
private var icon: Image {
59-
switch actionType {
59+
switch destination {
6060
case .carbEntry:
6161
return Image("carbs")
6262
case .bolus:
@@ -69,7 +69,7 @@ struct SystemStatusActionView: View {
6969
}
7070

7171
var body: some View {
72-
Link(destination: actionType.deeplink) {
72+
Link(destination: destination.deeplink) {
7373
icon
7474
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
7575
.foregroundColor(foregroundColor(active: active))

Loop Widget Extension/LoopWidgets.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ struct LoopWidgets: WidgetBundle {
1414
@WidgetBundleBuilder
1515
var body: some Widget {
1616
SystemStatusWidget()
17+
18+
if #available(iOSApplicationExtension 16.0, *) {
19+
LockscreenAccessoryWidget()
20+
}
1721
}
1822
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// LockscreenAccessoryWidget.swift
3+
// Loop Widget Extension
4+
//
5+
// Created by Cameron Ingham on 6/26/23.
6+
// Copyright © 2023 LoopKit Authors. All rights reserved.
7+
//
8+
9+
import LoopUI
10+
import SwiftUI
11+
import WidgetKit
12+
13+
@available(iOSApplicationExtension 16.0, *)
14+
struct LockscreenAccessoryWidgetEntryView : View {
15+
16+
@Environment(\.widgetFamily) private var widgetFamily
17+
18+
var entry: StatusWidgetTimelineProvider.Entry
19+
20+
var body: some View {
21+
HStack(alignment: .center, spacing: 10) {
22+
if widgetFamily == .accessoryRectangular {
23+
LoopCircleView(entry: entry)
24+
.scaleEffect(0.75)
25+
}
26+
27+
GlucoseView(entry: entry)
28+
}
29+
.widgetBackground()
30+
}
31+
}
32+
33+
@available(iOSApplicationExtension 16.0, *)
34+
struct LockscreenAccessoryWidget: Widget {
35+
let kind: String = "LockscreenAccessoryWidget"
36+
37+
var body: some WidgetConfiguration {
38+
StaticConfiguration(kind: kind, provider: StatusWidgetTimelineProvider()) { entry in
39+
LockscreenAccessoryWidgetEntryView(entry: entry)
40+
}
41+
.configurationDisplayName("Loop Accessory Widget")
42+
.description("See your current blood glucose.")
43+
.supportedFamilies([.accessoryCircular, .accessoryInline, .accessoryRectangular])
44+
}
45+
}

Loop Widget Extension/Widgets/SystemStatusWidget.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,20 @@ struct SystemStatusWidgetEntryView : View {
4040
)
4141
}
4242

43-
if widgetFamily == .systemMedium {
43+
if widgetFamily != .systemSmall {
4444
VStack(alignment: .center, spacing: 5) {
4545
HStack(alignment: .center, spacing: 5) {
46-
SystemStatusActionView(for: .carbEntry)
46+
SystemActionLink(to: .carbEntry)
4747

48-
SystemStatusActionView(for: .bolus)
48+
SystemActionLink(to: .bolus)
4949
}
5050

5151
HStack(alignment: .center, spacing: 5) {
5252
if entry.preMealPresetAllowed {
53-
SystemStatusActionView(for: .preMeal, active: entry.preMealPresetActive)
53+
SystemActionLink(to: .preMeal, active: entry.preMealPresetActive)
5454
}
5555

56-
SystemStatusActionView(for: .customPreset, active: entry.customPresetActive)
56+
SystemActionLink(to: .customPreset, active: entry.customPresetActive)
5757
}
5858
}
5959
.buttonStyle(.plain)

Loop.xcodeproj/project.pbxproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,14 @@
270270
7D70765E1FE06EE3004AC8EA /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 7D7076601FE06EE3004AC8EA /* Localizable.strings */; };
271271
7D7076631FE06EE4004AC8EA /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 7D7076651FE06EE4004AC8EA /* Localizable.strings */; };
272272
7E69CFFC2A16A77E00203CBD /* ResetLoopManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E69CFFB2A16A77E00203CBD /* ResetLoopManager.swift */; };
273+
8463E4012A4A541700098542 /* LockscreenAccessoryWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8463E4002A4A541700098542 /* LockscreenAccessoryWidget.swift */; };
273274
84AA81D32A4A27A3000B658B /* LoopWidgets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AA81D22A4A27A3000B658B /* LoopWidgets.swift */; };
274275
84AA81D62A4A28AF000B658B /* WidgetBackground.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AA81D52A4A28AF000B658B /* WidgetBackground.swift */; };
275276
84AA81D82A4A2910000B658B /* StatusWidgetTimelimeEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AA81D72A4A2910000B658B /* StatusWidgetTimelimeEntry.swift */; };
276277
84AA81DB2A4A2973000B658B /* Date.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AA81DA2A4A2973000B658B /* Date.swift */; };
277278
84AA81DD2A4A2999000B658B /* StatusWidgetTimelineProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AA81DC2A4A2999000B658B /* StatusWidgetTimelineProvider.swift */; };
278279
84AA81E12A4A2D3C000B658B /* ContentMargin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AA81E02A4A2D3C000B658B /* ContentMargin.swift */; };
279-
84AA81E32A4A36FB000B658B /* SystemStatusActionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AA81E22A4A36FB000B658B /* SystemStatusActionView.swift */; };
280+
84AA81E32A4A36FB000B658B /* SystemActionLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AA81E22A4A36FB000B658B /* SystemActionLink.swift */; };
280281
84AA81E52A4A3981000B658B /* DeeplinkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AA81E42A4A3981000B658B /* DeeplinkManager.swift */; };
281282
84AA81E72A4A4DEF000B658B /* PumpView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84AA81E62A4A4DEF000B658B /* PumpView.swift */; };
282283
891B508524342BE1005DA578 /* CarbAndBolusFlowViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 891B508424342BE1005DA578 /* CarbAndBolusFlowViewModel.swift */; };
@@ -1268,13 +1269,14 @@
12681269
7DD382791F8DBFC60071272B /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Interface.strings; sourceTree = "<group>"; };
12691270
7E69CFFB2A16A77E00203CBD /* ResetLoopManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResetLoopManager.swift; sourceTree = "<group>"; };
12701271
80F864E52433BF5D0026EC26 /* fi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fi; path = fi.lproj/InfoPlist.strings; sourceTree = "<group>"; };
1272+
8463E4002A4A541700098542 /* LockscreenAccessoryWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LockscreenAccessoryWidget.swift; sourceTree = "<group>"; };
12711273
84AA81D22A4A27A3000B658B /* LoopWidgets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoopWidgets.swift; sourceTree = "<group>"; };
12721274
84AA81D52A4A28AF000B658B /* WidgetBackground.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetBackground.swift; sourceTree = "<group>"; };
12731275
84AA81D72A4A2910000B658B /* StatusWidgetTimelimeEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusWidgetTimelimeEntry.swift; sourceTree = "<group>"; };
12741276
84AA81DA2A4A2973000B658B /* Date.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Date.swift; sourceTree = "<group>"; };
12751277
84AA81DC2A4A2999000B658B /* StatusWidgetTimelineProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusWidgetTimelineProvider.swift; sourceTree = "<group>"; };
12761278
84AA81E02A4A2D3C000B658B /* ContentMargin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentMargin.swift; sourceTree = "<group>"; };
1277-
84AA81E22A4A36FB000B658B /* SystemStatusActionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemStatusActionView.swift; sourceTree = "<group>"; };
1279+
84AA81E22A4A36FB000B658B /* SystemActionLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemActionLink.swift; sourceTree = "<group>"; };
12781280
84AA81E42A4A3981000B658B /* DeeplinkManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeeplinkManager.swift; sourceTree = "<group>"; };
12791281
84AA81E62A4A4DEF000B658B /* PumpView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PumpView.swift; sourceTree = "<group>"; };
12801282
891B508424342BE1005DA578 /* CarbAndBolusFlowViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarbAndBolusFlowViewModel.swift; sourceTree = "<group>"; };
@@ -2693,7 +2695,7 @@
26932695
14B1736E28AEDBF6006CCD7C /* BasalView.swift */,
26942696
14B1737028AEDBF6006CCD7C /* GlucoseView.swift */,
26952697
14B1737128AEDBF6006CCD7C /* LoopCircleView.swift */,
2696-
84AA81E22A4A36FB000B658B /* SystemStatusActionView.swift */,
2698+
84AA81E22A4A36FB000B658B /* SystemActionLink.swift */,
26972699
84AA81E62A4A4DEF000B658B /* PumpView.swift */,
26982700
);
26992701
path = Components;
@@ -2734,6 +2736,7 @@
27342736
isa = PBXGroup;
27352737
children = (
27362738
14B1736F28AEDBF6006CCD7C /* SystemStatusWidget.swift */,
2739+
8463E4002A4A541700098542 /* LockscreenAccessoryWidget.swift */,
27372740
);
27382741
path = Widgets;
27392742
sourceTree = "<group>";
@@ -3877,8 +3880,9 @@
38773880
14B1737728AEDC6C006CCD7C /* NSBundle.swift in Sources */,
38783881
84AA81D62A4A28AF000B658B /* WidgetBackground.swift in Sources */,
38793882
84AA81D82A4A2910000B658B /* StatusWidgetTimelimeEntry.swift in Sources */,
3883+
8463E4012A4A541700098542 /* LockscreenAccessoryWidget.swift in Sources */,
38803884
84AA81D32A4A27A3000B658B /* LoopWidgets.swift in Sources */,
3881-
84AA81E32A4A36FB000B658B /* SystemStatusActionView.swift in Sources */,
3885+
84AA81E32A4A36FB000B658B /* SystemActionLink.swift in Sources */,
38823886
14B1737828AEDC6C006CCD7C /* NSTimeInterval.swift in Sources */,
38833887
14B1737928AEDC6C006CCD7C /* NSUserDefaults+StatusExtension.swift in Sources */,
38843888
14B1737A28AEDC6C006CCD7C /* NumberFormatter.swift in Sources */,

0 commit comments

Comments
 (0)