-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow 3rd party apps to inject their existing image editors to the Qu…
…ickEditor (#375)
- Loading branch information
Showing
10 changed files
with
203 additions
and
62 deletions.
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
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,37 @@ | ||
import SwiftUI | ||
import GravatarUI | ||
|
||
struct TestImageCropper: View, ImageEditorView { | ||
var inputImage: UIImage | ||
var editingDidFinish: ((UIImage) -> Void) | ||
|
||
init(inputImage: UIImage, editingDidFinish: @escaping (UIImage) -> Void) { | ||
self.inputImage = inputImage | ||
self.editingDidFinish = editingDidFinish | ||
} | ||
|
||
var body: some View { | ||
Text("This is a dummy image cropper for solely test purposes. It doesn't do anything. It just passes the image as it is when the button is tapped.") | ||
.padding() | ||
Image(uiImage: inputImage) | ||
.resizable() | ||
.aspectRatio(contentMode: .fit) | ||
.frame(height: 100) | ||
Button(action: cropImage) { | ||
Text("Crop Image") | ||
.foregroundColor(.white) | ||
.padding() | ||
.background(Color.blue) | ||
.cornerRadius(10) | ||
} | ||
} | ||
|
||
private func cropImage() { | ||
editingDidFinish(inputImage) | ||
} | ||
} | ||
|
||
#Preview { | ||
TestImageCropper(inputImage: UIImage()) { _ in } | ||
} | ||
|
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
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
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
29 changes: 29 additions & 0 deletions
29
Sources/GravatarUI/SwiftUI/AvatarPicker/ImageEditorView.swift
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,29 @@ | ||
import Foundation | ||
import SwiftUI | ||
|
||
/// Describes an image editor to be used after picking the image from the photo picker. | ||
/// Caution: The output needs to be a square image; otherwise, the Gravatar backend will not accept it. | ||
public protocol ImageEditorView: View { | ||
/// The image to edit. | ||
var inputImage: UIImage { get } | ||
|
||
/// Callback to call when the editing is done. Pass the edited image here. | ||
var editingDidFinish: (UIImage) -> Void { get set } | ||
} | ||
|
||
public typealias ImageEditorBlock<ImageEditor: ImageEditorView> = (UIImage, _ editingDidFinish: @escaping (UIImage) -> Void) -> ImageEditor | ||
|
||
/// Because of how generics work, the compiler must resolve the image editor's concrete type. | ||
/// When its value is `nil` though, the compiler can't resolve the concrete type, and it complains. This type here is used to make the compiler happy when the | ||
/// passed value is `nil`. | ||
public struct NoCustomEditor: ImageEditorView { | ||
public var inputImage: UIImage | ||
public var editingDidFinish: (UIImage) -> Void | ||
|
||
public var body: some View { | ||
EmptyView() | ||
} | ||
} | ||
|
||
/// This exists for the same reason with `NoCustomEditor`. | ||
public typealias NoCustomEditorBlock = (UIImage, _ editingDidFinish: @escaping (UIImage) -> Void) -> NoCustomEditor |
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
Oops, something went wrong.