Skip to content

Commit

Permalink
Add animation to assist button
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoncal committed Nov 13, 2023
1 parent 950ffd5 commit 67ac37c
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions Sources/Extensions/Watch/Assist/AssistView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AssistHostingController: WKHostingController<AssistView> {
struct AssistView: View {

@ObservedObject private var viewModel: AssistViewModel
@State private var micAnimationRunning = false

init(viewModel: AssistViewModel) {
self._viewModel = .init(wrappedValue: viewModel)
Expand Down Expand Up @@ -73,17 +74,33 @@ struct AssistView: View {

private var assistButton: some View {
VStack {
Image(systemName: viewModel.microphoneIcon)
.resizable()
assistIcon
.aspectRatio(contentMode: .fit)
.frame(alignment: .center)
.foregroundColor(.accentColor)
.frame(alignment: .center)
}
.frame(maxWidth: .infinity)
.frame(height: 40)
.onTapGesture {
viewModel.requestInput()
}
.onChange(of: viewModel.microphoneIcon) { newValue in
withAnimation {
micAnimationRunning = newValue != AssistViewModel.MicrophoneIcons.microphoneIcon
}
}
}

@ViewBuilder
private var assistIcon: some View {
if #available(watchOSApplicationExtension 10.0, *) {
Image(systemName: viewModel.microphoneIcon)
.resizable()
.symbolEffect(.variableColor.iterative, options: .repeating, value: micAnimationRunning)
} else {
Image(systemName: viewModel.microphoneIcon)
.resizable()
}
}
}

Expand Down

0 comments on commit 67ac37c

Please sign in to comment.