mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Merge branch 'master' into bazel
This commit is contained in:
@@ -53,6 +53,7 @@ private final class NavigationButtonItemNode: ImmediateTextNode {
|
||||
}
|
||||
|
||||
private var imageNode: ASImageNode?
|
||||
private let imageRippleNode: ASImageNode
|
||||
|
||||
private var _image: UIImage?
|
||||
public var image: UIImage? {
|
||||
@@ -61,17 +62,33 @@ private final class NavigationButtonItemNode: ImmediateTextNode {
|
||||
} set(value) {
|
||||
_image = value
|
||||
|
||||
if let _ = value {
|
||||
if let value = value {
|
||||
if self.imageNode == nil {
|
||||
let imageNode = ASImageNode()
|
||||
imageNode.displaysAsynchronously = false
|
||||
self.imageNode = imageNode
|
||||
if false, value.size == CGSize(width: 30.0, height: 30.0) {
|
||||
if self.imageRippleNode.supernode == nil {
|
||||
self.addSubnode(self.imageRippleNode)
|
||||
self.imageRippleNode.image = generateFilledCircleImage(diameter: 30.0, color: self.rippleColor)
|
||||
}
|
||||
} else {
|
||||
if self.imageRippleNode.supernode != nil {
|
||||
self.imageRippleNode.image = nil
|
||||
self.imageRippleNode.removeFromSupernode()
|
||||
}
|
||||
}
|
||||
|
||||
self.addSubnode(imageNode)
|
||||
}
|
||||
self.imageNode?.image = image
|
||||
} else if let imageNode = self.imageNode {
|
||||
imageNode.removeFromSupernode()
|
||||
self.imageNode = nil
|
||||
if self.imageRippleNode.supernode != nil {
|
||||
self.imageRippleNode.image = nil
|
||||
self.imageRippleNode.removeFromSupernode()
|
||||
}
|
||||
}
|
||||
|
||||
self.invalidateCalculatedLayout()
|
||||
@@ -100,6 +117,14 @@ private final class NavigationButtonItemNode: ImmediateTextNode {
|
||||
}
|
||||
}
|
||||
|
||||
public var rippleColor: UIColor = UIColor(rgb: 0x000000, alpha: 0.05) {
|
||||
didSet {
|
||||
if self.imageRippleNode.image != nil {
|
||||
self.imageRippleNode.image = generateFilledCircleImage(diameter: 30.0, color: self.rippleColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public var disabledColor: UIColor = UIColor(rgb: 0xd0d0d0) {
|
||||
didSet {
|
||||
if let text = self._text {
|
||||
@@ -159,6 +184,11 @@ private final class NavigationButtonItemNode: ImmediateTextNode {
|
||||
}
|
||||
|
||||
override public init() {
|
||||
self.imageRippleNode = ASImageNode()
|
||||
self.imageRippleNode.displaysAsynchronously = false
|
||||
self.imageRippleNode.displayWithoutProcessing = true
|
||||
self.imageRippleNode.alpha = 0.0
|
||||
|
||||
super.init()
|
||||
|
||||
self.isAccessibilityElement = true
|
||||
@@ -182,7 +212,9 @@ private final class NavigationButtonItemNode: ImmediateTextNode {
|
||||
} else if let imageNode = self.imageNode {
|
||||
let nodeSize = imageNode.image?.size ?? CGSize()
|
||||
let size = CGSize(width: max(nodeSize.width, superSize.width), height: max(nodeSize.height, superSize.height))
|
||||
imageNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - nodeSize.width) / 2.0) + 5.0, y: floorToScreenPixels((size.height - nodeSize.height) / 2.0)), size: nodeSize)
|
||||
let imageFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - nodeSize.width) / 2.0) + 5.0, y: floorToScreenPixels((size.height - nodeSize.height) / 2.0)), size: nodeSize)
|
||||
imageNode.frame = imageFrame
|
||||
self.imageRippleNode.frame = imageFrame
|
||||
return size
|
||||
}
|
||||
return superSize
|
||||
@@ -208,7 +240,7 @@ private final class NavigationButtonItemNode: ImmediateTextNode {
|
||||
public override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
super.touchesMoved(touches, with: event)
|
||||
|
||||
self.updateHighlightedState(self.touchInsideApparentBounds(touches.first!), animated: true)
|
||||
//self.updateHighlightedState(self.touchInsideApparentBounds(touches.first!), animated: true)
|
||||
}
|
||||
|
||||
public override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
@@ -218,7 +250,7 @@ private final class NavigationButtonItemNode: ImmediateTextNode {
|
||||
let previousTouchCount = self.touchCount
|
||||
self.touchCount = max(0, self.touchCount - touches.count)
|
||||
|
||||
if previousTouchCount != 0 && self.touchCount == 0 && self.isEnabled && self.touchInsideApparentBounds(touches.first!) {
|
||||
if previousTouchCount != 0 && self.touchCount == 0 && self.isEnabled {
|
||||
self.pressed()
|
||||
}
|
||||
}
|
||||
@@ -241,7 +273,15 @@ private final class NavigationButtonItemNode: ImmediateTextNode {
|
||||
}
|
||||
|
||||
if shouldChangeHighlight {
|
||||
self.alpha = !self.isEnabled ? 1.0 : (highlighted ? 0.4 : 1.0)
|
||||
if let imageNode = self.imageNode {
|
||||
let previousAlpha = self.imageRippleNode.alpha
|
||||
self.imageRippleNode.alpha = highlighted ? 1.0 : 0.0
|
||||
if !highlighted {
|
||||
self.imageRippleNode.layer.animateAlpha(from: previousAlpha, to: self.imageRippleNode.alpha, duration: 0.25)
|
||||
}
|
||||
} else {
|
||||
self.alpha = !self.isEnabled ? 1.0 : (highlighted ? 0.4 : 1.0)
|
||||
}
|
||||
self.highlightChanged(highlighted)
|
||||
}
|
||||
}
|
||||
@@ -255,9 +295,16 @@ private final class NavigationButtonItemNode: ImmediateTextNode {
|
||||
}
|
||||
|
||||
|
||||
final class NavigationButtonNode: ASDisplayNode {
|
||||
public final class NavigationButtonNode: ASDisplayNode {
|
||||
private var nodes: [NavigationButtonItemNode] = []
|
||||
|
||||
public var singleCustomNode: ASDisplayNode? {
|
||||
for node in self.nodes {
|
||||
return node.node
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
public var pressed: (Int) -> () = { _ in }
|
||||
public var highlightChanged: (Int, Bool) -> () = { _, _ in }
|
||||
|
||||
@@ -271,6 +318,16 @@ final class NavigationButtonNode: ASDisplayNode {
|
||||
}
|
||||
}
|
||||
|
||||
public var rippleColor: UIColor = UIColor(rgb: 0x000000, alpha: 0.05) {
|
||||
didSet {
|
||||
if !self.rippleColor.isEqual(oldValue) {
|
||||
for node in self.nodes {
|
||||
node.rippleColor = self.rippleColor
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public var disabledColor: UIColor = UIColor(rgb: 0xd0d0d0) {
|
||||
didSet {
|
||||
if !self.disabledColor.isEqual(oldValue) {
|
||||
@@ -288,7 +345,7 @@ final class NavigationButtonNode: ASDisplayNode {
|
||||
}
|
||||
}
|
||||
|
||||
override init() {
|
||||
override public init() {
|
||||
super.init()
|
||||
|
||||
self.isAccessibilityElement = false
|
||||
@@ -305,6 +362,7 @@ final class NavigationButtonNode: ASDisplayNode {
|
||||
} else {
|
||||
node = NavigationButtonItemNode()
|
||||
node.color = self.color
|
||||
node.rippleColor = self.rippleColor
|
||||
node.highlightChanged = { [weak node, weak self] value in
|
||||
if let strongSelf = self, let node = node {
|
||||
if let index = strongSelf.nodes.firstIndex(where: { $0 === node }) {
|
||||
@@ -345,6 +403,7 @@ final class NavigationButtonNode: ASDisplayNode {
|
||||
} else {
|
||||
node = NavigationButtonItemNode()
|
||||
node.color = self.color
|
||||
node.rippleColor = self.rippleColor
|
||||
node.highlightChanged = { [weak node, weak self] value in
|
||||
if let strongSelf = self, let node = node {
|
||||
if let index = strongSelf.nodes.firstIndex(where: { $0 === node }) {
|
||||
@@ -377,7 +436,7 @@ final class NavigationButtonNode: ASDisplayNode {
|
||||
}
|
||||
}
|
||||
|
||||
func updateLayout(constrainedSize: CGSize) -> CGSize {
|
||||
public func updateLayout(constrainedSize: CGSize) -> CGSize {
|
||||
var nodeOrigin = CGPoint()
|
||||
var totalSize = CGSize()
|
||||
for node in self.nodes {
|
||||
@@ -395,4 +454,12 @@ final class NavigationButtonNode: ASDisplayNode {
|
||||
}
|
||||
return totalSize
|
||||
}
|
||||
|
||||
func internalHitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
|
||||
if self.nodes.count == 1 {
|
||||
return self.nodes[0].view
|
||||
} else {
|
||||
return super.hitTest(point, with: event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user