Skip to content

Commit

Permalink
Fix remaining tinted widgets (#3044)
Browse files Browse the repository at this point in the history
<!-- 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. -->
  • Loading branch information
bgoncal authored Sep 24, 2024
1 parent 4acaf55 commit 32475b5
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 25 deletions.
4 changes: 4 additions & 0 deletions HomeAssistant.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@
420FE84E2B556CE500878E06 /* CarPlayEntitiesListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 420FE84D2B556CE500878E06 /* CarPlayEntitiesListViewModel.swift */; };
420FE8502B556F7500878E06 /* CarPlayEntitiesListTemplate+Build.swift in Sources */ = {isa = PBXBuildFile; fileRef = 420FE84F2B556F7500878E06 /* CarPlayEntitiesListTemplate+Build.swift */; };
421326A82C0FC81800C7D059 /* View+ConditionalModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 421B1C1B2BD65BFA001ED18C /* View+ConditionalModifier.swift */; };
421960702CA2AE1600F7134E /* WidgetAssistViewTintedWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4219606F2CA2AE1600F7134E /* WidgetAssistViewTintedWrapper.swift */; };
421B1C162BD65246001ED18C /* WidgetsSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 421B1C152BD65246001ED18C /* WidgetsSettingsView.swift */; };
421B1C182BD6524E001ED18C /* WidgetsSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 421B1C172BD6524E001ED18C /* WidgetsSettingsViewModel.swift */; };
421B1C1A2BD65255001ED18C /* WidgetsSettingsView+build.swift in Sources */ = {isa = PBXBuildFile; fileRef = 421B1C192BD65255001ED18C /* WidgetsSettingsView+build.swift */; };
Expand Down Expand Up @@ -1778,6 +1779,7 @@
420FE84A2B556BB100878E06 /* CarPlayActionsTemplate+Build.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CarPlayActionsTemplate+Build.swift"; sourceTree = "<group>"; };
420FE84D2B556CE500878E06 /* CarPlayEntitiesListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CarPlayEntitiesListViewModel.swift; sourceTree = "<group>"; };
420FE84F2B556F7500878E06 /* CarPlayEntitiesListTemplate+Build.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CarPlayEntitiesListTemplate+Build.swift"; sourceTree = "<group>"; };
4219606F2CA2AE1600F7134E /* WidgetAssistViewTintedWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetAssistViewTintedWrapper.swift; sourceTree = "<group>"; };
421B1C152BD65246001ED18C /* WidgetsSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetsSettingsView.swift; sourceTree = "<group>"; };
421B1C172BD6524E001ED18C /* WidgetsSettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetsSettingsViewModel.swift; sourceTree = "<group>"; };
421B1C192BD65255001ED18C /* WidgetsSettingsView+build.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WidgetsSettingsView+build.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3982,6 +3984,7 @@
42F958972BB4681E00497981 /* WidgetAssist.swift */,
42F9589A2BB468F400497981 /* WidgetAssistProvider.swift */,
42F9589D2BB4705E00497981 /* WidgetAssistView.swift */,
4219606F2CA2AE1600F7134E /* WidgetAssistViewTintedWrapper.swift */,
);
path = Assist;
sourceTree = "<group>";
Expand Down Expand Up @@ -6431,6 +6434,7 @@
403AE9092C2E220200D48147 /* WidgetGauge.swift in Sources */,
42D3E4BA2C5D30CB00444BE6 /* WidgetScriptsAppIntent.swift in Sources */,
4289DDB12C85D629003591C2 /* ControlScenesValueProvider.swift in Sources */,
421960702CA2AE1600F7134E /* WidgetAssistViewTintedWrapper.swift in Sources */,
42F9589F2BB4707F00497981 /* WidgetAssistView.swift in Sources */,
403AE9122C2E2BFC00D48147 /* WidgetGaugeAppIntentTimelineProvider.swift in Sources */,
42F9589C2BB4691D00497981 /* WidgetAssistProvider.swift in Sources */,
Expand Down
9 changes: 7 additions & 2 deletions Sources/Extensions/Widgets/Assist/WidgetAssist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ struct WidgetAssist: Widget {
intent: AssistInAppIntent.self,
provider: WidgetAssistProvider(),
content: { entry in
WidgetAssistView(entry: entry)
.widgetBackground(Color.clear)
if #available(iOS 18.0, *) {
WidgetAssistViewTintedWrapper(entry: entry)
.widgetBackground(Color.clear)
} else {
WidgetAssistView(entry: entry, tinted: false)
.widgetBackground(Color.clear)
}
}
)
.contentMarginsDisabledIfAvailable()
Expand Down
51 changes: 31 additions & 20 deletions Sources/Extensions/Widgets/Assist/WidgetAssistView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import SwiftUI

