Skip to content

Commit 32475b5

Browse files
authored
Fix remaining tinted widgets (#3044)
<!-- Thank you for submitting a Pull Request and helping to improve Home Assistant. Please complete the following sections to help the processing and review of your changes. Please do not delete anything from this template. --> ## Summary <!-- Provide a brief summary of the changes you have made and most importantly what they aim to achieve --> ## Screenshots <!-- If this is a user-facing change not in the frontend, please include screenshots in light and dark mode. --> ![CleanShot 2024-09-24 at 10 47 59@2x](https://github.com/user-attachments/assets/b4f137d6-a2cd-4d58-9419-b6fa300aa134) ## Link to pull request in Documentation repository <!-- Pull requests that add, change or remove functionality must have a corresponding pull request in the Companion App Documentation repository (https://github.com/home-assistant/companion.home-assistant). Please add the number of this pull request after the "#" --> Documentation: home-assistant/companion.home-assistant# ## Any other notes <!-- If there is any other information of note, like if this Pull Request is part of a bigger change, please include it here. -->
1 parent 4acaf55 commit 32475b5

File tree

5 files changed

+69
-25
lines changed

5 files changed

+69
-25
lines changed

HomeAssistant.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@
548548
420FE84E2B556CE500878E06 /* CarPlayEntitiesListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 420FE84D2B556CE500878E06 /* CarPlayEntitiesListViewModel.swift */; };
549549
420FE8502B556F7500878E06 /* CarPlayEntitiesListTemplate+Build.swift in Sources */ = {isa = PBXBuildFile; fileRef = 420FE84F2B556F7500878E06 /* CarPlayEntitiesListTemplate+Build.swift */; };
550550
421326A82C0FC81800C7D059 /* View+ConditionalModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 421B1C1B2BD65BFA001ED18C /* View+ConditionalModifier.swift */; };
551+
421960702CA2AE1600F7134E /* WidgetAssistViewTintedWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4219606F2CA2AE1600F7134E /* WidgetAssistViewTintedWrapper.swift */; };
551552
421B1C162BD65246001ED18C /* WidgetsSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 421B1C152BD65246001ED18C /* WidgetsSettingsView.swift */; };
552553
421B1C182BD6524E001ED18C /* WidgetsSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 421B1C172BD6524E001ED18C /* WidgetsSettingsViewModel.swift */; };
553554
421B1C1A2BD65255001ED18C /* WidgetsSettingsView+build.swift in Sources */ = {isa = PBXBuildFile; fileRef = 421B1C192BD65255001ED18C /* WidgetsSettingsView+build.swift */; };
@@ -1778,6 +1779,7 @@
17781779
420FE84A2B556BB100878E06 /* CarPlayActionsTemplate+Build.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CarPlayActionsTemplate+Build.swift"; sourceTree = "<group>"; };
17791780
420FE84D2B556CE500878E06 /* CarPlayEntitiesListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarPlayEntitiesListViewModel.swift; sourceTree = "<group>"; };
17801781
420FE84F2B556F7500878E06 /* CarPlayEntitiesListTemplate+Build.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CarPlayEntitiesListTemplate+Build.swift"; sourceTree = "<group>"; };
1782+
4219606F2CA2AE1600F7134E /* WidgetAssistViewTintedWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetAssistViewTintedWrapper.swift; sourceTree = "<group>"; };
17811783
421B1C152BD65246001ED18C /* WidgetsSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetsSettingsView.swift; sourceTree = "<group>"; };
17821784
421B1C172BD6524E001ED18C /* WidgetsSettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetsSettingsViewModel.swift; sourceTree = "<group>"; };
17831785
421B1C192BD65255001ED18C /* WidgetsSettingsView+build.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WidgetsSettingsView+build.swift"; sourceTree = "<group>"; };
@@ -3982,6 +3984,7 @@
39823984
42F958972BB4681E00497981 /* WidgetAssist.swift */,
39833985
42F9589A2BB468F400497981 /* WidgetAssistProvider.swift */,
39843986
42F9589D2BB4705E00497981 /* WidgetAssistView.swift */,
3987+
4219606F2CA2AE1600F7134E /* WidgetAssistViewTintedWrapper.swift */,
39853988
);
39863989
path = Assist;
39873990
sourceTree = "<group>";
@@ -6431,6 +6434,7 @@
64316434
403AE9092C2E220200D48147 /* WidgetGauge.swift in Sources */,
64326435
42D3E4BA2C5D30CB00444BE6 /* WidgetScriptsAppIntent.swift in Sources */,
64336436
4289DDB12C85D629003591C2 /* ControlScenesValueProvider.swift in Sources */,
6437+
421960702CA2AE1600F7134E /* WidgetAssistViewTintedWrapper.swift in Sources */,
64346438
42F9589F2BB4707F00497981 /* WidgetAssistView.swift in Sources */,
64356439
403AE9122C2E2BFC00D48147 /* WidgetGaugeAppIntentTimelineProvider.swift in Sources */,
64366440
42F9589C2BB4691D00497981 /* WidgetAssistProvider.swift in Sources */,

Sources/Extensions/Widgets/Assist/WidgetAssist.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ struct WidgetAssist: Widget {
1010
intent: AssistInAppIntent.self,
1111
provider: WidgetAssistProvider(),
1212
content: { entry in
13-
WidgetAssistView(entry: entry)
14-
.widgetBackground(Color.clear)
13+
if #available(iOS 18.0, *) {
14+
WidgetAssistViewTintedWrapper(entry: entry)
15+
.widgetBackground(Color.clear)
16+
} else {
17+
WidgetAssistView(entry: entry, tinted: false)
18+
.widgetBackground(Color.clear)
19+
}
1520
}
1621
)
1722
.contentMarginsDisabledIfAvailable()

Sources/Extensions/Widgets/Assist/WidgetAssistView.swift

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import SwiftUI
33

44
struct WidgetAssistView: View {
55
@Environment(\.widgetFamily) private var widgetFamily
6-
let entry: WidgetAssistEntry
6+
private let entry: WidgetAssistEntry
7+
private let tinted: Bool
78

89
private var subtitle: String {
910
// Even though server is not visible, show ".unknownConfiguration"
@@ -15,8 +16,9 @@ struct WidgetAssistView: View {
1516
return entry.pipeline?.displayString ?? L10n.Widgets.Assist.unknownConfiguration
1617
}
1718

18-
init(entry: WidgetAssistEntry) {
19+
init(entry: WidgetAssistEntry, tinted: Bool) {
1920
self.entry = entry
21+
self.tinted = tinted
2022
}
2123

2224
var body: some View {
@@ -40,29 +42,38 @@ struct WidgetAssistView: View {
4042
private var singleHomeScreenItem: some View {
4143
VStack(spacing: Spaces.two) {
4244
Spacer()
43-
Image(uiImage: MaterialDesignIcons.messageProcessingOutlineIcon.image(
44-
ofSize: .init(width: 56, height: 56),
45-
color: UIColor(asset: Asset.Colors.haPrimary)
46-
))
47-
.foregroundStyle(.ultraThickMaterial)
48-
VStack(spacing: .zero) {
49-
Group {
50-
Text(L10n.Widgets.Assist.actionTitle)
51-
.font(.footnote.bold())
52-
.foregroundColor(Color(uiColor: .label))
53-
Text(subtitle)
54-
.font(.footnote.weight(.light))
55-
.lineLimit(2)
56-
.fixedSize(horizontal: false, vertical: true)
57-
.multilineTextAlignment(.center)
45+
Group {
46+
Image(uiImage: MaterialDesignIcons.messageProcessingOutlineIcon.image(
47+
ofSize: .init(width: 56, height: 56),
48+
color: UIColor(asset: Asset.Colors.haPrimary)
49+
))
50+
.foregroundStyle(.ultraThickMaterial)
51+
VStack(spacing: .zero) {
52+
Group {
53+
Text(L10n.Widgets.Assist.actionTitle)
54+
.font(.footnote.bold())
55+
.foregroundColor(Color(uiColor: .label))
56+
Text(subtitle)
57+
.font(.footnote.weight(.light))
58+
.lineLimit(2)
59+
.fixedSize(horizontal: false, vertical: true)
60+
.multilineTextAlignment(.center)
61+
}
62+
.foregroundColor(.gray)
63+
.frame(maxWidth: .infinity, alignment: .center)
64+
}
65+
}
66+
.modify { view in
67+
if #available(iOS 18, *) {
68+
view.widgetAccentable()
69+
} else {
70+
view
5871
}
59-
.foregroundColor(.gray)
60-
.frame(maxWidth: .infinity, alignment: .center)
6172
}
6273
Spacer()
6374
}
6475
.frame(maxWidth: .infinity, alignment: .leading)
6576
.padding(Spaces.two)
66-
.background(Color(uiColor: .systemBackground))
77+
.background(tinted ? Color.clear : Color(uiColor: .systemBackground))
6778
}
6879
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Foundation
2+
import SwiftUI
3+
4+
@available(iOS 16.0, *)
5+
struct WidgetAssistViewTintedWrapper: View {
6+
@Environment(\.widgetRenderingMode) var widgetRenderingMode
7+
8+
private let entry: WidgetAssistEntry
9+
10+
init(entry: WidgetAssistEntry) {
11+
self.entry = entry
12+
}
13+
14+
var body: some View {
15+
WidgetAssistView(
16+
entry: entry,
17+
tinted: widgetRenderingMode == .accented
18+
)
19+
}
20+
}

Sources/Extensions/Widgets/Common/WidgetBasicContainerView.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ struct WidgetBasicContainerView: View {
2626
.widgetBackground(Color.asset(Asset.Colors.primaryBackground))
2727
}
2828

29-
@available(iOS 17.0, *)
29+
@available(iOS 16.4, *)
3030
private func intent(for model: WidgetBasicViewModel) -> (any AppIntent)? {
3131
switch model.interactionType {
3232
case .widgetURL:
3333
return nil
3434
case let .appIntent(widgetIntentType):
3535
switch widgetIntentType {
3636
case .action:
37-
var intent = PerformAction()
37+
let intent = PerformAction()
3838
intent.action = IntentActionAppEntity(id: model.id, displayString: model.title)
3939
intent.hapticConfirmation = true
4040
return intent
@@ -86,7 +86,11 @@ struct WidgetBasicContainerView: View {
8686
ForEach(column) { model in
8787
if case let .widgetURL(url) = model.interactionType {
8888
Link(destination: url.withWidgetAuthenticity()) {
89-
WidgetBasicView(model: model, sizeStyle: sizeStyle, tinted: false)
89+
if #available(iOS 18.0, *) {
90+
WidgetBasicViewTintedWrapper(model: model, sizeStyle: sizeStyle)
91+
} else {
92+
WidgetBasicView(model: model, sizeStyle: sizeStyle, tinted: false)
93+
}
9094
}
9195
} else {
9296
if #available(iOS 17.0, *), let intent = intent(for: model) {

0 commit comments

Comments
 (0)