feedback-assistant / reports

Open collection of Apple Feedback Assistant reports
237 stars 2 forks source link

FB15509540: Allow any view transition in Form view #571

Open samhenrigold opened 3 weeks ago

samhenrigold commented 3 weeks ago

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()
}