Created
January 22, 2026 03:06
-
-
Save Kyome22/e62bf0cc49aeea8beece1753c4423b1c to your computer and use it in GitHub Desktop.
Strange Animation with contentMargins(.training)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
contentMargins(.trailing)を利用すると、ScrollViewが空っぽになる直前のアニメーションが変になります。When using
contentMargins(.trailing), the animation just before the ScrollView becomes empty looks strange.