Skip to content

Example views are presented twice in compact width environments #1478

Description

@philium

In compact width environments, when selecting subsequent examples (not the first one), the example view is presented twice: it appears, it disappears, and reappears. This can be seen by adding the following to any example (or multiple examples):

@State private var id = UUID()
.onAppear {
    print("\(id) onAppear")
}
.onDisappear {
    print("\(id) onDisappear")
}

Run the app, open an example, tap the back button, and select one of the modified examples. You'll see something like this in the console:

724BE33D-EB4E-445C-BD49-8B74CF6695FE onAppear
724BE33D-EB4E-445C-BD49-8B74CF6695FE onDisappear
85767EC3-A465-4F9C-A1F3-753F726AFE49 onAppear
85767EC3-A465-4F9C-A1F3-753F726AFE49 onDisappear
85767EC3-A465-4F9C-A1F3-753F726AFE49 onAppear

The first onAppear/onDisappear pair is from the initial example. The second example appears, disappears, and then appears again. This is unexpected, inefficient, and in some cases harmful (see swift/8234).

I suspect that using navigation links would address this problem. I checked a different app that uses navigation links and it does not exhibit this same problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions