0

With this test app:

import SwiftUI

enum Route
{
    case first
    case second
}

@main struct NavigatorApp : App
{
    @State private var path: [Route] = [.first]

    var body: some Scene
    {
        WindowGroup
        {
            NavigationStack(path: $path)
            {
                StartView()
            }
        }
    }
}

struct StartView : View
{
    var body: some View
    {
        Form
        {
            Section
            {
                NavigationLink(value: Route.first)
                {
                    Text("Go First")
                }
            }
        }
        .navigationTitle("Start")
        .navigationDestination(for: Route.self)
        { route in
            switch route
            {
            case .first:
                FirstView()

            case .second:
                SecondView()
            }
        }
    }
}

struct FirstView : View
{
    var body: some View
    {
        Form
        {
            Section
            {
                NavigationLink(value: Route.second)
                {
                    Text("Go Second")
                }
            }
        }
        .navigationTitle("First")
    }
}

struct SecondView : View
{
    @State private var hasOption: Bool = false

    var body: some View
    {
        Form
        {
            Section
            {
                Toggle("Some Option", isOn: $hasOption)
            }
        }
        .navigationTitle("Second")
    }
}

Why is the deselection animation of the "Go First" cell different/lacking/wrong when popping back to StartView the first time (when having a non-empty NavigationStack path)?

Is there anything I could do to fix this?

Here's a GIF of the unexpected 'animation' ("Go First" cell background jumps from grey to white):

Unexpected

Here a GIF of the normal animation ("Go First" background animates from grey to white):

Okay

meaning-matters
  • 21,929
  • 10
  • 82
  • 142

1 Answers1

1

Cell deselection doesn't fit into SwiftUI's state driven world so we just have to accept the visual glitches. It worked better when List/Form was backed by UITableView but since iOS 16 it's backed by UICollectionView which has always had buggy row select/deselect animations.

If you switch from NavigationStackView to NavigationSplitView and test collapsed on iPhone you'll see it's even worse with no animation at all.

malhal
  • 26,330
  • 7
  • 115
  • 133