Skip to content

Commit

Permalink
fix allowEditedImage
Browse files Browse the repository at this point in the history
  • Loading branch information
tsuzukihashi committed Dec 21, 2022
1 parent 83a5182 commit a9eb667
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
5 changes: 1 addition & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import PackageDescription
let package = Package(
name: "ImagePickerSwiftUI",
platforms: [
.iOS(.v13),
.macOS(.v10_15),
.watchOS(.v6),
.tvOS(.v13)
.iOS(.v13)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
Expand Down
14 changes: 8 additions & 6 deletions Sources/ImagePickerSwiftUI/ImagePickerSwiftUI.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import SwiftUI

@available(iOS 13.0, *)
@available(tvOS 13.0, *)
@available(watchOS 6.0, *)
@available(OSX 10.15, *)
public struct ImagePickerSwiftUI: UIViewControllerRepresentable {
@Environment(\.presentationMode) private var presentationMode
@Binding var selectedImage: UIImage?
Expand Down Expand Up @@ -51,10 +48,15 @@ public struct ImagePickerSwiftUI: UIViewControllerRepresentable {
}

public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {

parent.selectedImage = parent.croppingToSquare ? image.croppingToSquare() : image
if parent.allowsEditing {
if let image = info[UIImagePickerController.InfoKey.editedImage] as? UIImage {
parent.selectedImage = image
}
} else {
if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
parent.selectedImage = parent.croppingToSquare ? image.croppingToSquare() : image
}
}

parent.presentationMode.wrappedValue.dismiss()
Expand Down

0 comments on commit a9eb667

Please sign in to comment.