Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to react on different states of UILongPressGestureRecog… #125

Merged
merged 1 commit into from
May 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public protocol BaseMessageInteractionHandlerProtocol {
associatedtype ViewModelT
func userDidTapOnFailIcon(viewModel viewModel: ViewModelT)
func userDidTapOnBubble(viewModel viewModel: ViewModelT)
func userDidLongPressOnBubble(viewModel viewModel: ViewModelT)
func userDidBeginLongPressOnBubble(viewModel viewModel: ViewModelT)
func userDidEndLongPressOnBubble(viewModel viewModel: ViewModelT)
}

public class BaseMessagePresenter<BubbleViewT, ViewModelBuilderT, InteractionHandlerT where
Expand Down Expand Up @@ -102,9 +103,13 @@ public class BaseMessagePresenter<BubbleViewT, ViewModelBuilderT, InteractionHan
guard let sSelf = self else { return }
sSelf.onCellBubbleTapped()
}
cell.onBubbleLongPressed = { [weak self] (cell) in
cell.onBubbleLongPressBegan = { [weak self] (cell) in
guard let sSelf = self else { return }
sSelf.onCellBubbleLongPressed()
sSelf.onCellBubbleLongPressBegan()
}
cell.onBubbleLongPressEnded = { [weak self] (cell) in
guard let sSelf = self else { return }
sSelf.onCellBubbleLongPressEnded()
}
cell.onFailedButtonTapped = { [weak self] (cell) in
guard let sSelf = self else { return }
Expand Down Expand Up @@ -160,8 +165,12 @@ public class BaseMessagePresenter<BubbleViewT, ViewModelBuilderT, InteractionHan
self.interactionHandler?.userDidTapOnBubble(viewModel: self.messageViewModel)
}

public func onCellBubbleLongPressed() {
self.interactionHandler?.userDidLongPressOnBubble(viewModel: self.messageViewModel)
public func onCellBubbleLongPressBegan() {
self.interactionHandler?.userDidBeginLongPressOnBubble(viewModel: self.messageViewModel)
}

public func onCellBubbleLongPressEnded() {
self.interactionHandler?.userDidEndLongPressOnBubble(viewModel: self.messageViewModel)
}

public func onCellFailedButtonTapped() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,17 +312,19 @@ public class BaseMessageCollectionViewCell<BubbleViewType where BubbleViewType:U
self.onBubbleTapped?(cell: self)
}

public var onBubbleLongPressed: ((cell: BaseMessageCollectionViewCell) -> Void)?
public var onBubbleLongPressBegan: ((cell: BaseMessageCollectionViewCell) -> Void)?
public var onBubbleLongPressEnded: ((cell: BaseMessageCollectionViewCell) -> Void)?
@objc
private func bubbleLongPressed(longPressGestureRecognizer: UILongPressGestureRecognizer) {
if longPressGestureRecognizer.state == .Began {
self.bubbleLongPressed()
switch longPressGestureRecognizer.state {
case .Began:
self.onBubbleLongPressBegan?(cell: self)
case .Ended, .Cancelled:
self.onBubbleLongPressEnded?(cell: self)
default:
break
}
}

func bubbleLongPressed() {
self.onBubbleLongPressed?(cell: self)
}
}

struct BaseMessageLayoutModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@ class BaseMessagePresenterTests: XCTestCase {
XCTAssertTrue(self.interactionHandler.didHandleTapOnBubble)
}

func testThat_WhenCellIsLongPressedOnBubble_ThenInteractionHandlerHandlesEvent() {
func testThat_WhenCellIsBeginLongPressOnBubble_ThenInteractionHandlerHandlesEvent() {
let cell = PhotoMessageCollectionViewCell(frame: CGRect.zero)
self.presenter.configureCell(cell, decorationAttributes: self.decorationAttributes)
cell.bubbleLongPressed()
XCTAssertTrue(self.interactionHandler.didHandleLongPressOnBubble)
cell.onBubbleLongPressBegan?(cell: cell)
XCTAssertTrue(self.interactionHandler.didHandleBeginLongPressOnBubble)
}

func testThat_WhenCellIsEndLongPressOnBubble_ThenInteractionHandlerHandlesEvent() {
let cell = PhotoMessageCollectionViewCell(frame: CGRect.zero)
self.presenter.configureCell(cell, decorationAttributes: self.decorationAttributes)
cell.onBubbleLongPressEnded?(cell: cell)
XCTAssertTrue(self.interactionHandler.didHandleEndLongPressOnBubble)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ class PhotoMessageTestHandler: BaseMessageInteractionHandlerProtocol {
self.didHandleTapOnBubble = true
}

var didHandleLongPressOnBubble = false
func userDidLongPressOnBubble(viewModel viewModel: ViewModelT) {
self.didHandleLongPressOnBubble = true
var didHandleBeginLongPressOnBubble = false
func userDidBeginLongPressOnBubble(viewModel viewModel: ViewModelT) {
self.didHandleBeginLongPressOnBubble = true
}

var didHandleEndLongPressOnBubble = false
func userDidEndLongPressOnBubble(viewModel viewModel: ViewModelT) {
self.didHandleEndLongPressOnBubble = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ class TextMessageTestHandler: BaseMessageInteractionHandlerProtocol {

}

func userDidLongPressOnBubble(viewModel viewModel: ViewModelT) {
func userDidBeginLongPressOnBubble(viewModel viewModel: ViewModelT) {

}

func userDidEndLongPressOnBubble(viewModel viewModel: ViewModelT) {

}
}
8 changes: 6 additions & 2 deletions ChattoApp/ChattoApp/Source/BaseMessageHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ class BaseMessageHandler {

}

func userDidLongPressOnBubble(viewModel viewModel: DemoMessageViewModelProtocol) {
print("userDidLongPressOnBubble")
func userDidBeginLongPressOnBubble(viewModel viewModel: DemoMessageViewModelProtocol) {
print("userDidBeginLongPressOnBubble")
}

func userDidEndLongPressOnBubble(viewModel viewModel: DemoMessageViewModelProtocol) {
print("userDidEndLongPressOnBubble")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ class DemoPhotoMessageHandler: BaseMessageInteractionHandlerProtocol {
self.baseHandler.userDidTapOnBubble(viewModel: viewModel)
}

func userDidLongPressOnBubble(viewModel viewModel: DemoPhotoMessageViewModel) {
self.baseHandler.userDidLongPressOnBubble(viewModel: viewModel)
func userDidBeginLongPressOnBubble(viewModel viewModel: DemoPhotoMessageViewModel) {
self.baseHandler.userDidBeginLongPressOnBubble(viewModel: viewModel)
}

func userDidEndLongPressOnBubble(viewModel viewModel: DemoPhotoMessageViewModel) {
self.baseHandler.userDidEndLongPressOnBubble(viewModel: viewModel)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ class DemoTextMessageHandler: BaseMessageInteractionHandlerProtocol {
self.baseHandler.userDidTapOnBubble(viewModel: viewModel)
}

func userDidLongPressOnBubble(viewModel viewModel: DemoTextMessageViewModel) {
self.baseHandler.userDidLongPressOnBubble(viewModel: viewModel)
func userDidBeginLongPressOnBubble(viewModel viewModel: DemoTextMessageViewModel) {
self.baseHandler.userDidBeginLongPressOnBubble(viewModel: viewModel)
}

func userDidEndLongPressOnBubble(viewModel viewModel: DemoTextMessageViewModel) {
self.baseHandler.userDidEndLongPressOnBubble(viewModel: viewModel)
}
}