1

I have this View

NavigationView {
                 GeometryReader { geometry in

                    List {
                        ForEach(self.viewModel.items) { item in
                            HStack(spacing: 0, content:  {
                                ZStack {
                                    RowItemView(data: item.FirstItem)
                                    NavigationLink(destination: CustomView(data: item.FirstItem))
                                    {
                                        EmptyView()
                                    }

                                }
                                .frame(width: geometry.size.width / 2, alignment: .center)

                                if (item.SecondItem != nil)  {
                                    ZStack {
                                            RowItemView(data: item.SecondItem!)
                                    NavigationLink(destination: CustomView(data: item.SecondItem!))
                                    {
                                        EmptyView()
                                    }
                                }
                            })
                        }.listRowInsets(EdgeInsets())
                    }
                }

I want to hide the disclouse arrow of the NavigationView. I try to add .buttonStyle(PlainButtonStyle()) or add a negative trailing to the navigationLink, but it doesn't change.

I have already read this question and this one but they do not work in my case, probably because I'm creating a grid and not a plain list.

2 Answers2

1

In this scenario the possible approach is to use zero frame, as following

NavigationLink(destination: CustomView(data: item.FirstItem)) {
    EmptyView()
}.frame(width: 0)
Asperi
  • 228,894
  • 20
  • 464
  • 690
  • Hi, Thanks for the reply. It not works :-( The arrow is shift to the center of the view. – LucaFongaro Feb 14 '20 at 09:37
  • @LucaFongaro, that's strange. Is there any environment specific? I tested it with Xcode 11.2 / iOS 13.2 and it works. – Asperi Feb 14 '20 at 09:40
  • Hi. I have XCode 11.3.1. The arrow still show in Preview and on the device (iPhone 7 / iOS 13.3.1) The problem maybe is in this line of code `.listRowInsets(EdgeInsets())` If I remove it or pass it a non-zero Edge it works (also it isn't necessary to put the frame with 0 width) I hope Apple will create a simple API to hide the arrow :-/ EDIT With this `listRowInsets(EdgeInsets.init(top: 8, leading: 0, bottom: 8, trailing: 0))` It works. Thanks for your help. You put me in the right direction – LucaFongaro Feb 14 '20 at 13:29
0

Thanks to @Asperi I figured out what is the problem.

With a zero EdgeInsets in listRowInsets the arrow still show.

So I create this trick (Works in Xcode 13.3.1)

List {
    ForEach(self.viewModel.items) { item in
        //code for creating the row
    }.listRowInsets(EdgeInsets.init(top: 8, leading: 0, bottom: 8, trailing: 0))

Put a value for both top and bottom.

I do not know if it is the correct way to get rid of that annoying arrow, but for my app it works :-)