Post

Replies

Boosts

Views

Activity

PhotosPicker doesn’t appear when declared inside Menu
PhotosPicker in iOS 16 can be declared only with a separate trigger view. If this view is a part of regular view, then it’s OK. But if it’s declared in Menu as one of the options, then it doesn’t appear after triggering (Xcode 14 beta 5). So, this works: struct ContentView: View {     @State private var selectedPhotoItem: PhotosPickerItem?     var body: some View {         PhotosPicker(             selection: $selectedPhotoItem,             matching: .images,             photoLibrary: .shared()          ) {              Image(systemName: "photo.on.rectangle.angled")       }     } } And this is not: struct ContentView: View {     @State private var selectedPhotoItem: PhotosPickerItem?     var body: some View {         Menu {             PhotosPicker(                 selection: $selectedPhotoItem,                 matching: .images,                 photoLibrary: .shared()             ) {                 Label("Photo Library", systemImage: "photo.on.rectangle.angled")             }             Button(“Another action”) { }       } label: { Text("Menu") }     } } The same behaviour we have for ‘toolbar’ in NavigationStack. If PhotosPicker declared directly in ToolbarItem, it’s OK. But if it’s inside Menu of ToolbarItem, then it doesn’t appear after triggering. As I can guess PhotosPicker can’t appear for the same reason as the '.sheet' or '.alert' attached to Button inside Menu. It may be because of disappearing Menu after picking an option. This also won’t work: struct ContentView: View {     @State private var isPresentedSheet = false     var body: some View {         Menu {             Button(“Some action”) { isPresentedSheet = true }                 .sheet(isPresented: $isPresentedSheet) {                     SomeView()                 }             Button(“Another action”) { }         } label: { Text("Menu") }     } } struct SomeView: View {     var body: some View {         Text("Hello")     } } But in this case we can simply shift .sheet modifier up in the view hierarchy and it will work. struct ContentView: View {     @State private var isPresentedSheet = false     var body: some View {         Menu {             Button(“Some action”) { isPresentedSheet = true }             Button(“Another action”) { }         } label: { Text("Menu") }         .sheet(isPresented: $isPresentedSheet) {             SomeView()         }     } } struct SomeView: View {     var body: some View {         Text("Hello")     } } However with PhotosPicker there is no possibility to trigger it outside the Menu anywhere else in ‘body’. It has no ‘isPresented’ parameter or something like that. So the only possibility to show PhotosPicker now is the explicit view, that you can press on the screen - not from Menu. I have a design where PhotosPicker should be triggered from Menu of a Button. And I have no idea, how to show it right now. Is it a bug? Or is it a fundamental limitation of SwiftUI presentation system?
5
5
3.8k
Aug ’22
Picker selection when declared in toolbar Menu seems to be broken (Xcode 14 beta 5)
When selecting an option in Picker declared in Menu in toolbar with this code: struct ContentView: View {     @State private var option: Int = 0     var body: some View {         NavigationStack {             Text("Hello, World")                 .toolbar {                     ToolbarItem {                         Menu {                             Picker("", selection: $option) {                                 Text("Option 0").tag(0)                                 Text("Option 1").tag(1)                             }                         } label: {                             Image(systemName: "star")                         }                     }                 }         }     } } there is no visible change in selecton (checkmark is on the initial option). But the actual change happens - 'option' variable changes. In Xcode 13.4.1 / iOS 15.5 the same code works well (for NavigationView of course). I think this is certainly a bug.
1
0
850
Aug ’22