mirror of
https://github.com/mastodon/mastodon-ios.git
synced 2025-01-13 09:32:57 +01:00
feat: add timestamp updater
This commit is contained in:
parent
69a7517fde
commit
6f8666aaa8
@ -18,6 +18,8 @@ protocol StatusNodeDelegate: AnyObject {
|
|||||||
final class StatusNode: ASCellNode {
|
final class StatusNode: ASCellNode {
|
||||||
|
|
||||||
var disposeBag = Set<AnyCancellable>()
|
var disposeBag = Set<AnyCancellable>()
|
||||||
|
var timestamp: Date
|
||||||
|
var timestampSubscription: AnyCancellable?
|
||||||
weak var delegate: StatusNodeDelegate? // needs assign on main queue
|
weak var delegate: StatusNodeDelegate? // needs assign on main queue
|
||||||
|
|
||||||
static let avatarImageSize = CGSize(width: 42, height: 42)
|
static let avatarImageSize = CGSize(width: 42, height: 42)
|
||||||
@ -61,6 +63,7 @@ final class StatusNode: ASCellNode {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
init(status: Status) {
|
init(status: Status) {
|
||||||
|
timestamp = (status.reblog ?? status).createdAt
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
automaticallyManagesSubnodes = true
|
automaticallyManagesSubnodes = true
|
||||||
@ -78,23 +81,10 @@ final class StatusNode: ASCellNode {
|
|||||||
.font: UIFont.systemFont(ofSize: 13, weight: .regular)
|
.font: UIFont.systemFont(ofSize: 13, weight: .regular)
|
||||||
])
|
])
|
||||||
// set date
|
// set date
|
||||||
let createdAt = (status.reblog ?? status).createdAt
|
dateTextNode.attributedText = NSAttributedString(string: timestamp.slowedTimeAgoSinceNow, attributes: [
|
||||||
dateTextNode.attributedText = NSAttributedString(string: createdAt.slowedTimeAgoSinceNow, attributes: [
|
|
||||||
.foregroundColor: Asset.Colors.Label.secondary.color,
|
.foregroundColor: Asset.Colors.Label.secondary.color,
|
||||||
.font: UIFont.systemFont(ofSize: 13, weight: .regular)
|
.font: UIFont.systemFont(ofSize: 13, weight: .regular)
|
||||||
])
|
])
|
||||||
// RunLoop.main.perform { [weak self] in
|
|
||||||
// guard let self = self else { return }
|
|
||||||
// AppContext.shared.timestampUpdatePublisher
|
|
||||||
// .sink { [weak self] _ in
|
|
||||||
// guard let self = self else { return }
|
|
||||||
// self.dateTextNode.attributedText = NSAttributedString(string: createdAt.slowedTimeAgoSinceNow, attributes: [
|
|
||||||
// .foregroundColor: Asset.Colors.Label.secondary.color,
|
|
||||||
// .font: UIFont.systemFont(ofSize: 13, weight: .regular)
|
|
||||||
// ])
|
|
||||||
// }
|
|
||||||
// .store(in: &self.disposeBag)
|
|
||||||
// }
|
|
||||||
|
|
||||||
usernameTextNode.attributedText = NSAttributedString(string: "@" + status.author.acct, attributes: [
|
usernameTextNode.attributedText = NSAttributedString(string: "@" + status.author.acct, attributes: [
|
||||||
.foregroundColor: Asset.Colors.Label.secondary.color,
|
.foregroundColor: Asset.Colors.Label.secondary.color,
|
||||||
@ -113,6 +103,15 @@ final class StatusNode: ASCellNode {
|
|||||||
override func didEnterDisplayState() {
|
override func didEnterDisplayState() {
|
||||||
super.didEnterDisplayState()
|
super.didEnterDisplayState()
|
||||||
|
|
||||||
|
timestampSubscription = AppContext.shared.timestampUpdatePublisher
|
||||||
|
.sink { [weak self] _ in
|
||||||
|
guard let self = self else { return }
|
||||||
|
self.dateTextNode.attributedText = NSAttributedString(string: self.timestamp.slowedTimeAgoSinceNow, attributes: [
|
||||||
|
.foregroundColor: Asset.Colors.Label.secondary.color,
|
||||||
|
.font: UIFont.systemFont(ofSize: 13, weight: .regular)
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
statusContentTextNode.textView.isEditable = false
|
statusContentTextNode.textView.isEditable = false
|
||||||
statusContentTextNode.textView.textDragInteraction?.isEnabled = false
|
statusContentTextNode.textView.textDragInteraction?.isEnabled = false
|
||||||
statusContentTextNode.textView.linkTextAttributes = [
|
statusContentTextNode.textView.linkTextAttributes = [
|
||||||
@ -120,6 +119,11 @@ final class StatusNode: ASCellNode {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func didExitVisibleState() {
|
||||||
|
super.didExitVisibleState()
|
||||||
|
timestampSubscription = nil
|
||||||
|
}
|
||||||
|
|
||||||
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
|
override func layoutSpecThatFits(_ constrainedSize: ASSizeRange) -> ASLayoutSpec {
|
||||||
let headerStack = ASStackLayoutSpec.horizontal()
|
let headerStack = ASStackLayoutSpec.horizontal()
|
||||||
headerStack.alignItems = .center
|
headerStack.alignItems = .center
|
||||||
|
Loading…
Reference in New Issue
Block a user