Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FB15509540: Allow any view transition in Form view #571

Open
samhenrigold opened this issue Oct 29, 2024 · 0 comments
Open

FB15509540: Allow any view transition in Form view #571

samhenrigold opened this issue Oct 29, 2024 · 0 comments

Comments

@samhenrigold
Copy link

  • Date: 2024-10-16
  • Resolution: Open
  • Area: SwiftUI
  • OS: iOS 18.1
  • Type: Incorrect/Unexpected Behavior

Description

When conditionally showing and hiding Form sections, I’d expect to be able to use any transition I want, but the transitions are limited to just opacity.

Revealing sections with a combined slide/opacity transition is a common pattern and one I would expect to be possible in SwiftUI, but alas.

Files

//
//  SampleForm.swift
//  
//
//  Created by Sam Henri Gold on 2024-10-16.
//

import SwiftUI

struct SampleForm: View {
    @State private var showMoreFields = false
    @State private var textFieldValue = "World"
    @FocusState private var isFocused
    
    var body: some View {
        Form {
            Toggle("Show more fields", isOn: $showMoreFields.animation())
                .onChange(of: showMoreFields) {
                    isFocused = false
                }
            
            if showMoreFields {
                Section {
                    Text("Hello")
                    TextField("Hello what?", text: $textFieldValue)
                        .focused($isFocused)
                } footer: {
                    if isFocused {
                        Text("Some footer text with even more information")
                            .transition(.scale)
                    }
                }
                .transition(.slide)
            }
        }
        .animation(.easeInOut, value: showMoreFields)
        .animation(.easeInOut, value: isFocused)
    }
}

#Preview {
    SampleForm()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant