Skip to content

Commit 2f241a8

Browse files
committed
Fix animation glitch.
1 parent 42f5a7d commit 2f241a8

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

Planet/Views/My/AvatarPickerView.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ struct AvatarPickerView: View {
140140
.onChange(of: randomSelectedAvatarKey) { newValue in
141141
guard let newValue else { return }
142142
Task { @MainActor in
143-
withAnimation(.linear(duration: 0.25)) {
143+
withAnimation(.easeOut(duration: 0.3)) {
144144
proxy.scrollTo(newValue, anchor: .top)
145145
}
146146
}
@@ -215,14 +215,19 @@ struct AvatarPickerView: View {
215215
avatarChanged = true
216216
debugPrint("Set planet avatar to \(randomKey), at: \(avatarURL)")
217217
Task { @MainActor in
218-
self.randomSelectedAvatarKey = randomKey
219-
try? await Task.sleep(nanoseconds: 300_000_000)
220-
let _ = withAnimation(.linear(duration: 0.25)) {
221-
self.highlightedItems.insert(randomKey)
222-
}
223-
try? await Task.sleep(nanoseconds: 300_000_000)
224-
let _ = withAnimation(.easeOut(duration: 0.4)) {
225-
self.highlightedItems.removeAll()
218+
highlightedItems.removeAll()
219+
randomSelectedAvatarKey = randomKey
220+
Task.detached(priority: .utility) {
221+
try? await Task.sleep(nanoseconds: 300_000_000)
222+
let _ = await MainActor.run {
223+
self.highlightedItems.insert(randomKey)
224+
}
225+
try? await Task.sleep(nanoseconds: 600_000_000)
226+
await MainActor.run {
227+
let _ = withAnimation(.easeOut(duration: 0.4)) {
228+
highlightedItems.removeAll()
229+
}
230+
}
226231
}
227232
}
228233
}

0 commit comments

Comments
 (0)