Home telegram - listViewAccessoryItemNode
Post
Cancel

telegram - listViewAccessoryItemNode

ListViewAccessoryItemNode

class ListViewAccessoryItemNode: ASDisplayNode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var transitionOffset: CGPoint = CGPoint() {
    didSet {
      // animate the bounds origin (aka transitionOffset)
        self.bounds = CGRect(origin: self.transitionOffset, size: self.bounds.size)
    }
}

private var transitionOffsetAnimation: ListViewAnimation?

// animateTransitionOffset
// prepare the `transitionOffsetAnimation`
final func animateTransitionOffset(_ from: CGPoint, beginAt: Double, duration: Double, curve: @escaping (CGFloat) -> CGFloat) {
    self.transitionOffset = from
    self.transitionOffsetAnimation = ListViewAnimation(from: from, to: CGPoint(), duration: duration, curve: curve, beginAt: beginAt, update: { [weak self] _, currentValue in
        if let strongSelf = self {
            strongSelf.transitionOffset = currentValue
        }
    })
}

final func animate(_ timestamp: Double) -> Bool {
    if let animation = self.transitionOffsetAnimation {
        animation.applyAt(timestamp)
            
        if animation.completeAt(timestamp) {
            self.transitionOffsetAnimation = nil
        } else {
            return true
        }
    }
    return false
}

override open func layout() {
    super.layout()
    
    self.updateLayout(size: self.bounds.size, leftInset: 0.0, rightInset: 0.0)
}

// for subclasses to override
open func updateLayout(size: CGSize, leftInset: CGFloat, rightInset: CGFloat) {
}
This post is licensed under CC BY 4.0 by the author.