mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Merge commit 'af504a333ec8478ab081a1d92b58cc3a31a39237'
This commit is contained in:
@@ -84,6 +84,9 @@ final class ActionSheetControllerNode: ASDisplayNode, UIScrollViewDelegate {
|
||||
|
||||
insets.left = floor((layout.size.width - containerWidth) / 2.0)
|
||||
insets.right = insets.left
|
||||
if insets.bottom > 0 {
|
||||
insets.bottom -= 12.0
|
||||
}
|
||||
|
||||
self.validLayout = layout
|
||||
|
||||
|
||||
@@ -16,14 +16,16 @@ public final class ContextMenuController: ViewController {
|
||||
|
||||
private let actions: [ContextMenuAction]
|
||||
private let catchTapsOutside: Bool
|
||||
private let hasHapticFeedback: Bool
|
||||
|
||||
private var layout: ContainerViewLayout?
|
||||
|
||||
public var dismissed: (() -> Void)?
|
||||
|
||||
public init(actions: [ContextMenuAction], catchTapsOutside: Bool = false) {
|
||||
public init(actions: [ContextMenuAction], catchTapsOutside: Bool = false, hasHapticFeedback: Bool = false) {
|
||||
self.actions = actions
|
||||
self.catchTapsOutside = catchTapsOutside
|
||||
self.hasHapticFeedback = hasHapticFeedback
|
||||
|
||||
super.init(navigationBarPresentationData: nil)
|
||||
}
|
||||
@@ -32,13 +34,13 @@ public final class ContextMenuController: ViewController {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
open override func loadDisplayNode() {
|
||||
override public func loadDisplayNode() {
|
||||
self.displayNode = ContextMenuNode(actions: self.actions, dismiss: { [weak self] in
|
||||
self?.dismissed?()
|
||||
self?.contextMenuNode.animateOut {
|
||||
self?.presentingViewController?.dismiss(animated: false)
|
||||
}
|
||||
}, catchTapsOutside: self.catchTapsOutside)
|
||||
}, catchTapsOutside: self.catchTapsOutside, hasHapticFeedback: self.hasHapticFeedback)
|
||||
self.displayNodeDidLoad()
|
||||
}
|
||||
|
||||
@@ -55,7 +57,7 @@ public final class ContextMenuController: ViewController {
|
||||
}
|
||||
}
|
||||
|
||||
override open func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
|
||||
override public func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
|
||||
super.containerLayoutUpdated(layout, transition: transition)
|
||||
|
||||
if self.layout != nil && self.layout! != layout {
|
||||
@@ -78,7 +80,7 @@ public final class ContextMenuController: ViewController {
|
||||
}
|
||||
}
|
||||
|
||||
open override func viewWillAppear(_ animated: Bool) {
|
||||
override public func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
|
||||
self.contextMenuNode.animateIn()
|
||||
|
||||
@@ -144,7 +144,9 @@ final class ContextMenuNode: ASDisplayNode {
|
||||
private var dismissedByTouchOutside = false
|
||||
private let catchTapsOutside: Bool
|
||||
|
||||
init(actions: [ContextMenuAction], dismiss: @escaping () -> Void, catchTapsOutside: Bool) {
|
||||
private let feedback: HapticFeedback?
|
||||
|
||||
init(actions: [ContextMenuAction], dismiss: @escaping () -> Void, catchTapsOutside: Bool, hasHapticFeedback: Bool = false) {
|
||||
self.actions = actions
|
||||
self.dismiss = dismiss
|
||||
self.catchTapsOutside = catchTapsOutside
|
||||
@@ -156,6 +158,13 @@ final class ContextMenuNode: ASDisplayNode {
|
||||
return ContextMenuActionNode(action: action)
|
||||
}
|
||||
|
||||
if hasHapticFeedback {
|
||||
self.feedback = HapticFeedback()
|
||||
self.feedback?.prepareImpact()
|
||||
} else {
|
||||
self.feedback = nil
|
||||
}
|
||||
|
||||
super.init()
|
||||
|
||||
self.containerNode.addSubnode(self.scrollNode)
|
||||
@@ -219,6 +228,10 @@ final class ContextMenuNode: ASDisplayNode {
|
||||
self.containerNode.layer.animateSpring(from: NSValue(cgPoint: CGPoint(x: containerPosition.x, y: containerPosition.y + (self.arrowOnBottom ? 1.0 : -1.0) * self.containerNode.bounds.size.height / 2.0)), to: NSValue(cgPoint: containerPosition), keyPath: "position", duration: 0.4)
|
||||
|
||||
self.containerNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.1)
|
||||
|
||||
if let feedback = self.feedback {
|
||||
feedback.impact()
|
||||
}
|
||||
}
|
||||
|
||||
func animateOut(completion: @escaping () -> Void) {
|
||||
|
||||
Reference in New Issue
Block a user