-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transition not applied to entire View #62
Comments
Hi @LJNIC would you be able to provide us with a code snippet or a small example? Thank you. |
Here is an example adapted from the one in the readme. When hitting the |
Thanks for reporting this interesting issue. The problem is related to the "laziness" of the grid. If you try your example with struct A: View {
var body: some View {
Screen {
VStack(spacing: 50) {
Text("Hello World")
ScrollView {
LazyVGrid(columns: [.init(.flexible())]) {
ForEach(0..<20) { i in
Text("Won't Transition")
}
}
}
PushView(destination: B()) {
Text("PUSH")
}
}
.background(Color.green)
}
}
} |
It breaks again when a more complicated grid is used, unfortunately. Here is a snippet from my codebase: static let gridItem = GridItem(.adaptive(minimum: 50, maximum: 75))
static let columns = [GridItem](repeating: gridItem, count: 9)
LazyVGrid(columns: Self.columns) {
ForEach(0..<9) { y in
ForEach(0..<9) { x in
Rectangle()
.frame(width: 30, height: 30)
.animation(.spring())
}
}
} The animation on the individual rectangles also messes with it, though there's still issues when removed. This issue is rather unfortunate, because I love the functionality of the stack. |
Yes, you're right, it's unfortunate. For some reason, the lazy views break something in the navigation animation. I'll mark this as a bug, I'll try to investigate it as soon as possible. In the meantime, trying to help you find a workaround: do you really need a lazy grid in this case? Something like this would work (I know, it's just a silly workaround): struct A: View {
var body: some View {
Screen {
VStack {
ForEach(0..<9) { y in
HStack {
ForEach(0..<9) { x in
Rectangle()
.frame(width: 30, height: 30)
}
}
}
PushView(destination: B()) {
Text("PUSH")
}
}
}
}
} |
When I use a
PushView
, part of the contents of theView
are not treated the same for the transition. They will transition instantly, while the rest of the content transitions normally. It seems to primarily affect "dynamic" content, such as aForEach
. Is there a way around this?The text was updated successfully, but these errors were encountered: