-
Notifications
You must be signed in to change notification settings - Fork 11
Reply button for thread view #947
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
111 changes: 111 additions & 0 deletions
111
FlowCryptUI/Cell Nodes/ThreadMessageSenderCellNode.swift
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 |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| // | ||
| // ThreadMessageSenderCellNode.swift | ||
| // FlowCryptUI | ||
| // | ||
| // Created by Roma Sosnovsky on 06/11/21 | ||
| // Copyright © 2017-present FlowCrypt a. s. All rights reserved. | ||
| // | ||
|
|
||
| import AsyncDisplayKit | ||
| import UIKit | ||
|
|
||
| public final class ThreadMessageSenderCellNode: CellNode { | ||
| public struct Input { | ||
| public let sender: NSAttributedString | ||
| public let date: NSAttributedString? | ||
| public let isExpanded: Bool | ||
| public let buttonColor: UIColor | ||
|
|
||
| public init(sender: NSAttributedString, | ||
| date: NSAttributedString, | ||
| isExpanded: Bool, | ||
| buttonColor: UIColor) { | ||
| self.sender = sender | ||
| self.date = date | ||
| self.isExpanded = isExpanded | ||
| self.buttonColor = buttonColor | ||
| } | ||
|
|
||
| var replyImage: UIImage? { | ||
| return createButtonImage(systemName: "arrowshape.turn.up.left") | ||
| } | ||
| var expandImage: UIImage? { | ||
| let systemName = isExpanded ? "chevron.up" : "chevron.down" | ||
| return createButtonImage(systemName: systemName) | ||
| } | ||
|
|
||
| private func createButtonImage(systemName: String, pointSize: CGFloat = 18) -> UIImage? { | ||
| let configuration = UIImage.SymbolConfiguration(pointSize: pointSize) | ||
| return UIImage(systemName: systemName, withConfiguration: configuration) | ||
| } | ||
| } | ||
|
|
||
| private let senderNode = ASTextNode2() | ||
| private let dateNode = ASTextNode2() | ||
| public private(set) var replyNode = ASButtonNode() | ||
| public private(set) var expandNode = ASImageNode() | ||
|
|
||
| private let input: ThreadMessageSenderCellNode.Input | ||
| private var onReplyTap: ((ThreadMessageSenderCellNode) -> Void)? | ||
|
|
||
| public init(input: ThreadMessageSenderCellNode.Input, | ||
| onReplyTap: ((ThreadMessageSenderCellNode) -> Void)?) { | ||
| self.input = input | ||
| self.onReplyTap = onReplyTap | ||
| super.init() | ||
| automaticallyManagesSubnodes = true | ||
|
|
||
| senderNode.attributedText = input.sender | ||
| dateNode.attributedText = input.date | ||
|
|
||
| setupReplyNode() | ||
| setupExpandNode() | ||
| } | ||
|
|
||
| private func setupReplyNode() { | ||
| replyNode.setImage(input.replyImage, for: .normal) | ||
| replyNode.imageNode.imageModificationBlock = ASImageNodeTintColorModificationBlock(input.buttonColor) | ||
| replyNode.contentMode = .center | ||
| replyNode.alpha = input.isExpanded ? 1 : 0 | ||
| replyNode.addTarget(self, action: #selector(onReplyNodeTap), forControlEvents: .touchUpInside) | ||
| } | ||
|
|
||
| private func setupExpandNode() { | ||
| expandNode.image = input.expandImage | ||
| expandNode.imageModificationBlock = ASImageNodeTintColorModificationBlock(input.buttonColor) | ||
| expandNode.contentMode = .right | ||
| } | ||
|
|
||
| @objc private func onReplyNodeTap() { | ||
| onReplyTap?(self) | ||
| } | ||
|
|
||
| public override func layoutSpecThatFits(_: ASSizeRange) -> ASLayoutSpec { | ||
| replyNode.style.preferredSize = CGSize(width: 44, height: 44) | ||
| expandNode.style.preferredSize = CGSize(width: 18, height: 44) | ||
|
|
||
| let infoNode = ASStackLayoutSpec( | ||
| direction: .vertical, | ||
| spacing: 4, | ||
| justifyContent: .start, | ||
| alignItems: .start, | ||
| children: [senderNode, dateNode] | ||
| ) | ||
|
|
||
| infoNode.style.flexGrow = 1 | ||
| infoNode.style.flexShrink = 1 | ||
|
|
||
| let contentSpec = ASStackLayoutSpec( | ||
| direction: .horizontal, | ||
| spacing: 4, | ||
| justifyContent: .spaceBetween, | ||
| alignItems: .center, | ||
| children: [infoNode, replyNode, expandNode] | ||
| ) | ||
|
|
||
| return ASInsetLayoutSpec( | ||
| insets: UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 12), | ||
| child: contentSpec | ||
| ) | ||
| } | ||
| } |
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.
This name is much better - thank you!