Skip to content

Instantly share code, notes, and snippets.

@Kyome22
Created January 22, 2026 03:06
Show Gist options
  • Select an option

  • Save Kyome22/e62bf0cc49aeea8beece1753c4423b1c to your computer and use it in GitHub Desktop.

Select an option

Save Kyome22/e62bf0cc49aeea8beece1753c4423b1c to your computer and use it in GitHub Desktop.
Strange Animation with contentMargins(.training)
import SwiftUI
public struct ContentView: View {
@State var items = [Item]()
public init() {}
public var body: some View {
HStack {
Button {
items.append(Item())
} label: {
Image(systemName: "plus")
}
.frame(width: 50)
ScrollView {
VStack {
ForEach(items) { item in
HStack {
Text(item.id.uuidString)
.frame(maxWidth: .infinity)
Button {
items.removeAll { $0.id == item.id }
} label: {
Image(systemName: "trash.fill")
}
}
.padding()
.background(Color(.secondarySystemBackground), in: .rect(cornerRadius: 8))
}
}
.animation(.default, value: items.map(\.id))
}
.contentMargins(.trailing, 100)
Spacer(minLength: 0)
}
}
struct Item: Identifiable {
var id = UUID()
}
}
@Kyome22
Copy link
Author

Kyome22 commented Jan 22, 2026

contentMargins(.trailing)を利用すると、ScrollViewが空っぽになる直前のアニメーションが変になります。
When using contentMargins(.trailing), the animation just before the ScrollView becomes empty looks strange.

strange

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment