mirror of
https://github.com/appwrite/sdk-for-apple.git
synced 2026-11-18 20:53:33 +00:00
* chore: update Apple SDK to 18.3.0 * chore: update Apple SDK to 18.3.0 * chore: update Apple SDK to 19.0.0 * docs: state the SDK targets Appwrite server version 2.0.x * fix: regenerate with the latest sdk-generator and add auto image gravity
55 lines
1.4 KiB
Swift
55 lines
1.4 KiB
Swift
import SwiftUI
|
|
import UIKit
|
|
|
|
extension ImagePicker: UIViewControllerRepresentable {
|
|
|
|
var sourceType: UIImagePickerController.SourceType {
|
|
return .photoLibrary
|
|
}
|
|
|
|
func makeUIViewController(context: UIViewControllerRepresentableContext<ImagePicker>)
|
|
-> UIImagePickerController
|
|
{
|
|
|
|
let imagePicker = UIImagePickerController()
|
|
imagePicker.allowsEditing = false
|
|
imagePicker.sourceType = sourceType
|
|
imagePicker.delegate = context.coordinator
|
|
|
|
return imagePicker
|
|
}
|
|
|
|
func updateUIViewController(
|
|
_ uiViewController: UIImagePickerController,
|
|
context: UIViewControllerRepresentableContext<ImagePicker>
|
|
) {
|
|
}
|
|
|
|
func makeCoordinator() -> Coordinator {
|
|
Coordinator(self)
|
|
}
|
|
|
|
final class Coordinator: NSObject, UIImagePickerControllerDelegate,
|
|
UINavigationControllerDelegate
|
|
{
|
|
|
|
var parent: ImagePicker
|
|
|
|
init(_ parent: ImagePicker) {
|
|
self.parent = parent
|
|
}
|
|
|
|
func imagePickerController(
|
|
_ picker: UIImagePickerController,
|
|
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]
|
|
) {
|
|
|
|
if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
|
|
parent.selectedImage = image
|
|
}
|
|
|
|
parent.presentationMode.wrappedValue.dismiss()
|
|
}
|
|
}
|
|
}
|