Post

Replies

Boosts

Views

Activity

Compiler directives in SwiftUI for platform-specific attributes
I'm building a universal application with SwiftUI that has an iOS app and Share Extension as well as a macOS app and Share Extension. There's a few places where I'm using SwiftUI attributes that are iOS-specific (example a NavigationView that has a StackNavigationViewStyle attribute) and need to provide an alternative when running on macOS. My question is: How do I ensure that these attributes that are only available for one platform don't cause build issues for the other platform? I've tried using the #if os(iOS) compiler directive, but then I get a build error saying "Unexpected platform condition (expected 'os' 'arch' or 'swift')" when doing something like this: 				NavigationView { 						... 				}         #if os(iOS)			 				.navigationViewStyle(StackNavigationViewStyle())         #endif
4
0
6.1k
Jul ’20
Set minimum width for SidebarListStyle on macOS
I'm running into an issue with the SidebarListStyle on macOS. Because I'm using this style for the List, the sidebar divider is draggable, and you can drag it all the way left and hide the sidebar entirely (and it won't come back and I have to remove the app and preferences for it to be visible again). I'm setting a minimum value on the frame of the sidebar like this; however, it doesn't seem to be respected when running the app:         NavigationView {             sidebar                 .frame(minWidth: 200, idealWidth: 200, maxWidth: 400, maxHeight: .infinity)         }     } Is there a way to (a) Be able to specify a minimum width for the SideBarListStyle when presented in a NavigationView on macOS and (b) if the user is able to drag the divider to hide the SideBarListStyle, is there a way to programmatically unhide it when it's been hidden by the user?
2
0
1.6k
Aug ’20