Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tabbar iPad App to Sidebar macOS Catalyst app

I am struggling to figure out how to turn my tabbar based iPad app into a sidebar navigation based Catalyst app. Similar to the screenshot that Apple shows:

enter image description here

You can see in the screenshot above the iPad app uses a tabbar layout but the macOS Catalyst app used a left sidebar navigation.

How can I do this and convert my iPad app to use a sidebar in macOS?

like image 218
Nic Hubbard Avatar asked Nov 06 '22 07:11

Nic Hubbard


1 Answers

You can do something like this

#if targetEnvironment(macCatalyst)
    // here use the NavigationView + NavigationLinks to make the sidebar on macOS
#else
    // here use the Tab Bar view. 
#endif

You can use this to create entire alternate views if you need.

For example:

#if targetEnvironment(macCatalyst)
struct MyView: View {
    var body: some View {
        Text("Im in macOS")
    }
}
#else
struct MyView: View {
    var body: some View {
        Text("Im in iOS")
    }
}
#endif
like image 121
Lucas Desouza Avatar answered Nov 14 '22 22:11

Lucas Desouza