I had a similar issue and I finally found a solution that worked for me, try wrapping the view in a ZStack and utilizing a .clipped modifier like the below code.
```
struct ContentView: View {
@State var animation: Bool = false
var body: some View {
VStack {
// This is the Button
Button(action: {
withAnimation(.spring(dampingFraction: 1, blendDuration: 0.5)) {
animation.toggle()
}
}) {
Image(systemName: "star.fill")
.resizable()
.frame(width: 100, height: 100)
.foregroundColor(.accentColor)
}
ZStack{
// This condition sends up the View
if animation {
SecondView()
.transition(.move(edge: .bottom))
}
}.clipped()
}
.padding()
}
}
```
I found a bug in swiftUI_preview for animations. when you use a transition animation in code and want to see that in SwiftUI_preview it will not show animations or just show when some view disappears with animation. To solve this problem you just need to add your view in preview in a VStack. like this :
struct SomeView: View {
@State var isShowSideBar = false
var body: some View {
ZStack {
Button("ShowMenu") {
withAnimation {
isShowSideBar.toggle()
}
}
if isShowSideBar {
SideBarView()
.transition(.slide)
}
}
}
}
struct SomeView_Previews: PreviewProvider {
static var previews: some View {
VStack {
SomeView()
}
}
}
after this, all animations will happen.