Skip to content

Commit 2becfe2

Browse files
committed
Adjust widget animation
1 parent f8c9ffb commit 2becfe2

2 files changed

Lines changed: 72 additions & 11 deletions

File tree

Core/Sources/SuggestionWIdget/SuggestionPanelView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ struct SuggestionPanelView: View {
6262

6363
Spacer()
6464
}
65-
.frame(height: min(codeHeight, 300))
65+
.frame(maxHeight: max(codeHeight, 300))
66+
.fixedSize(horizontal: false, vertical: true)
6667

6768
HStack {
6869
Text("\(viewModel.currentSuggestionIndex)/\(viewModel.suggestionCount)")

Core/Sources/SuggestionWIdget/WidgetView.swift

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@ final class WidgetViewModel: ObservableObject {
99
case bottomRight
1010
}
1111

12-
var position: Position = .topRight
13-
@Published var isProcessing: Bool = false
12+
var position: Position
13+
@Published var isProcessing: Bool
1414

15-
init() {}
15+
init(position: Position = .topRight, isProcessing: Bool = false) {
16+
self.position = position
17+
self.isProcessing = isProcessing
18+
}
1619
}
1720

1821
struct WidgetView: View {
1922
@ObservedObject var viewModel: WidgetViewModel
2023
@ObservedObject var panelViewModel: SuggestionPanelViewModel
21-
@State var isHovering = false
24+
@State var isHovering: Bool = false
25+
@State var processingProgress: Double = 0
2226

2327
var body: some View {
2428
Circle().fill(isHovering ? .white.opacity(0.8) : .white.opacity(0.3))
@@ -28,21 +32,20 @@ struct WidgetView: View {
2832
}
2933
}
3034
.overlay {
35+
let lineWidth: Double = 4
36+
3137
Circle()
3238
.stroke(
3339
panelViewModel.suggestion.isEmpty
3440
? Color(nsColor: .darkGray)
3541
: Color.accentColor,
36-
style: .init(lineWidth: 4)
42+
style: .init(lineWidth: lineWidth)
3743
)
38-
.padding(2)
44+
.padding(lineWidth / 2)
3945
}
4046
.overlay {
4147
if viewModel.isProcessing {
42-
ProgressView()
43-
.progressViewStyle(.circular)
44-
.tint(.primary)
45-
.scaleEffect(x: 0.5, y: 0.5)
48+
animationgRing()
4649
}
4750
}
4851
.onHover { yes in
@@ -51,4 +54,61 @@ struct WidgetView: View {
5154
}
5255
}
5356
}
57+
58+
@ViewBuilder
59+
func animationgRing() -> some View {
60+
let lineWidth = processingProgress * 5 + 4
61+
62+
Circle()
63+
.stroke(
64+
Color.accentColor,
65+
style: .init(lineWidth: lineWidth)
66+
)
67+
.onAppear {
68+
Task {
69+
await Task.yield()
70+
withAnimation(
71+
.easeInOut(duration: 1)
72+
.repeatForever(
73+
autoreverses: true
74+
)
75+
) {
76+
processingProgress = 1
77+
}
78+
}
79+
}
80+
.padding(lineWidth / 2)
81+
}
82+
}
83+
84+
struct WidgetView_Preview: PreviewProvider {
85+
static var previews: some View {
86+
VStack {
87+
WidgetView(
88+
viewModel: .init(position: .topRight, isProcessing: false),
89+
panelViewModel: .init(),
90+
isHovering: false
91+
)
92+
93+
WidgetView(
94+
viewModel: .init(position: .topRight, isProcessing: false),
95+
panelViewModel: .init(),
96+
isHovering: true
97+
)
98+
99+
WidgetView(
100+
viewModel: .init(position: .topRight, isProcessing: true),
101+
panelViewModel: .init(),
102+
isHovering: false
103+
)
104+
105+
WidgetView(
106+
viewModel: .init(position: .topRight, isProcessing: false),
107+
panelViewModel: .init(suggestion: ["Hello"]),
108+
isHovering: false
109+
)
110+
}
111+
.frame(width: 40)
112+
.background(Color.black)
113+
}
54114
}

0 commit comments

Comments
 (0)