1

Compare the behavior of this two following code snippet; target iOS 14.4 iPad(4th gen) simulator, Xcode Version 12.4 (12D4e):

First:

    struct experimental: View {
        @State private var selection: Int? = 0
        
        var body: some View {
            NavigationView {
                            VStack {
                                ForEach(0 ..< 5) { item in
                                    NavigationLink(
                                        destination: Text("item \(item)"),
                                        tag: item,
                                        selection: $selection) {
                                        Text("item \(item)")
                                    }
                                }
                            }
                Text("Hello, World!")
            }
        }
    }

Second:

    struct experimental: View {
        @State private var selection: Int? = 0
        
        var body: some View {
            NavigationView {
                List(0 ..< 5) { item in
                    NavigationLink(
                        destination: Text("item \(item)"),
                        tag: item,
                        selection: $selection) {
                        Text("item \(item)")
                    }
                }
                Text("Hello, World!")
            }
        }
    }

The first example run as expected in simulator, the app initiate displaying default selection(item 0). However, the second example the app initiate displaying “Hello, World!” Text. When back button tapped on top left, it will return to default selection(item 0) then menu. The same unexpected behavior happened when we add another Text("Hello, World!") view to make it triple column navigation, middle and last column initiate to “Hello, World!” Text, but when back button on top tapped, middle column changed to default selection(item 0). It behave differently when List view used to wrap NavigationLink inside NavigationView.

Update: Problem occur on iPad DoubleColumnNavigationViewStyle() and new Three column NavigationView. Works fine for StackNavigationViewStyle

wk.experimental
  • 523
  • 4
  • 9
  • What happens if you wrap content inside NavigationView( List and Text ) in VStack? Currently Navigation View is returning 2 different views. – Tushar Sharma Mar 15 '21 at 06:29
  • Im not sure what you referring to: Wrapping both List and Text in VStack inside NavigationView is not what Im intent to do, by doing that both List and Text will be displayed in sidebar. Whereas, wrapping both List and Text in VStack separately not resolving the problem. Behaviorally, first case, initially it will display blank pages(since text moved inside VStack with List), then when back button tapped it will navigate to default selection(item 0), before you can tap back to sidebar. Latter case, still behave the same. Thus, same problem – wk.experimental Mar 15 '21 at 07:22
  • do you use iPad simulator? I think it behave correctly on iPhone simulator(since its StackNavigationStyle). Problem occur on DoubleColumnNavigationViewStyle() and the new three column iPad NavigationView. (default depend on how many child your NavigationView have) – wk.experimental Mar 15 '21 at 08:30
  • Apologies @wk.experimental I wasn’t testing on iPad, and had some other changes done, so got different result. While testing on ipAd I faced the same. Seems like bug though. – Tushar Sharma Mar 15 '21 at 08:32
  • yea, I think so. already reported it. Thank you for the help – wk.experimental Mar 15 '21 at 08:39
  • Did you resolve this issue? I’m facing what I think is the same problem – grg May 02 '21 at 10:39

0 Answers0