Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to navigate from one screen to another in SwiftUI Apple Watch App

I'm having problems doing navigation in a SwiftUI Apple Watch app. There's minimal resources online regarding this.

I mostly understand how to create SwiftUI views, but I'm not sure what the best way to navigate from SwiftUI view to another SwiftUI view is.

Is there a way to push a user to another SwiftUI screen when they tap a button?

like image 746
Ryan Avatar asked Jul 26 '19 15:07

Ryan


1 Answers

To provide a very basic example how it can work on watchOS.

struct ListView: View {
var body: some View {



    List{

        RowView(title: "Row 1")
        RowView(title: "Row 2")
        RowView(title: "Row 3")
        RowView(title: "Row 4")

    }
    .listStyle(.carousel)


    }
}
struct RowView: View {
    let title: String
    var body: some View {

    NavigationLink(destination: Text("Detail \(title)")) {

        Text(title)
            .frame(height: 80, alignment: .topTrailing)
            .listRowBackground(
                Color.blue
                    .cornerRadius(12)
        )
    }
}

}

like image 126
Marc T. Avatar answered Sep 23 '22 14:09

Marc T.