so I'm trying to show different elements in different ways when a view is presented in SwiftUI (One is a slide in from the leading edge and the other element is a slide up from the bottom of the screen). My basic view structure is as follows:
struct ViewName: View {
@ObservedObject var appState: AppState //this is just a class that tracks the state of app variables, in my case it holds a variable called 'showView' that indicates whether or not to show the view.
var body: some View {
ZStack {
Color.white
.edgesIgnoringSafeArea(.all)
VStack {
Text("Test")
}.transition(AnyTransition.asymmetric(insertion: .move(edge: .leading), removal: .move(edge: .trailing)))
VStack {
Spacer()
HStack {
Text("Test2")
Spacer()
Text("Test3")
}
}.transition(AnyTransition.move(edge: .bottom))
}
}
}
Elsewhere, I have the view initialized with something like:
if appState.showView {
ViewName(appState: appState)
}
and a button that changes whether the view is presented:
Button(action: {
withAnimation {
appState.showView.toggle()
}
}, label: {
Text("Click me")
})
It seems like Swift doesn't know what to do with the two transitions though, and it sort of defaults them both to a fade-in opacity transition. Not sure how to fix this. Any help much appreciated!