I have a view with dynamic content. I want to add an animation (fadeOut/fadeIn) to switch to the next view
For this purpose I tried:
.transition(.opacity)
.animation(.easeInOut, value: tabSelection)
But doesn't work, I get a slide animation from top to bottom
My current code:
struct LongOnboardingContainerView: View {
@State var tabSelection = 0
var body: some View {
ZStack {
Step.allCases[tabSelection].view {
tabSelection += 1
}
.transition(.opacity)
.animation(.easeInOut, value: tabSelection)
}
.ignoresSafeArea(.all)
}
enum Step: Int, CaseIterable {
case parentsGoal, nickname, age, mathSkills, languageSkill
func view(pushNext: @escaping () -> ()) -> AnyView {
switch self {
case parentsGoal mathSkills, languageSkill:
return AnyView(MultiAnswerView(viewModel: .init(step: self), pushNext: pushNext))
case .nickname:
return AnyView(NickNameController.swiftUIRepresentation { vc in
vc.nextHandler = pushNext
})
default:
return AnyView(Text("Test").onTapGesture {
pushNext()
})
}
}
}
}