Home > Mobile >  Prevent a macOS bar from having a sidebar
Prevent a macOS bar from having a sidebar

Time:06-21

By default the first list added to a view seems to be set to sidebar. Even if you don't specifically call .listStyle(SidebarListStyle()).

Is there any way that the list you set on the view (even if it's the first view) is not set to a sidebar? There is no indication on the Apple's documentation, and anything I have tried to style the list is not working.

So instead of the list looking like this

enter image description here

it should look like

enter image description here

Thanks for the help.

EDIT: Yes, code. Any simple code will do.

struct ContentView: View {
    var body: some View {
        List {
                NavigationLink(
                    destination: TextEView(),
                ) {
                    Text("One")
                }
        }
    }    
}

struct TextEView: View {
    @State private var fullText: String = "This is some editable text..."
    var body: some View {        
         TextEditor(text: $fullText)
    }
}

CodePudding user response:

For your case try

    List {
            NavigationLink(
                destination: TextEView(),
            ) {
                Text("One")
            }
    }
    .listStyle(.plain) // << here !!
  • Related