Skip to content

Commit 695fd29

Browse files
bgoncalCopilot
andauthored
Refactor watch Assist UI (#3702)
<!-- 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. --> ## 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. --> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 44499b2 commit 695fd29

File tree

2 files changed

+38
-20
lines changed

2 files changed

+38
-20
lines changed

Sources/Extensions/Watch/Assist/Views/ChatBubbleView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct ChatBubbleView: View {
88
Group {
99
if item.itemType == .typing {
1010
AssistTypingIndicator()
11-
.padding(.vertical, Spaces.half)
11+
.padding(.vertical, DesignSystem.Spaces.half)
1212
} else {
1313
Text(item.markdown)
1414
}
@@ -44,7 +44,7 @@ struct ChatBubbleView: View {
4444
case .info:
4545
.secondary
4646
default:
47-
.primary
47+
.black
4848
}
4949
}
5050

Sources/Extensions/Watch/Assist/WatchAssistView.swift

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@ import Shared
22
import SwiftUI
33

44
struct WatchAssistView: View {
5+
// MARK: - Constants
6+
7+
private enum Constants {
8+
static let micButtonFontSize: CGFloat = 11
9+
static let micButtonOffsetY: CGFloat = 22
10+
static let micRecordingFontSizeLarge: CGFloat = 80
11+
static let micRecordingFontSizeSmall: CGFloat = 50
12+
static let micButtonProgressScale: CGFloat = 1.5
13+
static let micButtonProgressHeight: CGFloat = 40
14+
static let micButtonProgressPadding: CGFloat = DesignSystem.Spaces.half
15+
static let micRecordingTextFontSize: CGFloat = 11
16+
static let emptyStateImageWidth: CGFloat = 70
17+
static let emptyStateImageHeight: CGFloat = 70
18+
static let emptyStateImageOpacity: Double = 0.5
19+
static let progressViewScale: CGFloat = 2
20+
}
21+
522
@StateObject private var viewModel: WatchAssistViewModel
623
@State private var isInitialAppearance = true
724
private let progressViewId = "progressViewId"
@@ -81,7 +98,7 @@ struct WatchAssistView: View {
8198

8299
private var volumeButton: some View {
83100
NavigationLink(destination: VolumeView()) {
84-
Image(systemName: "speaker.wave.2.fill")
101+
Image(systemSymbol: .speakerWave2Fill)
85102
}
86103
}
87104

@@ -91,7 +108,8 @@ struct WatchAssistView: View {
91108
.opacity(viewModel.state == .recording ? 1 : 0)
92109
ProgressView()
93110
.progressViewStyle(.circular)
94-
.scaleEffect(.init(floatLiteral: 2))
111+
// This could also be achieved using .controlSize(.large) on watchOS 9+
112+
.scaleEffect(Constants.progressViewScale)
95113
.ignoresSafeArea()
96114
.frame(maxWidth: .infinity, maxHeight: .infinity)
97115
.modify {
@@ -107,19 +125,19 @@ struct WatchAssistView: View {
107125
@ViewBuilder
108126
private var micButton: some View {
109127
if ![.loading, .recording].contains(viewModel.state), !viewModel.showChatLoader {
110-
HStack(spacing: Spaces.one) {
128+
HStack(spacing: DesignSystem.Spaces.one) {
111129
if viewModel.assistService.deviceReachable {
112130
Text(verbatim: L10n.Assist.Watch.MicButton.title)
113-
Image(systemName: "mic.fill")
131+
Image(systemSymbol: .micFill)
114132
} else {
115-
Image(systemName: "iphone.slash")
133+
Image(systemSymbol: .iphoneSlash)
116134
.foregroundStyle(.red)
117135
.padding(.trailing)
118136
}
119137
}
120-
.font(.system(size: 11))
138+
.font(.system(size: Constants.micButtonFontSize))
121139
.foregroundStyle(.gray)
122-
.offset(y: 22)
140+
.offset(y: Constants.micButtonOffsetY)
123141
}
124142
}
125143

@@ -135,11 +153,11 @@ struct WatchAssistView: View {
135153
private var micButtonProgressView: some View {
136154
ProgressView()
137155
.progressViewStyle(.circular)
138-
.scaleEffect(.init(floatLiteral: 1.5))
156+
// This could also be achieved using .controlSize(.large) on watchOS 9+
157+
.scaleEffect(Constants.micButtonProgressScale)
139158
.frame(maxWidth: .infinity, alignment: .center)
140-
.progressViewStyle(.linear)
141-
.frame(height: 40)
142-
.padding(Spaces.half)
159+
.frame(height: Constants.micButtonProgressHeight)
160+
.padding(Constants.micButtonProgressPadding)
143161
.modify {
144162
if #available(watchOS 10, *) {
145163
$0.background(.regularMaterial)
@@ -158,7 +176,7 @@ struct WatchAssistView: View {
158176
VStack(spacing: .zero) {
159177
if #available(watchOS 10.0, *) {
160178
Image(systemSymbol: .waveformCircleFill)
161-
.font(.system(size: 80))
179+
.font(.system(size: Constants.micRecordingFontSizeLarge))
162180
.symbolEffect(
163181
.variableColor.cumulative.dimInactiveLayers.nonReversing,
164182
options: .repeating,
@@ -168,10 +186,10 @@ struct WatchAssistView: View {
168186
.foregroundStyle(.white, Color.haPrimary)
169187
} else {
170188
Image(systemSymbol: .waveformCircleFill)
171-
.font(.system(size: 50))
189+
.font(.system(size: Constants.micRecordingFontSizeSmall))
172190
}
173191
Text(verbatim: L10n.Watch.Assist.Button.Recording.title)
174-
.font(.system(size: 11))
192+
.font(.system(size: Constants.micRecordingTextFontSize))
175193
.foregroundStyle(.gray)
176194
Text(verbatim: L10n.Watch.Assist.Button.SendRequest.title)
177195
.font(.footnote.bold())
@@ -194,7 +212,7 @@ struct WatchAssistView: View {
194212
ScrollViewReader { proxy in
195213
ScrollView {
196214
// Using LazyVStack instead of List to avoid List minimum row height
197-
LazyVStack(spacing: Spaces.one) {
215+
LazyVStack(spacing: DesignSystem.Spaces.one) {
198216
ForEach(viewModel.chatItems, id: \.id) { item in
199217
ChatBubbleView(item: item)
200218
}
@@ -221,12 +239,12 @@ struct WatchAssistView: View {
221239
Image(uiImage: Asset.casitaDark.image)
222240
.resizable()
223241
.frame(
224-
width: 70,
225-
height: 70,
242+
width: Constants.emptyStateImageWidth,
243+
height: Constants.emptyStateImageHeight,
226244
alignment: .center
227245
)
228246
.aspectRatio(contentMode: .fit)
229-
.opacity(0.5)
247+
.opacity(Constants.emptyStateImageOpacity)
230248
Spacer()
231249
}
232250
.listRowBackground(Color.clear)

0 commit comments

Comments
 (0)