Closed lisindima closed 4 years ago
@lisindima I have yet to dive into SwiftUI, so I'm not sure I understand the issue.
Thanks for the answer, I would like to see instructions on how to run this component in swiftui, I'm not sure if this can be done using UIViewControllerRepresentable
Makes sense, I will see if I can test it this week.
Hi, I was able to run this component on SwiftUI and it works fine)
import SwiftUI
import UnsplashPhotoPicker
struct UnsplashImagePicker: UIViewControllerRepresentable {
var urlUnsplashImage = [UnsplashPhoto]()
let configuration = UnsplashPhotoPickerConfiguration(
accessKey: "accessKey",
secretKey: "accessKey",
allowsMultipleSelection: false)
func makeUIViewController(context: UIViewControllerRepresentableContext<UnsplashImagePicker>) -> UnsplashPhotoPicker {
let unsplashPhotoPicker = UnsplashPhotoPicker(configuration: configuration)
unsplashPhotoPicker.photoPickerDelegate = context.coordinator
return unsplashPhotoPicker
}
func makeCoordinator() -> UnsplashImagePicker.Coordinator {
return Coordinator(self)
}
class Coordinator: UnsplashPhotoPickerDelegate {
var parent: UnsplashImagePicker
init(_ parent: UnsplashImagePicker) {
self.parent = parent
}
func unsplashPhotoPicker(_ photoPicker: UnsplashPhotoPicker, didSelectPhotos photos: [UnsplashPhoto]) {
print(photos)
}
func unsplashPhotoPickerDidCancel(_ photoPicker: UnsplashPhotoPicker) {
print("Unsplash photo picker did cancel")
}
}
func updateUIViewController(_ uiViewController: UnsplashPhotoPicker, context: UIViewControllerRepresentableContext<UnsplashImagePicker>) {
}
}
and yet there is a problem with this code, the unsplashPhotoPicker function does not work completely, respectively, it is not possible to select an image and nil always returns
Update: Returning to this problem, I found a small error, now everything works, all the information about the photo is also returned. I updated the code above, suddenly it will be needed!
Great! Thank you for taking a shot at it! 👏
Add support for SwiftUI