ios – How do I decide a View transition on the time of transition, or dynamically?

[ad_1]

I am making an attempt to construct a Tab-Like view in SwiftUI, the place sections are transitioned left or proper relative to their positioning within the listing. I do know that TabView Exists, however I would favor to not animate backwards and forwards over ALL the kid views; simply to animate the incoming and outgoing views in a tab-like vogue.

I am getting caught on a technique to outline the transition, since on the time of rendering the view tree I do not know if the present view might want to exit left or proper, for the reason that subsequent part has not been chosen however the consumer but.

It looks as if I want a technique to override the present views removing transition when selectedSection (beneath) is modified, however earlier than the tree is redrawn..

Can somebody level me in the suitable course?

enum Part: String, CaseIterable {
    case one, two, three, 4
}

struct Demo: View {
    @State var selectedSection: Part = .one

     var physique: some View {
            let transition: AnyTransition = .uneven(insertion: .transfer(edge: .main), removing: .transfer(edge: .trailing))

          Group {
               swap selectedSection {
               case .one:
                     ViewOne()
                case .two:
                     ViewTwo()
                case .three:
                     ViewThree()
                case .4:
                     ViewFour()
               }
          }
          .transition(transition)
          .animation(.easeInOut(length: 0.30), worth: selectedSection)
    }
}

[ad_2]

Leave a Reply