-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ :: [#62] Add ImagePicker Extension
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// ImagePicker.swift | ||
// Expo-iOS | ||
// | ||
// Created by 서지완 on 11/14/24. | ||
// Copyright © 2024 SchoolofCompany. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
struct ImagePicker: UIViewControllerRepresentable { | ||
@Binding var selectedImage: UIImage? | ||
@Environment(\.presentationMode) private var presentationMode | ||
|
||
func makeUIViewController(context: UIViewControllerRepresentableContext<ImagePicker>) -> UIImagePickerController { | ||
let picker = UIImagePickerController() | ||
picker.delegate = context.coordinator | ||
return picker | ||
} | ||
|
||
func updateUIViewController(_ uiViewController: UIImagePickerController, context: UIViewControllerRepresentableContext<ImagePicker>) {} | ||
|
||
func makeCoordinator() -> Coordinator { | ||
Coordinator(self) | ||
} | ||
|
||
class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate { | ||
let parent: ImagePicker | ||
|
||
init(_ parent: ImagePicker) { | ||
self.parent = parent | ||
} | ||
|
||
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { | ||
if let image = info[.originalImage] as? UIImage { | ||
parent.selectedImage = image | ||
} | ||
parent.presentationMode.wrappedValue.dismiss() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters