Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Section transition in SwiftUI Form

The Section transition in Form is always left-right, I would like to change it to right-left in some cases, I tried .transition with .move modifier, but it does not have effect.

struct ContentView: View {
    
    @State var visible = true

    var body: some View {
        
        Form {
            Button("visible") {
                self.visible.toggle()
            }
            visible ? Section {
                Text("Section 1")
                Text("Section 1")
            }.transition(.move(edge: .leading)) : nil
            !visible ? Section {
                Text("Section 2")
                Text("Section 2")
            }.transition(.move(edge: .trailing)) : nil
            Section {
                Text("Section 3")
                Text("Section 3")
            } // Section 3 should not be animated
        }.animation(.linear(duration: 0.5))
        
    }
}
like image 465
Sorin Lica Avatar asked Mar 18 '26 20:03

Sorin Lica


1 Answers

I read through a significant amount of Apple's code documentation for SwiftUI forms and it appears that there are very few options for customization; specifically with the way you have the code currently set up. In that, I would recommend creating the animations and page from scratch. Doing it that way, you would have complete creative freedom of the directions for the transitions. This would take a lot of work to look like a Form, but it's possible. The following answer will give you a right-left transition: https://stackoverflow.com/a/62144939/13296047

like image 102
EJZ Avatar answered Mar 20 '26 18:03

EJZ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!