You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Only for the initial render, BSImagePicker does not seem to display the images that Core UIKit UIImagePickerController has provided access to. Re-opening the BSImagePicker does however display them.
I've included the SwiftUI code and a .mov file showing this behavior. How can developers make the initial display of the selected images identical to the behavior when BSImagePicker is re-opened?
Thank you for your help, and thank you for developing this piece of software.
BSImagePicker_Issue.mov
structContentView:View{@StateObjectvarimagePickerCoordinatorView=ImagePickerCoordinatorView()@StatevarisPresentedImagePicker= false
varbody:someView{Button("Open BSImagePicker"){self.isPresentedImagePicker = true
}.sheet(isPresented:self.$isPresentedImagePicker, content:{
imagePickerCoordinatorView
})
if let list = imagePickerCoordinatorView.selectedAssets {Text("\(list.count) images selected")}else{Text("No images selected")}}}
//// ImagePickerCoordinatorView.swift
import SwiftUI
import Photos
import BSImagePicker
finalclassImagePickerCoordinatorView:NSObject,ObservableObject{@Environment(\.presentationMode)varpresentationMode:Binding<PresentationMode>@PublishedvarselectedAssets:[PHAsset]?{
didSet {print("New value of selectedAssets is \(selectedAssets)")}}func dismiss(){self.presentationMode.wrappedValue.dismiss()}func clearSelectedAssets(){self.selectedAssets =[PHAsset]()}}extensionImagePickerCoordinatorView:UIViewControllerRepresentable{publictypealiasUIViewControllerType=ImagePickerControllerpublicfunc makeUIViewController(context:Context)->ImagePickerController{letpicker=ImagePickerController()
picker.settings.selection.max =10
picker.settings.selection.unselectOnReachingMax = false
picker.settings.theme.selectionStyle =.numbered
picker.settings.fetch.assets.supportedMediaTypes =[.image]
picker.imagePickerDelegate = context.coordinator
return picker
}publicfunc updateUIViewController(_ uiViewController:ImagePickerController, context:Context){}publicfunc makeCoordinator()->Coordinator{returnCoordinator(self)}}extensionImagePickerCoordinatorView{publicclassCoordinator:ImagePickerControllerDelegate{privateletparent:ImagePickerCoordinatorViewpublicinit(_ parent:ImagePickerCoordinatorView){self.parent = parent
}publicfunc imagePicker(_ imagePicker:ImagePickerController, didSelectAsset asset:PHAsset){print("Selected: \(asset)")}publicfunc imagePicker(_ imagePicker:ImagePickerController, didDeselectAsset asset:PHAsset){print("Deselected: \(asset)")}publicfunc imagePicker(_ imagePicker:ImagePickerController, didFinishWithAssets assets:[PHAsset]){print("Finished with selections: \(assets)")
parent.selectedAssets = assets
parent.dismiss()}publicfunc imagePicker(_ imagePicker:ImagePickerController, didCancelWithAssets assets:[PHAsset]){print("Canceled with selections: \(assets)")
if (assets.count ==0){print("Canceled with no selection so setting selectedAssets to empty")
parent.selectedAssets?.removeAll()}
parent.dismiss()}publicfunc imagePicker(_ imagePicker:ImagePickerController, didReachSelectionLimit count:Int){print("Did Reach Selection Limit: \(count)")}}}
The text was updated successfully, but these errors were encountered:
test-ArG5R4aR78
changed the title
SwiftUI - Initial Selection from ImagePickerController Does Not Appear
SwiftUI - Initial Selection from UIImagePickerController Does Not Appear
Mar 14, 2021
If you are using the delegate and presenting the image picker yourself you also need to request permission to the photo library before presenting the picker.
Hello,
Only for the initial render, BSImagePicker does not seem to display the images that Core UIKit UIImagePickerController has provided access to. Re-opening the BSImagePicker does however display them.
I've included the SwiftUI code and a .mov file showing this behavior. How can developers make the initial display of the selected images identical to the behavior when BSImagePicker is re-opened?
I am using 750f26a git ref. Tag 3.3.1.
Thank you for your help, and thank you for developing this piece of software.
BSImagePicker_Issue.mov
The text was updated successfully, but these errors were encountered: