Post

Replies

Boosts

Views

Activity

PhotosPicker half size
I want to display a PhotosPicker in "half size " with the .presentationDetents([.medium, .large]) approach, but I cannot make it work. Here is a code example. If you run the example you will see that the bottom button opens a sheet in half screen. The top button will open the PhotosPicker, but not in "half size". Any help or info is greatly appreciated. import SwiftUI import PhotosUI struct ContentView: View {   @State private var showingGreeting = false   @State private var selectedItem: PhotosPickerItem? = nil   @State private var selectedImageData: Data? = nil   var body: some View {     VStack {       PhotosPicker(         selection: $selectedItem,         matching: .images,         photoLibrary: .shared()) {           Text("Open PhotosPicker")             .presentationDetents([.medium, .large])         }         .onChange(of: selectedItem) { newItem in           Task {             // Retrieve selected asset in the form of Data             if let data = try? await newItem?.loadTransferable(type: Data.self)             {               selectedImageData = data             }           }         }       if let selectedImageData,         let uiImage = UIImage(data: selectedImageData) {         Image(uiImage: uiImage)           .resizable()           .scaledToFit()           .frame(width: 250, height: 250)       }       Divider()       Button("Open sheet in half screen") {         showingGreeting.toggle()       }       .sheet(isPresented: $showingGreeting) {         Text("Hello there!")           .presentationDetents([.medium, .large])       }     }   } } struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView()   } }
1
0
1.2k
Aug ’22
PhotosPicker half size
I want to display a PhotosPicker in "half size " with the .presentationDetents([.medium, .large]) approach, but I cannot make it work. Here is a code example. If you run the example you will see that the bottom button opens a sheet in half screen. The top button will open the PhotosPicker, but not in "half size". Any help or info is greatly appreciated. import SwiftUI import PhotosUI struct ContentView: View {   @State private var showingGreeting = false   @State private var selectedItem: PhotosPickerItem? = nil   @State private var selectedImageData: Data? = nil   var body: some View {     VStack {       PhotosPicker(         selection: $selectedItem,         matching: .images,         photoLibrary: .shared()) {           Text("Open PhotosPicker")             .presentationDetents([.medium, .large])         }         .onChange(of: selectedItem) { newItem in           Task {             // Retrieve selected asset in the form of Data             if let data = try? await newItem?.loadTransferable(type: Data.self)             {               selectedImageData = data             }           }         }       if let selectedImageData,         let uiImage = UIImage(data: selectedImageData) {         Image(uiImage: uiImage)           .resizable()           .scaledToFit()           .frame(width: 250, height: 250)       }       Divider()       Button("Open sheet in half screen") {         showingGreeting.toggle()       }       .sheet(isPresented: $showingGreeting) {         Text("Hello there!")           .presentationDetents([.medium, .large])       }     }   } } struct ContentView_Previews: PreviewProvider {   static var previews: some View {     ContentView()   } }
Replies
1
Boosts
0
Views
1.2k
Activity
Aug ’22