When I tap on an item in a list, I'd like to transition a view in from the leading edge.
Currently:
When I use
ListView
by itself, the appear transition works fine.When I wrap
ListView
in aNavigationStack
, theImage
's appear transition does not occur. TheText
transitions correctly.In both instances, the disappear transition works fine.
Below is a minimal example (including preview providers) to demonstrate what I'm talking about:
import SwiftUI
struct ListView: View {
@State var selected: Int? = nil
var body: some View {
List(0..<4) { index in
HStack {
if selected == index {
Image(systemName: "checkmark.circle.fill")
.transition(.move(edge: .leading).combined(with: .opacity))
}
Text("\(index)")
Spacer()
}
.contentShape(Rectangle())
.onTapGesture { selected = index }
.animation(.default, value: selected == index)
}
}
}
struct AnimationBroken_Previews: PreviewProvider {
static var previews: some View {
NavigationStack {
ListView()
}
}
}
struct AnimationWorks_Previews: PreviewProvider {
static var previews: some View {
ListView()
}
}