Skip to content

Commit 09304fa

Browse files
committed
Fix performance issue with capsule notifications
1 parent f46b759 commit 09304fa

File tree

1 file changed

+3
-38
lines changed

1 file changed

+3
-38
lines changed

App/Sources/UI/Views/Notifications/CapsuleNotficationView.swift

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,10 @@ struct CapsuleNotificationView: View {
6767
}
6868

6969
var body: some View {
70-
TextContainerView(publisher: publisher)
70+
TextContainerView()
7171
.animation(.none, value: publisher.state)
7272
.font(.system(.title2, design: .rounded, weight: .regular))
7373
.padding(.leading, publisher.state == .running ? 24 : 0)
74-
.overlay(alignment: .leading) {
75-
ProgressView()
76-
.progressViewStyle(CustomProgressViewStyle())
77-
.frame(width: 18)
78-
.opacity(publisher.state == .running ? 1 : 0)
79-
.animation(nil, value: publisher.state)
80-
}
8174
.foregroundStyle(publisher.state.foregroundColor)
8275
.padding(.horizontal, 16)
8376
.padding(.vertical, 8)
@@ -107,11 +100,12 @@ struct CapsuleNotificationView: View {
107100
.frame(minWidth: 128, maxWidth: .infinity)
108101
.opacity(publisher.state == .idle ? 0 : 1)
109102
.animation(.smooth(duration: 0.275), value: publisher.state)
103+
.environmentObject(publisher)
110104
}
111105
}
112106

113107
private struct TextContainerView: View {
114-
@ObservedObject var publisher: CapsuleNotificationPublisher
108+
@EnvironmentObject var publisher: CapsuleNotificationPublisher
115109

116110
var body: some View {
117111
Group {
@@ -198,35 +192,6 @@ private struct AnimatedCharacterView: View {
198192
}
199193
}
200194

201-
private struct CustomProgressViewStyle: ProgressViewStyle {
202-
@State private var isSpinning: Bool = false
203-
204-
func makeBody(configuration _: Configuration) -> some View {
205-
Circle()
206-
.trim(from: 0.2, to: 1.0)
207-
.stroke(
208-
AngularGradient(
209-
gradient: Gradient(colors: [
210-
Color(.controlAccentColor.withSystemEffect(.disabled)),
211-
.accentColor,
212-
]),
213-
center: .center,
214-
),
215-
style: StrokeStyle(lineWidth: 2.5, lineCap: .round),
216-
)
217-
.padding(1)
218-
.rotationEffect(isSpinning ? .degrees(360) : .degrees(0))
219-
.animation(
220-
Animation.linear(duration: 1.0)
221-
.repeatForever(autoreverses: false),
222-
value: isSpinning,
223-
)
224-
.onAppear {
225-
isSpinning = true
226-
}
227-
}
228-
}
229-
230195
#Preview {
231196
let dynamicPublisher = CapsuleNotificationPublisher(text: "Running…", id: UUID().uuidString)
232197

0 commit comments

Comments
 (0)