Thursday, August 11, 2022
HomeiOS Developmentios - SwiftUI: Sizzling to create a customized SwiftUI Transition relying on...

ios – SwiftUI: Sizzling to create a customized SwiftUI Transition relying on a State Object?

[ad_1]

Context: I’ve encountered an issue whereas working with SwiftUI Transitions. I’ve a FormView containing 4 totally different Sub-Kinds. When the Consumer presses the Subsequent-Button, the following Sub-Type View is offered with a Transition (.transfer -> proper to left).

I even have a Again Button. When the Consumer presses this Button, the earlier Sub-Type View is proven, at present with the identical Transition (.transfer -> proper to left). Nonetheless, I might prefer to reverse the Transition on this case to (.transfer -> left to proper).


Code

enum FormStep {
    case step1, step2, step3, step4
}

struct CustomForm: View  {
    @State non-public var step: FormStep = .step1

    var physique: some View {
        // This Button will change the step State to the earlier step
        Button(motion: { withAnimation { previousStep() } } { Textual content("Earlier") }

        // That is the Proper to Left Transition utilized to subForm
        subForm
            .transition(.uneven(insertion: .transfer(edge: .trailing), removing: .transfer(edge: .main)))

        // This Button will change the step State to the following step
        Button(motion: { withAnimation { nextStep() } } { Textual content("Subsequent") }
    }

    @ViewBuilder non-public var subForm: some View {
        change medicationFormVM.step {
        case .step1: StepOneSubForm()
        case .step2: StepTwoSubForm()
        case .step3: StepThreeSubForm()
        case .step4: StepFourSubForm()
        }
    }
}

Query: As you’ll be able to see, not matter whether or not you navigate again or forth, the Transition will at all times be proper to left. How can I obtain my purpose of fixing the Transition relying on which Button received pressed?

[ad_2]

RELATED ARTICLES

Most Popular

Recent Comments