I'm trying to create a 'card flip' animation between two Views:
- View 'A' is a
CardView
within aLazyVGrid
- View 'B' is a custom modal overlay view
The LazyVGrid
and View 'B' are together in a ZStack
Specifically, the ContentView
is organized like so:
var body: some View {
ZStack {
NavigationView {
ScrollView {
LazyVGrid(columns: columns, spacing: 10) {
ForEach(model.events, id: \.self) { event in
SmallCardView(event: event)
.opacity(!showModal || event != modifiableEvent ? 1.0 : 0.0)
}
}
}
}
.brightness(self.showModal ? -0.1 : 0)
.blur(radius: self.showModal ? 16 : 0)
if self.showModal {
AddEventView(
showModal: $showModal,
existingEvent: modifiableEvent,
)
.opacity(showModal ? 1.0 : 0.0)
.padding(.horizontal, 16)
}
}
}
I came across this SO post, and the answer seems super promising, however the answer doesn't take into account if one of the views is within a Stack / Grid, which is the case for me. So, my question is, how can I adapt the linked solution so that it works as expected if one of the views is indeed embedded within a Stack or a Grid.
Edit: Another thing to note is that the size and position of the Views are different
I tried adding .modifier(FlipEffect(flipped: $showModal, angle: animate3d ? 180 : 0, axis: (x: 0, y: 1)))
to both the ZStack
and SmallCardView
, however neither yielded the expected results.
Thanks!
Edit: For clarity, I want to animate in a card flip style between these two views: