Skip to content

Commit

Permalink
Remove deprecated declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
wiruzx committed Apr 8, 2019
1 parent 9e5af06 commit 99a2812
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 52 deletions.
16 changes: 3 additions & 13 deletions ChattoAdditions/Source/Input/Photos/PhotosChatInputItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ open class PhotosChatInputItem: ChatInputItemProtocol {

typealias Class = PhotosChatInputItem

public var photoInputHandler: ((UIImage) -> Void)?
public var photoWithSourceInputHandler: ((UIImage, PhotosInputViewPhotoSource) -> Void)?
public var photoInputHandler: ((UIImage, PhotosInputViewPhotoSource) -> Void)?
public var cameraPermissionHandler: (() -> Void)?
public var photosPermissionHandler: (() -> Void)?
public weak var presentingController: UIViewController?
Expand Down Expand Up @@ -93,24 +92,15 @@ open class PhotosChatInputItem: ChatInputItemProtocol {
return self.internalTabView
}

open func handleInput(_ input: AnyObject) {
if let image = input as? UIImage {
self.photoInputHandler?(image)
}
}
open func handleInput(_ input: AnyObject) {}
}

// MARK: - PhotosInputViewDelegate
extension PhotosChatInputItem: PhotosInputViewDelegate {
public func inputView(_ inputView: PhotosInputViewProtocol, didSelectImage image: UIImage) {
self.photoInputHandler?(image)
}

public func inputView(_ inputView: PhotosInputViewProtocol,
didSelectImage image: UIImage,
source: PhotosInputViewPhotoSource) {
self.photoInputHandler?(image)
self.photoWithSourceInputHandler?(image, source)
self.photoInputHandler?(image, source)
}

public func inputViewDidRequestCameraPermission(_ inputView: PhotosInputViewProtocol) {
Expand Down
20 changes: 4 additions & 16 deletions ChattoAdditions/Source/Input/Photos/PhotosInputView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,14 @@ public enum PhotosInputViewPhotoSource {
case gallery
}

public protocol PhotosInputViewDelegate: class {
@available(*, deprecated, renamed: "inputView(_:didSelectImage:source:)")
func inputView(_ inputView: PhotosInputViewProtocol, didSelectImage image: UIImage)
/// If you implement this method, deprecated one will not be called
func inputView(_ inputView: PhotosInputViewProtocol, didSelectImage image: UIImage, source: PhotosInputViewPhotoSource)
public protocol PhotosInputViewDelegate: AnyObject {
func inputView(_ inputView: PhotosInputViewProtocol,
didSelectImage image: UIImage,
source: PhotosInputViewPhotoSource)
func inputViewDidRequestCameraPermission(_ inputView: PhotosInputViewProtocol)
func inputViewDidRequestPhotoLibraryPermission(_ inputView: PhotosInputViewProtocol)
}

extension PhotosInputViewDelegate {
public func inputView(_ inputView: PhotosInputViewProtocol, didSelectImage image: UIImage) {
fatalError("Please implement inputView(_:didSelectImage:source:)")
}
public func inputView(_ inputView: PhotosInputViewProtocol,
didSelectImage image: UIImage,
source: PhotosInputViewPhotoSource) {
self.inputView(inputView, didSelectImage: image)
}
}

public final class PhotosInputView: UIView, PhotosInputViewProtocol {

fileprivate struct Constants {
Expand Down
25 changes: 2 additions & 23 deletions ChattoAdditions/Tests/Input/PhotosChatInputItemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,40 +40,19 @@ class PhotosChatInputItemTests: XCTestCase {
XCTAssertFalse(self.inputItem.showsSendButton)
}

func testThat_GivenItemHasPhotoInputHandler_WhenInputIsImage_ItemHandlesInput() {
var handled = false
self.inputItem.photoInputHandler = { image in
handled = true
}
self.inputItem.handleInput(UIImage())
XCTAssertTrue(handled)
}

func testThat_GivenItemHasPhotoInputHandler_WhenInputIsNotImage_ItemDoesntHandleInput() {
var handled = false
self.inputItem.photoInputHandler = { image in
self.inputItem.photoInputHandler = { image, _ in
handled = true
}
self.inputItem.handleInput(5 as AnyObject)
XCTAssertFalse(handled)
}

func testThat_WhenInputViewSelectsImage_ItemPassedImageIntoPhotoHandler() {
var handledImage: UIImage?
self.inputItem.photoInputHandler = { image in
handledImage = image
}
let image = UIImage()
let inputView = MockPhotosInputView()
self.inputItem.inputView(inputView, didSelectImage: image)

XCTAssertEqual(handledImage!, image)
}

func testThat_WhenInputViewSelectsImageWithSource_ThenItemPassedImageAndSourceIntoPhotoWithSourceHandler() {
var handledImage: UIImage?
var handledSource: PhotosInputViewPhotoSource?
self.inputItem.photoWithSourceInputHandler = { image, source in
self.inputItem.photoInputHandler = { image, source in
handledImage = image
handledSource = source
}
Expand Down

0 comments on commit 99a2812

Please sign in to comment.