How to delete Navigation Link > symbol in SwiftUI?

Viewed 671

How to delete Navigation Link > symbol in SwiftUI?


enter image description here

Navigation code

NavigationView{
    List{
        ForEach(messages) { item in
            NavigationLink(destination: MessageDetailView()){
                ChatRowView(chat: item)
                .padding(.vertical,3)
            }
           
        }
     
  
    }
2 Answers

Chevron image of link is injected by List for automatically detected NavigationLink. This is default behavior of List.

The possible solution is to replace NavigationLink inside List with Button and activate NavigationLink programmatically.

Here is a demo of approach. Tested with Xcode 12.4 / iOS 14.4

demo

struct Message: Identifiable, Hashable {
    let id: String
}

struct ContentView: View {
    let messages = [Message(id: "1"), Message(id: "2"), Message(id: "3")]
    @State private var tappedItem: Message?

    var body: some View {
        NavigationView{
            List{
                ForEach(messages) { item in
                    Button(action: { tappedItem = item }) {   // << activate !!
                        Text("Message \(item.id)")
                            .padding(.vertical,3)
                    }
                }
            }
            .background(
                NavigationLink(destination: Text("MessageDetailView \(tappedItem?.id ?? "")"),
                    isActive: Binding(
                        get: { tappedItem != nil },         // << handle !!
                        set: { _,_ in tappedItem = nil }
                    )){
                    EmptyView()
                }
            )
        }
    }
}

You should not use List in this case:


enter image description here

import SwiftUI

struct ContentView: View {
    
    var body: some View {

        NavigationView{
            
            VStack {
                
                ForEach(0..<10) { item in
                    
                    NavigationLink(destination: Text("some text here!")){
                        
                        HStack { Text("Link " + item.description); Spacer() }.padding(.horizontal)
                        
                    }
                    
                    Divider()
                    
                }
                
                Spacer()
                
            }
            .navigationTitle("Hello World!")
            
        }
    }
}
Related