File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed
CameraScanExmaple/CameraScanExmaple/feature Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ struct TakePictureView: View {
2929 VStack {
3030 HStack {
3131 Spacer ( )
32+
3233 SelectPhotoButton ( onSelectedImageAction: { image in
3334 print ( image)
3435 } , content: {
Original file line number Diff line number Diff line change @@ -5,18 +5,22 @@ import UIKit
55// MARK: - ImagePicker
66
77public struct ImagePicker {
8-
8+ private let allowsEditing : Bool
9+ private let sourceType : UIImagePickerController . SourceType
910 private let onSelectedImageAction : ( UIImage ) -> Void
1011 private let onDismissalAction : ( ) -> Void
1112
1213 public init (
14+ allowsEditing: Bool = false ,
15+ sourceType: UIImagePickerController . SourceType = . photoLibrary,
1316 onSelectedImageAction: @escaping ( UIImage ) -> Void ,
1417 onDismissalAction: @escaping ( ) -> Void = { } )
1518 {
19+ self . allowsEditing = allowsEditing
20+ self . sourceType = sourceType
1621 self . onSelectedImageAction = onSelectedImageAction
1722 self . onDismissalAction = onDismissalAction
1823 }
19-
2024}
2125
2226
@@ -26,8 +30,8 @@ extension ImagePicker: UIViewControllerRepresentable {
2630
2731 public func makeUIViewController( context: Context ) -> some UIViewController {
2832 let controller = UIImagePickerController ( )
29- controller. allowsEditing = false
30- controller. sourceType = . photoLibrary
33+ controller. allowsEditing = allowsEditing
34+ controller. sourceType = sourceType
3135 controller. delegate = context. coordinator
3236
3337 return controller
Original file line number Diff line number Diff line change @@ -9,10 +9,17 @@ public struct SelectPhotoButton<Content: View> {
99 private let onSelectedImageAction : ( UIImage ) -> Void
1010 @State private var isShowImagePicker : Bool = false
1111
12+ private let allowsEditing : Bool
13+ private let sourceType : UIImagePickerController . SourceType
14+
1215 public init (
16+ allowsEditing: Bool = false ,
17+ sourceType: UIImagePickerController . SourceType = . photoLibrary,
1318 onSelectedImageAction: @escaping ( UIImage ) -> Void ,
1419 @ViewBuilder content: ( ) -> Content )
1520 {
21+ self . allowsEditing = allowsEditing
22+ self . sourceType = sourceType
1623 self . onSelectedImageAction = onSelectedImageAction
1724 self . content = content ( )
1825 }
@@ -32,6 +39,8 @@ extension SelectPhotoButton: View {
3239 isPresented: $isShowImagePicker,
3340 content: {
3441 ImagePicker (
42+ allowsEditing: allowsEditing,
43+ sourceType: sourceType,
3544 onSelectedImageAction: onSelectedImageAction,
3645 onDismissalAction: { isShowImagePicker = false } )
3746 } )
You can’t perform that action at this time.
0 commit comments