Skip to content

StackElementIDGenerator breaks List selection #3633

Open
@myihsan

Description

@myihsan

Description

Normally, pop to a List will also deselect the cell along with the pop transition, and this behavior depends on the value of NavigationLink in SwiftUI.
However, NavigationLink.init(state:label:fileID:filePath:line:column:) will increment the id each time, making the value unique.

@Dependency(\.stackElementID) var stackElementID
self.init(value: state.map { StackState.Component(id: stackElementID(), element: $0) }) {

With this implementation, the cell selection will not be retained during the push and pop, so the cell will be deselected instantly when pop (not during the transition).

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

The value of NavigationLink remains the same when the state is the same.

Image

Actual behavior

The value of NavigationLink changes each time.

Image

Reproducing project

https://github.com/pointfreeco/swift-composable-architecture/blob/main/Examples/CaseStudies/SwiftUICaseStudies/04-NavigationStack.swift

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working due to a bug in the library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions