Skip to content

Commit

Permalink
Merge pull request #20 from wordpress-mobile/issue/add_draw_operation
Browse files Browse the repository at this point in the history
Add Draw Operation
  • Loading branch information
leandroalonso authored May 14, 2020
2 parents 324261b + abc8347 commit dc67739
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion MediaEditor.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'MediaEditor'
s.version = '1.1.0-beta.1'
s.version = '1.1.0-beta.2'
s.summary = 'An extensible Media Editor for iOS.'

s.description = <<-DESC
Expand Down
5 changes: 3 additions & 2 deletions Sources/Capabilities/Drawing/MediaEditorDrawing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ class MediaEditorDrawing: UIViewController {
}

@IBAction func done(_ sender: Any) {
guard let image = annotationView.image else {
guard annotationView.canUndo,
let image = annotationView.image else {
onCancel?()
return
}

onFinishEditing?(image, [.other])
onFinishEditing?(image, [.draw])
}
}

Expand Down
1 change: 1 addition & 0 deletions Sources/Enums/MediaEditorOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public enum MediaEditorOperation {
case rotate
case filter
case other
case draw
}
15 changes: 12 additions & 3 deletions Tests/Capabilities/Drawing/MediaEditorDrawingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ class MediaEditorDrawingTests: XCTestCase {
let mediaEditorDrawing = MediaEditorDrawing.initialize(image, onFinishEditing: { finishedImage, _ in
result = finishedImage
}, onCancel: {}) as! MediaEditorDrawing
let annotationViewMock = MediaEditorAnnotationViewMock()

mediaEditorDrawing.loadView()
mediaEditorDrawing.annotationView = annotationViewMock
mediaEditorDrawing.viewDidLoad()
mediaEditorDrawing.done(self)

Expand All @@ -70,17 +72,17 @@ class MediaEditorDrawingTests: XCTestCase {

func testModifiedImageIsReturnedIfChangesAreMade() {
let image = UIImage(systemName: "arrowshape.turn.up.left")!
let drawingUrl = Bundle(for: MediaEditorDrawingTests.self).url(forResource: "demo-drawing", withExtension: nil)!
let drawingData = try! Data(contentsOf: drawingUrl)

var result: UIImage? = nil
let mediaEditorDrawing = MediaEditorDrawing.initialize(image, onFinishEditing: { finishedImage, _ in
result = finishedImage
}, onCancel: {}) as! MediaEditorDrawing
let annotationViewMock = MediaEditorAnnotationViewMock()
annotationViewMock.image = UIImage()

mediaEditorDrawing.loadView()
mediaEditorDrawing.viewDidLoad()
mediaEditorDrawing.annotationView.drawingData = drawingData
mediaEditorDrawing.annotationView = annotationViewMock
mediaEditorDrawing.view.setNeedsLayout()
mediaEditorDrawing.view.layoutIfNeeded()

Expand All @@ -98,3 +100,10 @@ class MediaEditorDrawingTests: XCTestCase {
expect(mediaEditorDrawing.redoButton.isEnabled).to(beFalse())
}
}

@available(iOS 13.0, *)
private class MediaEditorAnnotationViewMock: MediaEditorAnnotationView {
override var canUndo: Bool {
return true
}
}

0 comments on commit dc67739

Please sign in to comment.