-
-
Notifications
You must be signed in to change notification settings - Fork 29
[trello.com/c/4FomJzhO] Add Copy action to Failed messages menu + Open menu on long tap #833
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
Open
Lainaaa
wants to merge
7
commits into
develop
Choose a base branch
from
trello.com/c/4FomJzhO
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+428
−267
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
54c0615
[trello.com/c/4FomJzhO] Add Copy action to Failed messages menu. Refa…
Lainaaa 389ec24
[trello.com/c/4FomJzhO] Fix localization
Lainaaa 5a3d8a6
[trello.com/c/4FomJzhO] Open menu for failed message instead of copy …
Lainaaa 04c1334
[trello.com/c/4FomJzhO] Open menu for by double touch on MacOS, long …
Lainaaa 72c1f17
Merge branch 'develop' into trello.com/c/4FomJzhO
Lainaaa 782533b
[trello.com/c/4FomJzhO] Update interval duration from merged changes
Lainaaa 1d28099
[trello.com/c/4FomJzhO] Fix media message animation
Lainaaa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -18,8 +18,14 @@ final class ChatMessageCell: TextMessageCell, ChatModelView { | |
// MARK: Dependencies | ||
|
||
var chatMessagesListViewModel: ChatMessagesListViewModel? | ||
|
||
var copyAction: ((String) -> Void)? | ||
|
||
// MARK: Proprieties | ||
|
||
// MARK: Gesture Helper | ||
var GestureTaskManager: TaskManager = TaskManager() | ||
var didPerformLongPressAction: Bool = false | ||
|
||
private lazy var reactionsContanerView: UIStackView = { | ||
let stack = UIStackView(arrangedSubviews: [ownReactionLabel, opponentReactionLabel]) | ||
|
@@ -88,8 +94,6 @@ final class ChatMessageCell: TextMessageCell, ChatModelView { | |
} | ||
} | ||
|
||
var copyNotification: (() -> Void)? | ||
|
||
var reactionsContanerViewWidth: CGFloat { | ||
if getReaction(for: model.address) == nil && getReaction(for: model.opponentAddress) == nil { | ||
return .zero | ||
|
@@ -117,8 +121,7 @@ final class ChatMessageCell: TextMessageCell, ChatModelView { | |
originalColor: model.backgroundColor.uiColor | ||
) | ||
if isSelected { | ||
UIPasteboard.general.string = self.model.text.string | ||
self.copyNotification?() | ||
copyAction?(self.model.text.string) | ||
} | ||
} | ||
} | ||
|
@@ -131,8 +134,6 @@ final class ChatMessageCell: TextMessageCell, ChatModelView { | |
private let opponentReactionSize = CGSize(width: 55, height: 27) | ||
private let opponentReactionImageSize = CGSize(width: 12, height: 12) | ||
private var layoutAttributes: MessagesCollectionViewLayoutAttributes? | ||
private var taskManager = TaskManager() | ||
private var didCopy = false | ||
|
||
// MARK: - Methods | ||
|
||
|
@@ -173,7 +174,7 @@ final class ChatMessageCell: TextMessageCell, ChatModelView { | |
} | ||
|
||
private func configureLongPressGesture() { | ||
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPressToCopy(_:))) | ||
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(handleLongPress(_:))) | ||
longPress.minimumPressDuration = 0.2 | ||
messageContainerView.addGestureRecognizer(longPress) | ||
messageContainerView.isUserInteractionEnabled = true | ||
|
@@ -411,29 +412,29 @@ final class ChatMessageCell: TextMessageCell, ChatModelView { | |
/// Handle tap gesture on contentView and its subviews. | ||
override func handleTapGesture(_ gesture: UIGestureRecognizer) { | ||
let touchLocation = gesture.location(in: self) | ||
|
||
let containerViewContains = containerView.frame.contains(touchLocation) | ||
let canHandle = !cellContentView( | ||
canHandle: convert(touchLocation, to: containerView) | ||
) | ||
|
||
switch true { | ||
case containerViewContains && canHandle: | ||
delegate?.didTapMessage(in: self) | ||
case avatarView.frame.contains(touchLocation): | ||
delegate?.didTapAvatar(in: self) | ||
case cellTopLabel.frame.contains(touchLocation): | ||
delegate?.didTapCellTopLabel(in: self) | ||
case cellBottomLabel.frame.contains(touchLocation): | ||
delegate?.didTapCellBottomLabel(in: self) | ||
case messageTopLabel.frame.contains(touchLocation): | ||
delegate?.didTapMessageTopLabel(in: self) | ||
case messageBottomLabel.frame.contains(touchLocation): | ||
delegate?.didTapMessageBottomLabel(in: self) | ||
case accessoryView.frame.contains(touchLocation): | ||
delegate?.didTapAccessoryView(in: self) | ||
default: | ||
delegate?.didTapBackground(in: self) | ||
case containerViewContains && canHandle: | ||
delegate?.didTapMessage(in: self) | ||
case avatarView.frame.contains(touchLocation): | ||
delegate?.didTapAvatar(in: self) | ||
case cellTopLabel.frame.contains(touchLocation): | ||
delegate?.didTapCellTopLabel(in: self) | ||
case cellBottomLabel.frame.contains(touchLocation): | ||
delegate?.didTapCellBottomLabel(in: self) | ||
case messageTopLabel.frame.contains(touchLocation): | ||
delegate?.didTapMessageTopLabel(in: self) | ||
case messageBottomLabel.frame.contains(touchLocation): | ||
delegate?.didTapMessageBottomLabel(in: self) | ||
case accessoryView.frame.contains(touchLocation): | ||
delegate?.didTapAccessoryView(in: self) | ||
default: | ||
delegate?.didTapBackground(in: self) | ||
} | ||
} | ||
|
||
|
@@ -491,47 +492,17 @@ private extension ChatMessageCell { | |
@objc func tapReactionAction() { | ||
chatMenuManager.presentMenuProgrammatically(for: containerView) | ||
} | ||
|
||
@objc private func handleLongPressToCopy(_ gesture: UILongPressGestureRecognizer) { | ||
switch gesture.state { | ||
case .began: | ||
didCopy = false | ||
messageContainerView.animatePressDown() | ||
|
||
Task { [weak self] in | ||
try? await Task.sleep(interval: quickCopyInterval) | ||
|
||
guard let self = self, | ||
gesture.state == .began || gesture.state == .changed else { return } | ||
|
||
await MainActor.run { | ||
self.longPressCopyAction() | ||
self.didCopy = true | ||
} | ||
}.stored(in: taskManager) | ||
|
||
case .ended: | ||
if !didCopy { | ||
taskManager.clean() | ||
longPressCopyAction() | ||
} | ||
|
||
case .cancelled, .failed: | ||
messageContainerView.animatePressUp() | ||
|
||
default: | ||
break | ||
} | ||
} | ||
|
||
private func longPressCopyAction() { | ||
self.messageContainerView.animatePressUp() | ||
UIPasteboard.general.string = self.model.text.string | ||
self.copyNotification?() | ||
} | ||
} | ||
|
||
extension ChatMessageCell: ChatMenuManagerDelegate { | ||
var isFailedMessage: Bool { | ||
model.backgroundColor == .failed | ||
} | ||
|
||
func showFailedMenu(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. showFailedMenuAlert ? |
||
self.actionHandler(.showFailedMessageAlert(id: model.id)) | ||
} | ||
|
||
func getCopyView() -> UIView? { | ||
copy( | ||
with: model, | ||
|
@@ -599,6 +570,59 @@ extension ChatMessageCell: ChatCellProtocol { | |
} | ||
} | ||
|
||
// MARK: - Long Press | ||
extension ChatMessageCell: GestureHelper { | ||
@objc private func handleLongPress(_ gesture: UILongPressGestureRecognizer) { | ||
if !isMacOS, model.backgroundColor == .failed { | ||
handleLongPressToShowFailed(gesture) | ||
return | ||
} | ||
if isMacOS { | ||
handleLongPressToCopy(gesture) | ||
return | ||
} | ||
handleLongPressToOpenMenu(gesture) | ||
} | ||
|
||
private func handleLongPressToCopy(_ gesture: UILongPressGestureRecognizer) { | ||
processLongPress( | ||
gesture: gesture, | ||
perform: { [weak self] in | ||
guard let text = self?.model.text.string else { return } | ||
self?.copyAction?(text) }, | ||
onGestureBegan: { [weak self] in | ||
self?.messageContainerView.animatePressDown() }, | ||
onGestureEnded: { [weak self] in self?.messageContainerView.animatePressUp() } | ||
) | ||
} | ||
|
||
private func handleLongPressToShowFailed(_ gesture: UILongPressGestureRecognizer) { | ||
processLongPress( | ||
gesture: gesture, | ||
perform: { [weak self] in | ||
guard let id = self?.model.id else { return } | ||
self?.actionHandler(.showFailedMessageAlert(id: id)) }, | ||
onGestureBegan: { [weak self] in | ||
self?.messageContainerView.animatePressDown() }, | ||
onGestureEnded: { [weak self] in self?.messageContainerView.animatePressUp() } | ||
) | ||
} | ||
|
||
private func handleLongPressToOpenMenu(_ gesture: UILongPressGestureRecognizer) { | ||
processLongPress( | ||
gesture: gesture, | ||
touchDuration: 0.2, | ||
perform: { [weak self] in | ||
guard let view = self?.containerView else { return } | ||
self?.chatMenuManager.presentMenuProgrammatically(for: view) | ||
}, | ||
onGestureBegan: { [weak self] in | ||
self?.messageContainerView.animatePressDown() }, | ||
onGestureEnded: { [weak self] in self?.messageContainerView.animatePressUp() } | ||
) | ||
} | ||
} | ||
|
||
private let reactionsContanerVerticalSpace: CGFloat = 10 | ||
private let minReactionsSpacingToOwnBoundary: CGFloat = 60 | ||
private let minReactionsSpacingToOppositeBoundary: CGFloat = 15 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally speaking ,deciding on the state based on backgroundColor is not a future-proof solution. Would you consider improving this part a bit?