0

This is a problem on iOS 15 RC only. It works all good on iOS 14.

The problem is if my destination on NavigationLink is created dynamically, it pop automatically if i try push a view via NavigationLink. Here is a bit code snippet

 NavigationLink(
     destination: (createSettingNavigationLink(name: nameAndImage[0])),
     label: {
         CellButton(title: nameAndImage[0], image: nameAndImage[1])
     }

func createSettingNavigationLink(name: String) -> some View {
        if name == "shop.Settings" {
            return ShopSettings()
        }
        if name == "shop.Goods" {
            return ShopGoodsManagementPage()
        }
        if name == "shop.Order" {
            return ShopOrderPage()
        }
        if name == "Customer Service" {
            return ServiceListPage(isStore: true)
        }
        if name == "shop.Performance" {
            return PerformanceManagementPage()
        }
        if name == "shop.Earnings" {
            return CommissionSummaryPage()
        }
        if name == "shop.Increase_sales" {
            return BCWebView(urlStr: Constants.increaseSalesGuide)
                    .navigationBarTitle(Text("Increase Sales Guide"), displayMode: .inline)
                    .navigationBarHidden(false)
            )
        }
        return EmptyView()
    }

)


By the way, the approach mentioned here SwiftUI Unexpectedly NavigationLink pops automatically does not help.

LiangWang
  • 8,038
  • 8
  • 41
  • 54
  • Just a tip - give `createSettingNavigationLink` a `some View` return type, use `switch name { ... }`, and then you can remove the `return`s and `AnyView`s. – George Sep 17 '21 at 22:52
  • 1
    It would be helpful to have a [mre]. What you have here won't compile for anyone else. – jnpdx Sep 17 '21 at 23:15
  • @LiangWang: Why AnyView? why not View? why so many if? why not Switch? or why not a dic even? – ios coder Sep 17 '21 at 23:22
  • Thanks, I have removed the AnyView. However, my key point is why my case does not work in iOS 15 ( can compile but just not behavior right) – LiangWang Sep 17 '21 at 23:29
  • I've made some test code similar to your snippet, but cannot replicate your issue (I can show the test code if interested). All works well on ios-15 RC, using Xcode 13-beta (not Xcode 13-RC). Maybe your issue has to do with some other code/context that is not shown. – workingdog support Ukraine Sep 18 '21 at 01:47

1 Answers1

0

My final solution is to change the above function to struct view. I think it makes sense since the struct view seems to keep states while function is pure stateless.

LiangWang
  • 8,038
  • 8
  • 41
  • 54