I'm trying to use a different version of view modifier when a view is inserted and when its being removed. However combining .asymmetric
and .modifier
transitions don't quite work as expected.
Here's a test that attempts to print out the combination of states the view transitions between:
struct TransitionPrinting: ViewModifier {
var isInsertion: Bool
var isActive: Bool
func body(content: Content) -> some View {
content
.onAppear {
print("isInsertion", isInsertion, "isActive", isActive)
}
}
}
struct ContentView: View {
@State var toggled = false
var body: some View {
VStack {
Toggle("Toggle", isOn: $toggled)
if toggled {
Text("Hello, world!")
.transition(
.asymmetric(
insertion: .modifier(
active: TransitionPrinting(isInsertion: true, isActive: true),
identity: TransitionPrinting(isInsertion: true, isActive: false)
),
removal: .modifier(
active: TransitionPrinting(isInsertion: false, isActive: true),
identity: TransitionPrinting(isInsertion: false, isActive: false)
)
)
)
}
Spacer()
}
.padding()
}
}
When the above is run, I only see the following in the simulator (with 2 of the states missing):
isInsertion true isActive true
isInsertion false isActive false
What's wrong here?