struct WidgetAssistView: View {
@Environment(\.widgetFamily) private var widgetFamily
let entry: WidgetAssistEntry
private let entry: WidgetAssistEntry
private let tinted: Bool

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

init(entry: WidgetAssistEntry) {
init(entry: WidgetAssistEntry, tinted: Bool) {
self.entry = entry
self.tinted = tinted
}

var body: some View {
Expand All @@ -40,29 +42,38 @@ struct WidgetAssistView: View {
private var singleHomeScreenItem: some View {
VStack(spacing: Spaces.two) {
Spacer()
Image(uiImage: MaterialDesignIcons.messageProcessingOutlineIcon.image(
ofSize: .init(width: 56, height: 56),
color: UIColor(asset: Asset.Colors.haPrimary)
))
.foregroundStyle(.ultraThickMaterial)
VStack(spacing: .zero) {
Group {
Text(L10n.Widgets.Assist.actionTitle)
.font(.footnote.bold())
.foregroundColor(Color(uiColor: .label))
Text(subtitle)
.font(.footnote.weight(.light))
.lineLimit(2)
.fixedSize(horizontal: false, vertical: true)
.multilineTextAlignment(.center)
Group {
Image(uiImage: MaterialDesignIcons.messageProcessingOutlineIcon.image(
ofSize: .init(width: 56, height: 56),
color: UIColor(asset: Asset.Colors.haPrimary)
))
.foregroundStyle(.ultraThickMaterial)
VStack(spacing: .zero) {
Group {
Text(L10n.Widgets.Assist.actionTitle)
.font(.footnote.bold())
.foregroundColor(Color(uiColor: .label))
Text(subtitle)
.font(.footnote.weight(.light))
.lineLimit(2)
.fixedSize(horizontal: false, vertical: true)
.multilineTextAlignment(.center)
}
.foregroundColor(.gray)
.frame(maxWidth: .infinity, alignment: .center)
}
}
.modify { view in
if #available(iOS 18, *) {
view.widgetAccentable()
} else {
view
}
.foregroundColor(.gray)
.frame(maxWidth: .infinity, alignment: .center)
}
Spacer()
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(Spaces.two)
.background(Color(uiColor: .systemBackground))
.background(tinted ? Color.clear : Color(uiColor: .systemBackground))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Foundation
import SwiftUI

@available(iOS 16.0, *)
struct WidgetAssistViewTintedWrapper: View {
@Environment(\.widgetRenderingMode) var widgetRenderingMode

private let entry: WidgetAssistEntry

init(entry: WidgetAssistEntry) {
self.entry = entry
}

var body: some View {
WidgetAssistView(
entry: entry,
tinted: widgetRenderingMode == .accented
)
}
}
10 changes: 7 additions & 3 deletions Sources/Extensions/Widgets/Common/WidgetBasicContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ struct WidgetBasicContainerView: View {
.widgetBackground(Color.asset(Asset.Colors.primaryBackground))
}

@available(iOS 17.0, *)
@available(iOS 16.4, *)
private func intent(for model: WidgetBasicViewModel) -> (any AppIntent)? {
switch model.interactionType {
case .widgetURL:
return nil
case let .appIntent(widgetIntentType):
switch widgetIntentType {
case .action:
var intent = PerformAction()
let intent = PerformAction()
intent.action = IntentActionAppEntity(id: model.id, displayString: model.title)
intent.hapticConfirmation = true
return intent
Expand Down Expand Up @@ -86,7 +86,11 @@ struct WidgetBasicContainerView: View {
ForEach(column) { model in
if case let .widgetURL(url) = model.interactionType {
Link(destination: url.withWidgetAuthenticity()) {
WidgetBasicView(model: model, sizeStyle: sizeStyle, tinted: false)
if #available(iOS 18.0, *) {
WidgetBasicViewTintedWrapper(model: model, sizeStyle: sizeStyle)
} else {
WidgetBasicView(model: model, sizeStyle: sizeStyle, tinted: false)
}
}
} else {
if #available(iOS 17.0, *), let intent = intent(for: model) {
Expand Down

0 comments on commit 32475b5

Please sign in to comment.