Various fixes

This commit is contained in:
Ilya Laktyushin 2022-07-24 01:09:15 +03:00
parent 3d0f297554
commit 68f93cc748
3 changed files with 60 additions and 8 deletions

View File

@ -356,6 +356,8 @@ final class InnerTextSelectionTipContainerNode: ASDisplayNode {
private var file: TelegramMediaFile?
private let targetSelectionIndex: Int?
private var hapticFeedback: HapticFeedback?
private var action: (() -> Void)?
var requestDismiss: (@escaping () -> Void) -> Void = { _ in }
@ -442,13 +444,7 @@ final class InnerTextSelectionTipContainerNode: ASDisplayNode {
guard let strongSelf = self else {
return
}
if highlighted {
strongSelf.highlightBackgroundNode.alpha = 1.0
} else {
let previousAlpha = strongSelf.highlightBackgroundNode.alpha
strongSelf.highlightBackgroundNode.alpha = 0.0
strongSelf.highlightBackgroundNode.layer.animateAlpha(from: previousAlpha, to: 0.0, duration: 0.2)
}
strongSelf.updateHighlight(animated: true)
}
self.buttonNode.addTarget(self, action: #selector(self.pressed), forControlEvents: .touchUpInside)
@ -595,6 +591,55 @@ final class InnerTextSelectionTipContainerNode: ASDisplayNode {
})
}
}
func updateHighlight(animated: Bool) {
if self.buttonNode.isHighlighted || self.isHighlighted {
self.highlightBackgroundNode.alpha = 1.0
} else {
if animated {
let previousAlpha = self.highlightBackgroundNode.alpha
self.highlightBackgroundNode.alpha = 0.0
self.highlightBackgroundNode.layer.animateAlpha(from: previousAlpha, to: 0.0, duration: 0.2)
} else {
self.highlightBackgroundNode.alpha = 0.0
}
}
}
var isHighlighted = false
func setHighlighted(_ highlighted: Bool) {
guard self.isHighlighted != highlighted else {
return
}
self.isHighlighted = highlighted
if highlighted {
if self.hapticFeedback == nil {
self.hapticFeedback = HapticFeedback()
}
self.hapticFeedback?.tap()
}
self.updateHighlight(animated: false)
}
func highlightGestureMoved(location: CGPoint) {
if self.bounds.contains(location) && self.isUserInteractionEnabled {
self.setHighlighted(true)
} else {
self.setHighlighted(false)
}
}
func highlightGestureFinished(performAction: Bool) {
if self.isHighlighted {
self.setHighlighted(false)
if performAction {
self.pressed()
}
}
}
}
final class ContextActionsContainerNode: ASDisplayNode {

View File

@ -912,10 +912,17 @@ final class ContextControllerActionsStackNode: ASDisplayNode {
}
func highlightGestureMoved(location: CGPoint) {
if let tipNode = self.tipNode {
let tipLocation = self.view.convert(location, to: tipNode.view)
tipNode.highlightGestureMoved(location: tipLocation)
}
self.node.highlightGestureMoved(location: self.view.convert(location, to: self.node.view))
}
func highlightGestureFinished(performAction: Bool) {
if let tipNode = self.tipNode {
tipNode.highlightGestureFinished(performAction: performAction)
}
self.node.highlightGestureFinished(performAction: performAction)
}
}

View File

@ -379,7 +379,7 @@ final class ChatTextInputMediaRecordingButton: TGModernConversationInputMicButto
environment: {},
containerSize: animationFrame.size
)
// self.innerIconView.frame = CGRect(origin: CGPoint(x: floor((size.width - iconSize.width) / 2.0), y: floor((size.height - iconSize.height) / 2.0)), size: iconSize)
if let view = animationView.view {
view.isUserInteractionEnabled = false
if view.superview == nil {