File tree Expand file tree Collapse file tree 2 files changed +50
-1
lines changed
FunForYou/FunForYou/Sources
Presentation/Daily/DailyWriting Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Original file line number Diff line number Diff line change
1
+ //
2
+ // Untitled.swift
3
+ // FunForYou
4
+ //
5
+ // Created by 배현진 on 6/4/25.
6
+ //
7
+ import PhotosUI
8
+ import SwiftUI
9
+
10
+ struct PhotoPicker : UIViewControllerRepresentable {
11
+ @Binding var selectedImage : UIImage ?
12
+
13
+ func makeUIViewController( context: Context ) -> PHPickerViewController {
14
+ var config = PHPickerConfiguration ( )
15
+ config. selectionLimit = 1
16
+ config. filter = . images
17
+
18
+ let picker = PHPickerViewController ( configuration: config)
19
+ picker. delegate = context. coordinator
20
+ return picker
21
+ }
22
+
23
+ func updateUIViewController( _ uiViewController: PHPickerViewController , context: Context ) { }
24
+
25
+ func makeCoordinator( ) -> Coordinator {
26
+ Coordinator ( self )
27
+ }
28
+
29
+ class Coordinator : NSObject , PHPickerViewControllerDelegate {
30
+ let parent : PhotoPicker
31
+
32
+ init ( _ parent: PhotoPicker ) {
33
+ self . parent = parent
34
+ }
35
+
36
+ func picker( _ picker: PHPickerViewController , didFinishPicking results: [ PHPickerResult ] ) {
37
+ picker. dismiss ( animated: true )
38
+
39
+ guard let itemProvider = results. first? . itemProvider,
40
+ itemProvider. canLoadObject ( ofClass: UIImage . self) else { return }
41
+
42
+ itemProvider. loadObject ( ofClass: UIImage . self) { image, _ in
43
+ DispatchQueue . main. async {
44
+ self . parent. selectedImage = image as? UIImage
45
+ }
46
+ }
47
+ }
48
+ }
49
+ }
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ struct DailyWritingView: View {
29
29
)
30
30
}
31
31
. sheet ( isPresented: $viewModel. state. isShowImagePicker) {
32
- // TODO: - 이미지 picker 구현해서 띄우기
32
+ PhotoPicker ( selectedImage : $viewModel . state . selectedImage )
33
33
}
34
34
. hideKeyboardOnTap ( )
35
35
}
You can’t perform that action at this time.
0 commit comments