mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Context menu pagination
This commit is contained in:
parent
53e1fec16b
commit
99047a4de4
@ -222,7 +222,7 @@ final class AuthorizationSequenceCodeEntryControllerNode: ASDisplayNode, UITextF
|
||||
return
|
||||
}
|
||||
|
||||
let controller = ContextMenuController(actions: [ContextMenuAction(content: .text(title: strongSelf.strings.Common_Paste, accessibilityLabel: strongSelf.strings.Common_Paste), action: { [weak self] in
|
||||
let controller = makeContextMenuController(actions: [ContextMenuAction(content: .text(title: strongSelf.strings.Common_Paste, accessibilityLabel: strongSelf.strings.Common_Paste), action: { [weak self] in
|
||||
self?.updateCode(code)
|
||||
})])
|
||||
|
||||
|
@ -562,7 +562,7 @@
|
||||
// }
|
||||
//
|
||||
// private func longPressMedia(_ media: InstantPageMedia) {
|
||||
// let controller = ContextMenuController(actions: [ContextMenuAction(content: .text(title: self.strings.Conversation_ContextMenuCopy, accessibilityLabel: self.strings.Conversation_ContextMenuCopy), action: { [weak self] in
|
||||
// let controller = makeContextMenuController(actions: [ContextMenuAction(content: .text(title: self.strings.Conversation_ContextMenuCopy, accessibilityLabel: self.strings.Conversation_ContextMenuCopy), action: { [weak self] in
|
||||
// if let strongSelf = self, let image = media.media as? TelegramMediaImage {
|
||||
// let media = TelegramMediaImage(imageId: MediaId(namespace: 0, id: 0), representations: image.representations, immediateThumbnailData: image.immediateThumbnailData, reference: nil, partialReference: nil, flags: [])
|
||||
// let _ = copyToPasteboard(context: strongSelf.context, postbox: strongSelf.context.account.postbox, userLocation: strongSelf.sourceLocation.userLocation, mediaReference: .standalone(media: media)).start()
|
||||
@ -709,7 +709,7 @@
|
||||
// }))
|
||||
// }
|
||||
//
|
||||
// let controller = ContextMenuController(actions: actions)
|
||||
// let controller = makeContextMenuController(actions: actions)
|
||||
// controller.dismissed = { [weak self] in
|
||||
// self?.updateTextSelectionRects([], text: nil)
|
||||
// }
|
||||
|
@ -3,8 +3,8 @@ import UIKit
|
||||
import AsyncDisplayKit
|
||||
|
||||
public final class ContextMenuControllerPresentationArguments {
|
||||
fileprivate let sourceNodeAndRect: () -> (ASDisplayNode, CGRect, ASDisplayNode, CGRect)?
|
||||
fileprivate let bounce: Bool
|
||||
public let sourceNodeAndRect: () -> (ASDisplayNode, CGRect, ASDisplayNode, CGRect)?
|
||||
public let bounce: Bool
|
||||
|
||||
public init(sourceNodeAndRect: @escaping () -> (ASDisplayNode, CGRect, ASDisplayNode, CGRect)?, bounce: Bool = true) {
|
||||
self.sourceNodeAndRect = sourceNodeAndRect
|
||||
@ -12,105 +12,43 @@ public final class ContextMenuControllerPresentationArguments {
|
||||
}
|
||||
}
|
||||
|
||||
public final class ContextMenuController: ViewController, KeyShortcutResponder, StandalonePresentableController {
|
||||
private var contextMenuNode: ContextMenuNode {
|
||||
return self.displayNode as! ContextMenuNode
|
||||
}
|
||||
public protocol ContextMenuController: ViewController, StandalonePresentableController {
|
||||
var centerHorizontally: Bool { get set }
|
||||
var dismissed: (() -> Void)? { get set }
|
||||
var dismissOnTap: ((UIView, CGPoint) -> Bool)? { get set }
|
||||
}
|
||||
|
||||
public struct ContextMenuControllerArguments {
|
||||
public var actions: [ContextMenuAction]
|
||||
public var catchTapsOutside: Bool
|
||||
public var hasHapticFeedback: Bool
|
||||
public var blurred: Bool
|
||||
public var skipCoordnateConversion: Bool
|
||||
|
||||
public var keyShortcuts: [KeyShortcut] {
|
||||
return [KeyShortcut(input: UIKeyCommand.inputEscape, action: { [weak self] in
|
||||
if let strongSelf = self {
|
||||
strongSelf.dismiss()
|
||||
}
|
||||
})]
|
||||
}
|
||||
private let actions: [ContextMenuAction]
|
||||
private let catchTapsOutside: Bool
|
||||
private let hasHapticFeedback: Bool
|
||||
private let blurred: Bool
|
||||
private let skipCoordnateConversion: Bool
|
||||
|
||||
private var layout: ContainerViewLayout?
|
||||
|
||||
public var centerHorizontally = false
|
||||
public var dismissed: (() -> Void)?
|
||||
|
||||
public var dismissOnTap: ((UIView, CGPoint) -> Bool)?
|
||||
|
||||
public init(actions: [ContextMenuAction], catchTapsOutside: Bool = false, hasHapticFeedback: Bool = false, blurred: Bool = false, skipCoordnateConversion: Bool = false) {
|
||||
public init(actions: [ContextMenuAction], catchTapsOutside: Bool, hasHapticFeedback: Bool, blurred: Bool, skipCoordnateConversion: Bool) {
|
||||
self.actions = actions
|
||||
self.catchTapsOutside = catchTapsOutside
|
||||
self.hasHapticFeedback = hasHapticFeedback
|
||||
self.blurred = blurred
|
||||
self.skipCoordnateConversion = skipCoordnateConversion
|
||||
|
||||
super.init(navigationBarPresentationData: nil)
|
||||
|
||||
self.statusBar.statusBarStyle = .Ignore
|
||||
}
|
||||
|
||||
required public init(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override public func loadDisplayNode() {
|
||||
self.displayNode = ContextMenuNode(actions: self.actions, dismiss: { [weak self] in
|
||||
self?.dismissed?()
|
||||
self?.contextMenuNode.animateOut(bounce: (self?.presentationArguments as? ContextMenuControllerPresentationArguments)?.bounce ?? true, completion: {
|
||||
self?.presentingViewController?.dismiss(animated: false)
|
||||
})
|
||||
}, dismissOnTap: { [weak self] view, point in
|
||||
guard let self, let dismissOnTap = self.dismissOnTap else {
|
||||
return false
|
||||
}
|
||||
return dismissOnTap(view, point)
|
||||
}, catchTapsOutside: self.catchTapsOutside, hasHapticFeedback: self.hasHapticFeedback, blurred: self.blurred)
|
||||
self.displayNodeDidLoad()
|
||||
}
|
||||
|
||||
override public func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
|
||||
self.contextMenuNode.animateIn(bounce: (self.presentationArguments as? ContextMenuControllerPresentationArguments)?.bounce ?? true)
|
||||
}
|
||||
|
||||
override public func dismiss(completion: (() -> Void)? = nil) {
|
||||
self.dismissed?()
|
||||
self.contextMenuNode.animateOut(bounce: (self.presentationArguments as? ContextMenuControllerPresentationArguments)?.bounce ?? true, completion: { [weak self] in
|
||||
self?.presentingViewController?.dismiss(animated: false)
|
||||
})
|
||||
}
|
||||
|
||||
override public func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
|
||||
super.containerLayoutUpdated(layout, transition: transition)
|
||||
|
||||
self.contextMenuNode.centerHorizontally = self.centerHorizontally
|
||||
if self.layout != nil && self.layout! != layout {
|
||||
self.dismissed?()
|
||||
self.contextMenuNode.animateOut(bounce: (self.presentationArguments as? ContextMenuControllerPresentationArguments)?.bounce ?? true, completion: { [weak self] in
|
||||
self?.presentingViewController?.dismiss(animated: false)
|
||||
})
|
||||
} else {
|
||||
self.layout = layout
|
||||
|
||||
if let presentationArguments = self.presentationArguments as? ContextMenuControllerPresentationArguments, let (sourceNode, sourceRect, containerNode, containerRect) = presentationArguments.sourceNodeAndRect() {
|
||||
if self.skipCoordnateConversion {
|
||||
self.contextMenuNode.sourceRect = sourceRect
|
||||
self.contextMenuNode.containerRect = containerRect
|
||||
} else {
|
||||
self.contextMenuNode.sourceRect = sourceNode.view.convert(sourceRect, to: nil)
|
||||
self.contextMenuNode.containerRect = containerNode.view.convert(containerRect, to: nil)
|
||||
}
|
||||
} else {
|
||||
self.contextMenuNode.sourceRect = nil
|
||||
self.contextMenuNode.containerRect = nil
|
||||
}
|
||||
|
||||
self.contextMenuNode.containerLayoutUpdated(layout, transition: transition)
|
||||
}
|
||||
}
|
||||
|
||||
override public func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
}
|
||||
}
|
||||
|
||||
private var contextMenuControllerProvider: ((ContextMenuControllerArguments) -> ContextMenuController)?
|
||||
|
||||
public func setContextMenuControllerProvider(_ f: @escaping (ContextMenuControllerArguments) -> ContextMenuController) {
|
||||
contextMenuControllerProvider = f
|
||||
}
|
||||
|
||||
public func makeContextMenuController(actions: [ContextMenuAction], catchTapsOutside: Bool = false, hasHapticFeedback: Bool = false, blurred: Bool = false, skipCoordnateConversion: Bool = false) -> ContextMenuController {
|
||||
guard let contextMenuControllerProvider = contextMenuControllerProvider else {
|
||||
preconditionFailure()
|
||||
}
|
||||
return contextMenuControllerProvider(ContextMenuControllerArguments(
|
||||
actions: actions,
|
||||
catchTapsOutside: catchTapsOutside,
|
||||
hasHapticFeedback: hasHapticFeedback,
|
||||
blurred: blurred,
|
||||
skipCoordnateConversion: skipCoordnateConversion
|
||||
))
|
||||
}
|
||||
|
@ -1,285 +0,0 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import AsyncDisplayKit
|
||||
|
||||
private func generateShadowImage() -> UIImage? {
|
||||
return generateImage(CGSize(width: 30.0, height: 1.0), rotatedContext: { size, context in
|
||||
context.clear(CGRect(origin: CGPoint(), size: size))
|
||||
context.setShadow(offset: CGSize(), blur: 10.0, color: UIColor(white: 0.18, alpha: 1.0).cgColor)
|
||||
context.setFillColor(UIColor(white: 0.18, alpha: 1.0).cgColor)
|
||||
context.fill(CGRect(origin: CGPoint(x: -15.0, y: 0.0), size: CGSize(width: 30.0, height: 1.0)))
|
||||
})
|
||||
}
|
||||
|
||||
private final class ContextMenuContentScrollNode: ASDisplayNode {
|
||||
var contentWidth: CGFloat = 0.0
|
||||
|
||||
private var initialOffset: CGFloat = 0.0
|
||||
|
||||
private let leftShadow: ASImageNode
|
||||
private let rightShadow: ASImageNode
|
||||
private let leftOverscrollNode: ASDisplayNode
|
||||
private let rightOverscrollNode: ASDisplayNode
|
||||
let contentNode: ASDisplayNode
|
||||
|
||||
override init() {
|
||||
self.contentNode = ASDisplayNode()
|
||||
|
||||
let shadowImage = generateShadowImage()
|
||||
|
||||
self.leftShadow = ASImageNode()
|
||||
self.leftShadow.displaysAsynchronously = false
|
||||
self.leftShadow.image = shadowImage
|
||||
self.rightShadow = ASImageNode()
|
||||
self.rightShadow.displaysAsynchronously = false
|
||||
self.rightShadow.image = shadowImage
|
||||
self.rightShadow.transform = CATransform3DMakeScale(-1.0, 1.0, 1.0)
|
||||
|
||||
self.leftOverscrollNode = ASDisplayNode()
|
||||
//self.leftOverscrollNode.backgroundColor = UIColor(white: 0.0, alpha: 0.8)
|
||||
self.rightOverscrollNode = ASDisplayNode()
|
||||
//self.rightOverscrollNode.backgroundColor = UIColor(white: 0.0, alpha: 0.8)
|
||||
|
||||
super.init()
|
||||
|
||||
self.contentNode.addSubnode(self.leftOverscrollNode)
|
||||
self.contentNode.addSubnode(self.rightOverscrollNode)
|
||||
self.addSubnode(self.contentNode)
|
||||
|
||||
self.addSubnode(self.leftShadow)
|
||||
self.addSubnode(self.rightShadow)
|
||||
}
|
||||
|
||||
override func didLoad() {
|
||||
super.didLoad()
|
||||
|
||||
//let panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(self.panGesture(_:)))
|
||||
//self.view.addGestureRecognizer(panRecognizer)
|
||||
}
|
||||
|
||||
@objc func panGesture(_ recognizer: UIPanGestureRecognizer) {
|
||||
switch recognizer.state {
|
||||
case .began:
|
||||
self.initialOffset = self.contentNode.bounds.origin.x
|
||||
case .changed:
|
||||
var bounds = self.contentNode.bounds
|
||||
bounds.origin.x = self.initialOffset - recognizer.translation(in: self.view).x
|
||||
if bounds.origin.x > self.contentWidth - bounds.size.width {
|
||||
let delta = bounds.origin.x - (self.contentWidth - bounds.size.width)
|
||||
bounds.origin.x = self.contentWidth - bounds.size.width + ((1.0 - (1.0 / (((delta) * 0.55 / (50.0)) + 1.0))) * 50.0)
|
||||
}
|
||||
if bounds.origin.x < 0.0 {
|
||||
let delta = -bounds.origin.x
|
||||
bounds.origin.x = -((1.0 - (1.0 / (((delta) * 0.55 / (50.0)) + 1.0))) * 50.0)
|
||||
}
|
||||
self.contentNode.bounds = bounds
|
||||
self.updateShadows(.immediate)
|
||||
case .ended, .cancelled:
|
||||
var bounds = self.contentNode.bounds
|
||||
bounds.origin.x = self.initialOffset - recognizer.translation(in: self.view).x
|
||||
|
||||
var duration = 0.4
|
||||
|
||||
if abs(bounds.origin.x - self.initialOffset) > 10.0 || abs(recognizer.velocity(in: self.view).x) > 100.0 {
|
||||
duration = 0.2
|
||||
if bounds.origin.x < self.initialOffset {
|
||||
bounds.origin.x = 0.0
|
||||
} else {
|
||||
bounds.origin.x = self.contentWidth - bounds.size.width
|
||||
}
|
||||
} else {
|
||||
bounds.origin.x = self.initialOffset
|
||||
}
|
||||
|
||||
if bounds.origin.x > self.contentWidth - bounds.size.width {
|
||||
bounds.origin.x = self.contentWidth - bounds.size.width
|
||||
}
|
||||
if bounds.origin.x < 0.0 {
|
||||
bounds.origin.x = 0.0
|
||||
}
|
||||
let previousBounds = self.contentNode.bounds
|
||||
self.contentNode.bounds = bounds
|
||||
self.contentNode.layer.animateBounds(from: previousBounds, to: bounds, duration: duration, timingFunction: kCAMediaTimingFunctionSpring)
|
||||
self.updateShadows(.animated(duration: duration, curve: .spring))
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
override func layout() {
|
||||
let bounds = self.bounds
|
||||
self.contentNode.frame = bounds
|
||||
self.leftShadow.frame = CGRect(origin: CGPoint(), size: CGSize(width: 30.0, height: bounds.height))
|
||||
self.rightShadow.frame = CGRect(origin: CGPoint(x: bounds.size.width - 30.0, y: 0.0), size: CGSize(width: 30.0, height: bounds.height))
|
||||
self.leftOverscrollNode.frame = bounds.offsetBy(dx: -bounds.width, dy: 0.0)
|
||||
self.rightOverscrollNode.frame = bounds.offsetBy(dx: self.contentWidth, dy: 0.0)
|
||||
self.updateShadows(.immediate)
|
||||
}
|
||||
|
||||
private func updateShadows(_ transition: ContainedViewLayoutTransition) {
|
||||
let bounds = self.contentNode.bounds
|
||||
|
||||
let leftAlpha = max(0.0, min(1.0, bounds.minX / 20.0))
|
||||
transition.updateAlpha(node: self.leftShadow, alpha: leftAlpha)
|
||||
|
||||
let rightAlpha = max(0.0, min(1.0, (self.contentWidth - bounds.maxX) / 20.0))
|
||||
transition.updateAlpha(node: self.rightShadow, alpha: rightAlpha)
|
||||
}
|
||||
}
|
||||
|
||||
final class ContextMenuNode: ASDisplayNode {
|
||||
private let actions: [ContextMenuAction]
|
||||
private let dismiss: () -> Void
|
||||
private let dismissOnTap: (UIView, CGPoint) -> Bool
|
||||
|
||||
private let containerNode: ContextMenuContainerNode
|
||||
private let scrollNode: ContextMenuContentScrollNode
|
||||
private let actionNodes: [ContextMenuActionNode]
|
||||
|
||||
var sourceRect: CGRect?
|
||||
var containerRect: CGRect?
|
||||
var arrowOnBottom: Bool = true
|
||||
var centerHorizontally: Bool = false
|
||||
|
||||
private var dismissedByTouchOutside = false
|
||||
private let catchTapsOutside: Bool
|
||||
|
||||
private let feedback: HapticFeedback?
|
||||
|
||||
init(actions: [ContextMenuAction], dismiss: @escaping () -> Void, dismissOnTap: @escaping (UIView, CGPoint) -> Bool, catchTapsOutside: Bool, hasHapticFeedback: Bool, blurred: Bool = false) {
|
||||
self.actions = actions
|
||||
self.dismiss = dismiss
|
||||
self.dismissOnTap = dismissOnTap
|
||||
self.catchTapsOutside = catchTapsOutside
|
||||
|
||||
self.containerNode = ContextMenuContainerNode(blurred: blurred)
|
||||
self.scrollNode = ContextMenuContentScrollNode()
|
||||
|
||||
self.actionNodes = actions.map { action in
|
||||
return ContextMenuActionNode(action: action, blurred: blurred)
|
||||
}
|
||||
|
||||
if hasHapticFeedback {
|
||||
self.feedback = HapticFeedback()
|
||||
self.feedback?.prepareImpact(.light)
|
||||
} else {
|
||||
self.feedback = nil
|
||||
}
|
||||
|
||||
super.init()
|
||||
|
||||
self.containerNode.addSubnode(self.scrollNode)
|
||||
|
||||
self.addSubnode(self.containerNode)
|
||||
let dismissNode = {
|
||||
dismiss()
|
||||
}
|
||||
for actionNode in self.actionNodes {
|
||||
actionNode.dismiss = dismissNode
|
||||
self.scrollNode.contentNode.addSubnode(actionNode)
|
||||
}
|
||||
}
|
||||
|
||||
func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
|
||||
var unboundActionsWidth: CGFloat = 0.0
|
||||
let actionSeparatorWidth: CGFloat = UIScreenPixel
|
||||
for actionNode in self.actionNodes {
|
||||
if !unboundActionsWidth.isZero {
|
||||
unboundActionsWidth += actionSeparatorWidth
|
||||
}
|
||||
let actionSize = actionNode.measure(CGSize(width: layout.size.width, height: 54.0))
|
||||
actionNode.frame = CGRect(origin: CGPoint(x: unboundActionsWidth, y: 0.0), size: actionSize)
|
||||
unboundActionsWidth += actionSize.width
|
||||
}
|
||||
|
||||
let maxActionsWidth = layout.size.width - 20.0
|
||||
let actionsWidth = min(unboundActionsWidth, maxActionsWidth)
|
||||
|
||||
let sourceRect: CGRect = self.sourceRect ?? CGRect(origin: CGPoint(x: layout.size.width / 2.0, y: layout.size.height / 2.0), size: CGSize())
|
||||
let containerRect: CGRect = self.containerRect ?? self.bounds
|
||||
|
||||
let insets = layout.insets(options: [.statusBar, .input])
|
||||
|
||||
let verticalOrigin: CGFloat
|
||||
var arrowOnBottom = true
|
||||
if sourceRect.minY - 54.0 > containerRect.minY + insets.top {
|
||||
verticalOrigin = sourceRect.minY - 54.0
|
||||
} else {
|
||||
verticalOrigin = min(containerRect.maxY - insets.bottom - 54.0, sourceRect.maxY)
|
||||
arrowOnBottom = false
|
||||
}
|
||||
self.arrowOnBottom = arrowOnBottom
|
||||
|
||||
let horizontalOrigin: CGFloat = floor(max(8.0, min(self.centerHorizontally ? sourceRect.midX - actionsWidth / 2.0 : max(sourceRect.minX + 8.0, sourceRect.midX - actionsWidth / 2.0), layout.size.width - actionsWidth - 8.0)))
|
||||
|
||||
self.containerNode.frame = CGRect(origin: CGPoint(x: horizontalOrigin, y: verticalOrigin), size: CGSize(width: actionsWidth, height: 54.0))
|
||||
self.containerNode.relativeArrowPosition = (sourceRect.midX - horizontalOrigin, arrowOnBottom)
|
||||
|
||||
self.scrollNode.frame = CGRect(origin: CGPoint(), size: CGSize(width: actionsWidth, height: 54.0))
|
||||
self.scrollNode.contentWidth = unboundActionsWidth
|
||||
|
||||
self.containerNode.layout()
|
||||
self.scrollNode.layout()
|
||||
}
|
||||
|
||||
func animateIn(bounce: Bool) {
|
||||
if bounce {
|
||||
self.containerNode.layer.animateSpring(from: NSNumber(value: Float(0.2)), to: NSNumber(value: Float(1.0)), keyPath: "transform.scale", duration: 0.4)
|
||||
let containerPosition = self.containerNode.layer.position
|
||||
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.allowsGroupOpacity = true
|
||||
self.layer.rasterizationScale = UIScreen.main.scale
|
||||
self.layer.shouldRasterize = true
|
||||
self.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.1, completion: { [weak self] _ in
|
||||
self?.allowsGroupOpacity = false
|
||||
self?.layer.shouldRasterize = false
|
||||
})
|
||||
|
||||
if let feedback = self.feedback {
|
||||
feedback.impact(.light)
|
||||
}
|
||||
}
|
||||
|
||||
func animateOut(bounce: Bool, completion: @escaping () -> Void) {
|
||||
self.allowsGroupOpacity = true
|
||||
self.layer.rasterizationScale = UIScreen.main.scale
|
||||
self.layer.shouldRasterize = true
|
||||
self.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak self] _ in
|
||||
self?.allowsGroupOpacity = false
|
||||
self?.layer.shouldRasterize = false
|
||||
completion()
|
||||
})
|
||||
}
|
||||
|
||||
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
|
||||
if let event = event {
|
||||
var eventIsPresses = false
|
||||
if #available(iOSApplicationExtension 9.0, iOS 9.0, *) {
|
||||
eventIsPresses = event.type == .presses
|
||||
}
|
||||
if event.type == .touches || eventIsPresses {
|
||||
if !self.containerNode.frame.contains(point) {
|
||||
if self.dismissOnTap(self.view, point) {
|
||||
self.dismiss()
|
||||
if self.catchTapsOutside {
|
||||
return self.view
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if !self.dismissedByTouchOutside {
|
||||
self.dismissedByTouchOutside = true
|
||||
self.dismiss()
|
||||
}
|
||||
if self.catchTapsOutside {
|
||||
return self.view
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.hitTest(point, with: event)
|
||||
}
|
||||
}
|
@ -3130,7 +3130,7 @@ public final class DrawingToolsInteraction {
|
||||
}
|
||||
}
|
||||
let entityFrame = entityView.convert(entityView.selectionBounds, to: node.view).offsetBy(dx: 0.0, dy: -6.0)
|
||||
let controller = ContextMenuController(actions: actions)
|
||||
let controller = makeContextMenuController(actions: actions)
|
||||
let bounds = node.bounds.insetBy(dx: 0.0, dy: 160.0)
|
||||
self.present(
|
||||
controller,
|
||||
|
@ -527,7 +527,7 @@ public final class RecognizedTextSelectionNode: ASDisplayNode {
|
||||
let _ = self?.dismissSelection()
|
||||
}))
|
||||
|
||||
self.present(ContextMenuController(actions: actions, catchTapsOutside: false, hasHapticFeedback: false), ContextMenuControllerPresentationArguments(sourceNodeAndRect: { [weak self] in
|
||||
self.present(makeContextMenuController(actions: actions, catchTapsOutside: false, hasHapticFeedback: false), ContextMenuControllerPresentationArguments(sourceNodeAndRect: { [weak self] in
|
||||
guard let strongSelf = self, let rootNode = strongSelf.rootNode else {
|
||||
return nil
|
||||
}
|
||||
|
@ -1002,7 +1002,7 @@ final class InstantPageControllerNode: ASDisplayNode, UIScrollViewDelegate {
|
||||
}
|
||||
|
||||
private func longPressMedia(_ media: InstantPageMedia) {
|
||||
let controller = ContextMenuController(actions: [ContextMenuAction(content: .text(title: self.strings.Conversation_ContextMenuCopy, accessibilityLabel: self.strings.Conversation_ContextMenuCopy), action: { [weak self] in
|
||||
let controller = makeContextMenuController(actions: [ContextMenuAction(content: .text(title: self.strings.Conversation_ContextMenuCopy, accessibilityLabel: self.strings.Conversation_ContextMenuCopy), action: { [weak self] in
|
||||
if let strongSelf = self, case let .image(image) = media.media {
|
||||
let media = TelegramMediaImage(imageId: MediaId(namespace: 0, id: 0), representations: image.representations, immediateThumbnailData: image.immediateThumbnailData, reference: nil, partialReference: nil, flags: [])
|
||||
let _ = copyToPasteboard(context: strongSelf.context, postbox: strongSelf.context.account.postbox, userLocation: strongSelf.sourceLocation.userLocation, mediaReference: .standalone(media: media)).start()
|
||||
@ -1147,7 +1147,7 @@ final class InstantPageControllerNode: ASDisplayNode, UIScrollViewDelegate {
|
||||
}))
|
||||
}
|
||||
|
||||
let controller = ContextMenuController(actions: actions)
|
||||
let controller = makeContextMenuController(actions: actions)
|
||||
controller.dismissed = { [weak self] in
|
||||
self?.updateTextSelectionRects([], text: nil)
|
||||
}
|
||||
|
@ -410,7 +410,7 @@ class InstantPageReferenceControllerNode: ViewControllerTracingNode, UIScrollVie
|
||||
coveringRect = coveringRect.union(rects[i])
|
||||
}
|
||||
|
||||
let controller = ContextMenuController(actions: [ContextMenuAction(content: .text(title: self.presentationData.strings.Conversation_ContextMenuCopy, accessibilityLabel: self.presentationData.strings.Conversation_ContextMenuCopy), action: {
|
||||
let controller = makeContextMenuController(actions: [ContextMenuAction(content: .text(title: self.presentationData.strings.Conversation_ContextMenuCopy, accessibilityLabel: self.presentationData.strings.Conversation_ContextMenuCopy), action: {
|
||||
UIPasteboard.general.string = text
|
||||
}), ContextMenuAction(content: .text(title: self.presentationData.strings.Conversation_ContextMenuShare, accessibilityLabel: self.presentationData.strings.Conversation_ContextMenuShare), action: { [weak self] in
|
||||
if let strongSelf = self, case let .Loaded(content) = strongSelf.webPage.content {
|
||||
|
@ -502,7 +502,7 @@ final class InstantPageTextSelectionNode: ASDisplayNode {
|
||||
self?.performAction(text, .share)
|
||||
self?.dismissSelection()
|
||||
}))
|
||||
self.present(ContextMenuController(actions: actions, catchTapsOutside: false, hasHapticFeedback: false), ContextMenuControllerPresentationArguments(sourceNodeAndRect: { [weak self] in
|
||||
self.present(makeContextMenuController(actions: actions, catchTapsOutside: false, hasHapticFeedback: false), ContextMenuControllerPresentationArguments(sourceNodeAndRect: { [weak self] in
|
||||
guard let strongSelf = self, let rootNode = strongSelf.rootNode else {
|
||||
return nil
|
||||
}
|
||||
|
@ -1333,7 +1333,7 @@ public func deviceContactInfoController(context: AccountContext, updatedPresenta
|
||||
return false
|
||||
})
|
||||
if let resultItemNode = resultItemNode {
|
||||
let contextMenuController = ContextMenuController(actions: [ContextMenuAction(content: .text(title: presentationData.strings.Conversation_ContextMenuCopy, accessibilityLabel: presentationData.strings.Conversation_ContextMenuCopy), action: {
|
||||
let contextMenuController = makeContextMenuController(actions: [ContextMenuAction(content: .text(title: presentationData.strings.Conversation_ContextMenuCopy, accessibilityLabel: presentationData.strings.Conversation_ContextMenuCopy), action: {
|
||||
UIPasteboard.general.string = value
|
||||
|
||||
let content: UndoOverlayContent = .copy(text: presentationData.strings.Conversation_TextCopied)
|
||||
|
@ -613,7 +613,7 @@ private class RecentSessionScreenNode: ViewControllerTracingNode, UIScrollViewDe
|
||||
strongSelf.controller?.present(UndoOverlayController(presentationData: presentationData, content: .copy(text: presentationData.strings.Conversation_TextCopied), elevatedLayout: false, animateInAsReplacement: false, action: { _ in return false }), in: .window(.root))
|
||||
}
|
||||
}))
|
||||
let contextMenuController = ContextMenuController(actions: actions)
|
||||
let contextMenuController = makeContextMenuController(actions: actions)
|
||||
self.controller?.present(contextMenuController, in: .window(.root), with: ContextMenuControllerPresentationArguments(sourceNodeAndRect: { [weak self] in
|
||||
if let strongSelf = self {
|
||||
return (node, node.bounds.insetBy(dx: 0.0, dy: -2.0), strongSelf, strongSelf.view.bounds)
|
||||
|
@ -2015,7 +2015,7 @@ public final class StickerPackScreenImpl: ViewController {
|
||||
}
|
||||
}))
|
||||
|
||||
let contextMenuController = ContextMenuController(actions: actions)
|
||||
let contextMenuController = makeContextMenuController(actions: actions)
|
||||
strongSelf.present(contextMenuController, in: .window(.root), with: ContextMenuControllerPresentationArguments(sourceNodeAndRect: { [weak self] in
|
||||
if let strongSelf = self {
|
||||
return (node, frame.insetBy(dx: -40.0, dy: 0.0), strongSelf.controllerNode, strongSelf.controllerNode.view.bounds)
|
||||
|
@ -408,6 +408,7 @@ swift_library(
|
||||
"//submodules/TelegramUI/Components/Chat/ChatNavigationButton",
|
||||
"//submodules/TelegramUI/Components/Chat/ChatLoadingNode",
|
||||
"//submodules/TelegramUI/Components/Settings/PeerNameColorScreen",
|
||||
"//submodules/TelegramUI/Components/ContextMenuScreen",
|
||||
] + select({
|
||||
"@build_bazel_rules_apple//apple:ios_arm64": appcenter_targets,
|
||||
"//build-system:ios_sim_arm64": [],
|
||||
|
@ -1139,7 +1139,7 @@ public class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode {
|
||||
if let subject = item.associatedData.subject, case let .messageOptions(_, _, info) = subject, case .reply = info {
|
||||
enableOtherActions = false
|
||||
} else if item.controllerInteraction.canSetupReply(item.message) == .reply {
|
||||
enableOtherActions = false
|
||||
//enableOtherActions = false
|
||||
}
|
||||
|
||||
if !item.controllerInteraction.canSendMessages() && !enableCopy {
|
||||
|
24
submodules/TelegramUI/Components/ContextMenuScreen/BUILD
Normal file
24
submodules/TelegramUI/Components/ContextMenuScreen/BUILD
Normal file
@ -0,0 +1,24 @@
|
||||
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
|
||||
|
||||
swift_library(
|
||||
name = "ContextMenuScreen",
|
||||
module_name = "ContextMenuScreen",
|
||||
srcs = glob([
|
||||
"Sources/**/*.swift",
|
||||
]),
|
||||
copts = [
|
||||
"-warnings-as-errors",
|
||||
],
|
||||
deps = [
|
||||
"//submodules/AsyncDisplayKit",
|
||||
"//submodules/Display",
|
||||
"//submodules/TelegramPresentationData",
|
||||
"//submodules/ComponentFlow",
|
||||
"//submodules/Components/ViewControllerComponent",
|
||||
"//submodules/AccountContext",
|
||||
"//submodules/AppBundle",
|
||||
],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
],
|
||||
)
|
@ -1,6 +1,7 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import AsyncDisplayKit
|
||||
import Display
|
||||
|
||||
final private class ContextMenuActionButton: HighlightTrackingButton {
|
||||
override func convert(_ point: CGPoint, from view: UIView?) -> CGPoint {
|
@ -0,0 +1,109 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import Display
|
||||
|
||||
public final class ContextMenuControllerImpl: ViewController, KeyShortcutResponder, ContextMenuController {
|
||||
private var contextMenuNode: ContextMenuNode {
|
||||
return self.displayNode as! ContextMenuNode
|
||||
}
|
||||
|
||||
public var keyShortcuts: [KeyShortcut] {
|
||||
return [KeyShortcut(input: UIKeyCommand.inputEscape, action: { [weak self] in
|
||||
if let strongSelf = self {
|
||||
strongSelf.dismiss()
|
||||
}
|
||||
})]
|
||||
}
|
||||
private let actions: [ContextMenuAction]
|
||||
private let catchTapsOutside: Bool
|
||||
private let hasHapticFeedback: Bool
|
||||
private let blurred: Bool
|
||||
private let skipCoordnateConversion: Bool
|
||||
|
||||
private var layout: ContainerViewLayout?
|
||||
|
||||
public var centerHorizontally = false
|
||||
public var dismissed: (() -> Void)?
|
||||
|
||||
public var dismissOnTap: ((UIView, CGPoint) -> Bool)?
|
||||
|
||||
public init(_ arguments: ContextMenuControllerArguments) {
|
||||
self.actions = arguments.actions
|
||||
self.catchTapsOutside = arguments.catchTapsOutside
|
||||
self.hasHapticFeedback = arguments.hasHapticFeedback
|
||||
self.blurred = arguments.blurred
|
||||
self.skipCoordnateConversion = arguments.skipCoordnateConversion
|
||||
|
||||
super.init(navigationBarPresentationData: nil)
|
||||
|
||||
self.statusBar.statusBarStyle = .Ignore
|
||||
}
|
||||
|
||||
required public init(coder aDecoder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
override public func loadDisplayNode() {
|
||||
self.displayNode = ContextMenuNode(actions: self.actions, dismiss: { [weak self] in
|
||||
self?.dismissed?()
|
||||
self?.contextMenuNode.animateOut(bounce: (self?.presentationArguments as? ContextMenuControllerPresentationArguments)?.bounce ?? true, completion: {
|
||||
self?.presentingViewController?.dismiss(animated: false)
|
||||
})
|
||||
}, dismissOnTap: { [weak self] view, point in
|
||||
guard let self, let dismissOnTap = self.dismissOnTap else {
|
||||
return false
|
||||
}
|
||||
return dismissOnTap(view, point)
|
||||
}, catchTapsOutside: self.catchTapsOutside, hasHapticFeedback: self.hasHapticFeedback, blurred: self.blurred)
|
||||
self.displayNodeDidLoad()
|
||||
}
|
||||
|
||||
override public func viewDidAppear(_ animated: Bool) {
|
||||
super.viewDidAppear(animated)
|
||||
|
||||
self.contextMenuNode.animateIn(bounce: (self.presentationArguments as? ContextMenuControllerPresentationArguments)?.bounce ?? true)
|
||||
}
|
||||
|
||||
override public func dismiss(completion: (() -> Void)? = nil) {
|
||||
self.dismissed?()
|
||||
self.contextMenuNode.animateOut(bounce: (self.presentationArguments as? ContextMenuControllerPresentationArguments)?.bounce ?? true, completion: { [weak self] in
|
||||
self?.presentingViewController?.dismiss(animated: false)
|
||||
})
|
||||
}
|
||||
|
||||
override public func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
|
||||
super.containerLayoutUpdated(layout, transition: transition)
|
||||
|
||||
self.contextMenuNode.centerHorizontally = self.centerHorizontally
|
||||
if self.layout != nil && self.layout! != layout {
|
||||
self.dismissed?()
|
||||
self.contextMenuNode.animateOut(bounce: (self.presentationArguments as? ContextMenuControllerPresentationArguments)?.bounce ?? true, completion: { [weak self] in
|
||||
self?.presentingViewController?.dismiss(animated: false)
|
||||
})
|
||||
} else {
|
||||
self.layout = layout
|
||||
|
||||
if let presentationArguments = self.presentationArguments as? ContextMenuControllerPresentationArguments, let (sourceNode, sourceRect, containerNode, containerRect) = presentationArguments.sourceNodeAndRect() {
|
||||
if self.skipCoordnateConversion {
|
||||
self.contextMenuNode.sourceRect = sourceRect
|
||||
self.contextMenuNode.containerRect = containerRect
|
||||
} else {
|
||||
self.contextMenuNode.sourceRect = sourceNode.view.convert(sourceRect, to: nil)
|
||||
self.contextMenuNode.containerRect = containerNode.view.convert(containerRect, to: nil)
|
||||
}
|
||||
} else {
|
||||
self.contextMenuNode.sourceRect = nil
|
||||
self.contextMenuNode.containerRect = nil
|
||||
}
|
||||
|
||||
self.contextMenuNode.containerLayoutUpdated(layout, transition: transition)
|
||||
}
|
||||
}
|
||||
|
||||
override public func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,322 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import AsyncDisplayKit
|
||||
import AppBundle
|
||||
import AsyncDisplayKit
|
||||
import Display
|
||||
|
||||
private func generateShadowImage() -> UIImage? {
|
||||
return generateImage(CGSize(width: 30.0, height: 1.0), rotatedContext: { size, context in
|
||||
context.clear(CGRect(origin: CGPoint(), size: size))
|
||||
context.setShadow(offset: CGSize(), blur: 10.0, color: UIColor(white: 0.18, alpha: 1.0).cgColor)
|
||||
context.setFillColor(UIColor(white: 0.18, alpha: 1.0).cgColor)
|
||||
context.fill(CGRect(origin: CGPoint(x: -15.0, y: 0.0), size: CGSize(width: 30.0, height: 1.0)))
|
||||
})
|
||||
}
|
||||
|
||||
private final class ArrowNode: HighlightTrackingButtonNode {
|
||||
private let isLeft: Bool
|
||||
|
||||
private let iconView: UIImageView
|
||||
private let separatorLayer: SimpleLayer
|
||||
var action: (() -> Void)?
|
||||
|
||||
init(isLeft: Bool) {
|
||||
self.isLeft = isLeft
|
||||
|
||||
self.iconView = UIImageView()
|
||||
self.iconView.image = UIImage(bundleImageName: "Chat/Context Menu/Arrow")!.withRenderingMode(.alwaysTemplate)
|
||||
if isLeft {
|
||||
self.iconView.transform = CGAffineTransformMakeScale(-1.0, 1.0)
|
||||
}
|
||||
|
||||
self.separatorLayer = SimpleLayer()
|
||||
|
||||
super.init()
|
||||
|
||||
self.layer.addSublayer(self.separatorLayer)
|
||||
self.view.addSubview(self.iconView)
|
||||
|
||||
self.addTarget(self, action: #selector(self.pressed), forControlEvents: .touchUpInside)
|
||||
|
||||
self.backgroundColor = UIColor(rgb: 0x2f2f2f)
|
||||
self.highligthedChanged = { [weak self] highlighted in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
self.backgroundColor = highlighted ? UIColor(rgb: 0x8c8e8e) : UIColor(rgb: 0x2f2f2f)
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func pressed() {
|
||||
self.action?()
|
||||
}
|
||||
|
||||
func update(color: UIColor, separatorColor: UIColor, height: CGFloat) -> CGSize {
|
||||
let size = CGSize(width: 33.0, height: height)
|
||||
|
||||
self.iconView.tintColor = color
|
||||
if let icon = self.iconView.image {
|
||||
let iconFrame = CGRect(origin: CGPoint(x: floor((size.width - icon.size.width) * 0.5), y: floor((size.height - icon.size.height) * 0.5)), size: icon.size)
|
||||
self.iconView.center = CGPoint(x: iconFrame.midX, y: iconFrame.midY)
|
||||
self.iconView.bounds = CGRect(origin: CGPoint(), size: iconFrame.size)
|
||||
}
|
||||
|
||||
self.separatorLayer.backgroundColor = separatorColor.cgColor
|
||||
self.separatorLayer.frame = CGRect(origin: CGPoint(x: self.isLeft ? (size.width - UIScreenPixel) : 0.0, y: 0.0), size: CGSize(width: UIScreenPixel, height: size.height))
|
||||
|
||||
return size
|
||||
}
|
||||
}
|
||||
|
||||
final class ContextMenuNode: ASDisplayNode {
|
||||
private let actions: [ContextMenuAction]
|
||||
private let dismiss: () -> Void
|
||||
private let dismissOnTap: (UIView, CGPoint) -> Bool
|
||||
|
||||
private let containerNode: ContextMenuContainerNode
|
||||
private let contentNode: ASDisplayNode
|
||||
private var separatorNodes: [ASDisplayNode] = []
|
||||
private let actionNodes: [ContextMenuActionNode]
|
||||
private let pageLeftNode: ArrowNode
|
||||
private let pageRightNode: ArrowNode
|
||||
|
||||
private var currentPageIndex: Int = 0
|
||||
private var pageCount: Int = 0
|
||||
|
||||
private var validLayout: ContainerViewLayout?
|
||||
|
||||
var sourceRect: CGRect?
|
||||
var containerRect: CGRect?
|
||||
var arrowOnBottom: Bool = true
|
||||
var centerHorizontally: Bool = false
|
||||
|
||||
private var dismissedByTouchOutside = false
|
||||
private let catchTapsOutside: Bool
|
||||
|
||||
private let feedback: HapticFeedback?
|
||||
|
||||
init(actions: [ContextMenuAction], dismiss: @escaping () -> Void, dismissOnTap: @escaping (UIView, CGPoint) -> Bool, catchTapsOutside: Bool, hasHapticFeedback: Bool, blurred: Bool = false) {
|
||||
self.actions = actions
|
||||
self.dismiss = dismiss
|
||||
self.dismissOnTap = dismissOnTap
|
||||
self.catchTapsOutside = catchTapsOutside
|
||||
|
||||
self.containerNode = ContextMenuContainerNode(blurred: blurred)
|
||||
self.contentNode = ASDisplayNode()
|
||||
self.contentNode.clipsToBounds = true
|
||||
|
||||
self.actionNodes = actions.map { action in
|
||||
return ContextMenuActionNode(action: action, blurred: blurred)
|
||||
}
|
||||
|
||||
self.pageLeftNode = ArrowNode(isLeft: true)
|
||||
self.pageRightNode = ArrowNode(isLeft: false)
|
||||
|
||||
if hasHapticFeedback {
|
||||
self.feedback = HapticFeedback()
|
||||
self.feedback?.prepareImpact(.light)
|
||||
} else {
|
||||
self.feedback = nil
|
||||
}
|
||||
|
||||
super.init()
|
||||
|
||||
self.containerNode.addSubnode(self.contentNode)
|
||||
|
||||
self.addSubnode(self.containerNode)
|
||||
let dismissNode = {
|
||||
dismiss()
|
||||
}
|
||||
for actionNode in self.actionNodes {
|
||||
actionNode.dismiss = dismissNode
|
||||
self.contentNode.addSubnode(actionNode)
|
||||
}
|
||||
|
||||
self.containerNode.addSubnode(self.pageLeftNode)
|
||||
self.containerNode.addSubnode(self.pageRightNode)
|
||||
|
||||
let navigatePage: (Bool) -> Void = { [weak self] isLeft in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
var index = self.currentPageIndex
|
||||
if isLeft {
|
||||
index -= 1
|
||||
} else {
|
||||
index += 1
|
||||
}
|
||||
index = max(0, min(index, self.pageCount - 1))
|
||||
if self.currentPageIndex != index {
|
||||
self.currentPageIndex = index
|
||||
|
||||
if let validLayout = self.validLayout {
|
||||
self.containerLayoutUpdated(validLayout, transition: .animated(duration: 0.35, curve: .spring))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.pageLeftNode.action = {
|
||||
navigatePage(true)
|
||||
}
|
||||
self.pageRightNode.action = {
|
||||
navigatePage(false)
|
||||
}
|
||||
}
|
||||
|
||||
func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
|
||||
self.validLayout = layout
|
||||
|
||||
struct Page {
|
||||
var range: Range<Int>
|
||||
var width: CGFloat
|
||||
var offsetX: CGFloat
|
||||
}
|
||||
|
||||
let separatorColor = UIColor(rgb: 0x8c8e8e)
|
||||
|
||||
let height: CGFloat = 54.0
|
||||
|
||||
let pageLeftSize = self.pageLeftNode.update(color: .white, separatorColor: separatorColor, height: height)
|
||||
let pageRightSize = self.pageRightNode.update(color: .white, separatorColor: separatorColor, height: height)
|
||||
|
||||
let maxPageWidth = layout.size.width - 20.0 - pageLeftSize.width - pageRightSize.width
|
||||
var absoluteActionOffsetX: CGFloat = 0.0
|
||||
|
||||
var pages: [Page] = []
|
||||
for i in 0 ..< self.actionNodes.count {
|
||||
if i != 0 {
|
||||
absoluteActionOffsetX += UIScreenPixel
|
||||
}
|
||||
let actionSize = self.actionNodes[i].measure(CGSize(width: layout.size.width, height: height))
|
||||
if pages.isEmpty || (pages[pages.count - 1].width + actionSize.width) > maxPageWidth {
|
||||
pages.append(Page(range: i ..< (i + 1), width: actionSize.width, offsetX: absoluteActionOffsetX))
|
||||
} else {
|
||||
pages[pages.count - 1].width += actionSize.width
|
||||
}
|
||||
let actionFrame = CGRect(origin: CGPoint(x: absoluteActionOffsetX, y: 0.0), size: actionSize)
|
||||
self.actionNodes[i].frame = actionFrame
|
||||
absoluteActionOffsetX += actionSize.width
|
||||
|
||||
let separatorNode: ASDisplayNode
|
||||
if i < self.separatorNodes.count {
|
||||
separatorNode = self.separatorNodes[i]
|
||||
} else {
|
||||
separatorNode = ASDisplayNode()
|
||||
separatorNode.isUserInteractionEnabled = false
|
||||
self.separatorNodes.append(separatorNode)
|
||||
self.contentNode.insertSubnode(separatorNode, at: 0)
|
||||
}
|
||||
separatorNode.backgroundColor = separatorColor
|
||||
separatorNode.frame = CGRect(origin: CGPoint(x: actionFrame.maxX, y: 0.0), size: CGSize(width: UIScreenPixel, height: height))
|
||||
separatorNode.isHidden = i == self.actionNodes.count - 1
|
||||
}
|
||||
|
||||
self.pageCount = pages.count
|
||||
|
||||
if !pages.isEmpty {
|
||||
var leftInset: CGFloat = 0.0
|
||||
if self.currentPageIndex > 0 {
|
||||
leftInset = pageLeftSize.width
|
||||
}
|
||||
var rightInset: CGFloat = 0.0
|
||||
if self.currentPageIndex < pages.count - 1 {
|
||||
rightInset = pageLeftSize.width
|
||||
}
|
||||
|
||||
let offsetX = -pages[self.currentPageIndex].offsetX
|
||||
|
||||
let contentWidth = leftInset + rightInset + pages[self.currentPageIndex].width
|
||||
|
||||
let contentNodeFrame = CGRect(origin: CGPoint(x: leftInset, y: 0.0), size: CGSize(width: pages[self.currentPageIndex].width, height: height))
|
||||
transition.updatePosition(node: self.contentNode, position: CGPoint(x: contentNodeFrame.midX, y: contentNodeFrame.midY))
|
||||
transition.updateBounds(node: self.contentNode, bounds: CGRect(origin: CGPoint(x: -offsetX, y: 0.0), size: contentNodeFrame.size))
|
||||
|
||||
transition.updateFrame(node: self.pageLeftNode, frame: CGRect(origin: CGPoint(x: leftInset - pageLeftSize.width, y: 0.0), size: pageLeftSize))
|
||||
transition.updateFrame(node: self.pageRightNode, frame: CGRect(origin: CGPoint(x: contentWidth - rightInset, y: 0.0), size: pageRightSize))
|
||||
|
||||
let sourceRect: CGRect = self.sourceRect ?? CGRect(origin: CGPoint(x: layout.size.width / 2.0, y: layout.size.height / 2.0), size: CGSize())
|
||||
let containerRect: CGRect = self.containerRect ?? CGRect(origin: CGPoint(), size: layout.size)
|
||||
|
||||
let insets = layout.insets(options: [.statusBar, .input])
|
||||
|
||||
let verticalOrigin: CGFloat
|
||||
var arrowOnBottom = true
|
||||
if sourceRect.minY - height > containerRect.minY + insets.top {
|
||||
verticalOrigin = sourceRect.minY - height
|
||||
} else {
|
||||
verticalOrigin = min(containerRect.maxY - insets.bottom - height, sourceRect.maxY)
|
||||
arrowOnBottom = false
|
||||
}
|
||||
self.arrowOnBottom = arrowOnBottom
|
||||
|
||||
let horizontalOrigin: CGFloat = floor(max(8.0, min(self.centerHorizontally ? sourceRect.midX - contentWidth / 2.0 : max(sourceRect.minX + 8.0, sourceRect.midX - contentWidth / 2.0), layout.size.width - contentWidth - 8.0)))
|
||||
|
||||
let containerFrame = CGRect(origin: CGPoint(x: horizontalOrigin, y: verticalOrigin), size: CGSize(width: contentWidth, height: height))
|
||||
transition.updateFrame(node: self.containerNode, frame: containerFrame)
|
||||
self.containerNode.relativeArrowPosition = (sourceRect.midX - horizontalOrigin, arrowOnBottom)
|
||||
self.containerNode.updateLayout(transition: transition)
|
||||
}
|
||||
}
|
||||
|
||||
func animateIn(bounce: Bool) {
|
||||
if bounce {
|
||||
self.containerNode.layer.animateSpring(from: NSNumber(value: Float(0.2)), to: NSNumber(value: Float(1.0)), keyPath: "transform.scale", duration: 0.4)
|
||||
let containerPosition = self.containerNode.layer.position
|
||||
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.allowsGroupOpacity = true
|
||||
self.layer.rasterizationScale = UIScreen.main.scale
|
||||
self.layer.shouldRasterize = true
|
||||
self.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.1, completion: { [weak self] _ in
|
||||
self?.allowsGroupOpacity = false
|
||||
self?.layer.shouldRasterize = false
|
||||
})
|
||||
|
||||
if let feedback = self.feedback {
|
||||
feedback.impact(.light)
|
||||
}
|
||||
}
|
||||
|
||||
func animateOut(bounce: Bool, completion: @escaping () -> Void) {
|
||||
self.allowsGroupOpacity = true
|
||||
self.layer.rasterizationScale = UIScreen.main.scale
|
||||
self.layer.shouldRasterize = true
|
||||
self.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak self] _ in
|
||||
self?.allowsGroupOpacity = false
|
||||
self?.layer.shouldRasterize = false
|
||||
completion()
|
||||
})
|
||||
}
|
||||
|
||||
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
|
||||
if let event = event {
|
||||
var eventIsPresses = false
|
||||
if #available(iOSApplicationExtension 9.0, iOS 9.0, *) {
|
||||
eventIsPresses = event.type == .presses
|
||||
}
|
||||
if event.type == .touches || eventIsPresses {
|
||||
if !self.containerNode.frame.contains(point) {
|
||||
if self.dismissOnTap(self.view, point) {
|
||||
self.dismiss()
|
||||
if self.catchTapsOutside {
|
||||
return self.view
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if !self.dismissedByTouchOutside {
|
||||
self.dismissedByTouchOutside = true
|
||||
self.dismiss()
|
||||
}
|
||||
if self.catchTapsOutside {
|
||||
return self.view
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.hitTest(point, with: event)
|
||||
}
|
||||
}
|
@ -38,6 +38,7 @@ swift_library(
|
||||
"//submodules/TelegramUI/Components/MultiAnimationRenderer",
|
||||
"//submodules/TelegramUI/Components/TelegramAccountAuxiliaryMethods",
|
||||
"//submodules/TelegramUI/Components/PeerSelectionController",
|
||||
"//submodules/TelegramUI/Components/ContextMenuScreen",
|
||||
],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
|
@ -30,6 +30,7 @@ import MultiAnimationRenderer
|
||||
import TelegramUIDeclareEncodables
|
||||
import TelegramAccountAuxiliaryMethods
|
||||
import PeerSelectionController
|
||||
import ContextMenuScreen
|
||||
|
||||
private var installedSharedLogger = false
|
||||
|
||||
@ -457,6 +458,9 @@ public class ShareRootControllerImpl {
|
||||
(environment as? ShareControllerEnvironmentExtension)?.accounts = otherAccounts.compactMap { $0.account as? ShareControllerAccountContextExtension }
|
||||
|
||||
initializeLegacyComponents(application: nil, currentSizeClassGetter: { return .compact }, currentHorizontalClassGetter: { return .compact }, documentsPath: "", currentApplicationBounds: { return CGRect() }, canOpenUrl: { _ in return false}, openUrl: { _ in })
|
||||
setContextMenuControllerProvider { arguments in
|
||||
return ContextMenuControllerImpl(arguments)
|
||||
}
|
||||
|
||||
let displayShare: () -> Void = {
|
||||
var cancelImpl: (() -> Void)?
|
||||
|
@ -3304,7 +3304,7 @@ final class StoryItemSetContainerSendMessage {
|
||||
frame = view.controlsContainerView.convert(frame, to: nil)
|
||||
|
||||
let node = controller.displayNode
|
||||
let menuController = ContextMenuController(actions: actions, blurred: true)
|
||||
let menuController = makeContextMenuController(actions: actions, blurred: true)
|
||||
menuController.centerHorizontally = true
|
||||
menuController.dismissed = { [weak self, weak view] in
|
||||
if let self, let view {
|
||||
|
@ -40,6 +40,7 @@ import ManagedFile
|
||||
import DeviceProximity
|
||||
import MediaEditor
|
||||
import TelegramUIDeclareEncodables
|
||||
import ContextMenuScreen
|
||||
|
||||
#if canImport(AppCenter)
|
||||
import AppCenter
|
||||
@ -602,6 +603,9 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
|
||||
}, openUrl: { url in
|
||||
UIApplication.shared.open(url, options: [:], completionHandler: nil)
|
||||
})
|
||||
setContextMenuControllerProvider { arguments in
|
||||
return ContextMenuControllerImpl(arguments)
|
||||
}
|
||||
|
||||
if #available(iOS 10.0, *) {
|
||||
UNUserNotificationCenter.current().delegate = self
|
||||
|
@ -452,11 +452,13 @@ private func generateChatReplyOptionItems(selfController: ChatControllerImpl, ch
|
||||
})))
|
||||
}
|
||||
|
||||
items.append(.separator)
|
||||
|
||||
items.append(.action(ContextMenuActionItem(text: "Apply Changes", icon: { theme in return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Select"), color: theme.contextMenu.primaryColor) }, action: { _, f in
|
||||
f(.default)
|
||||
})))
|
||||
if !items.isEmpty {
|
||||
items.append(.separator)
|
||||
|
||||
items.append(.action(ContextMenuActionItem(text: "Apply Changes", icon: { theme in return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Select"), color: theme.contextMenu.primaryColor) }, action: { _, f in
|
||||
f(.default)
|
||||
})))
|
||||
}
|
||||
|
||||
if replySubject.quote != nil {
|
||||
items.append(.action(ContextMenuActionItem(text: "Remove Quote", textColor: .destructive, icon: { theme in return generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/QuoteRemove"), color: theme.contextMenu.destructiveColor) }, action: { [weak selfController] c, f in
|
||||
|
@ -3710,7 +3710,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
|
||||
}))
|
||||
}
|
||||
|
||||
let contextMenuController = ContextMenuController(actions: actions)
|
||||
let contextMenuController = makeContextMenuController(actions: actions)
|
||||
strongSelf.controller?.present(contextMenuController, in: .window(.root), with: ContextMenuControllerPresentationArguments(sourceNodeAndRect: { [weak self] in
|
||||
if let strongSelf = self {
|
||||
return (node, node.bounds.insetBy(dx: 0.0, dy: -2.0), strongSelf, strongSelf.view.bounds)
|
||||
@ -7481,7 +7481,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
|
||||
}))
|
||||
}
|
||||
|
||||
let contextMenuController = ContextMenuController(actions: actions)
|
||||
let contextMenuController = makeContextMenuController(actions: actions)
|
||||
controller.present(contextMenuController, in: .window(.root), with: ContextMenuControllerPresentationArguments(sourceNodeAndRect: { [weak self, weak sourceNode] in
|
||||
if let controller = self?.controller, let sourceNode = sourceNode {
|
||||
var rect = sourceNode.bounds.insetBy(dx: 0.0, dy: 2.0)
|
||||
@ -7496,7 +7496,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
|
||||
})
|
||||
}
|
||||
case let .phone(phone):
|
||||
let contextMenuController = ContextMenuController(actions: [ContextMenuAction(content: .text(title: self.presentationData.strings.Conversation_ContextMenuCopy, accessibilityLabel: self.presentationData.strings.Conversation_ContextMenuCopy), action: { [weak self] in
|
||||
let contextMenuController = makeContextMenuController(actions: [ContextMenuAction(content: .text(title: self.presentationData.strings.Conversation_ContextMenuCopy, accessibilityLabel: self.presentationData.strings.Conversation_ContextMenuCopy), action: { [weak self] in
|
||||
UIPasteboard.general.string = phone
|
||||
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
@ -7532,7 +7532,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
|
||||
content = .linkCopied(text: self.presentationData.strings.Conversation_LinkCopied)
|
||||
}
|
||||
|
||||
let contextMenuController = ContextMenuController(actions: [ContextMenuAction(content: .text(title: self.presentationData.strings.Conversation_ContextMenuCopy, accessibilityLabel: self.presentationData.strings.Conversation_ContextMenuCopy), action: { [weak self] in
|
||||
let contextMenuController = makeContextMenuController(actions: [ContextMenuAction(content: .text(title: self.presentationData.strings.Conversation_ContextMenuCopy, accessibilityLabel: self.presentationData.strings.Conversation_ContextMenuCopy), action: { [weak self] in
|
||||
UIPasteboard.general.string = text
|
||||
|
||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||
|
@ -220,6 +220,7 @@ public final class TextSelectionNode: ASDisplayNode {
|
||||
private let updateIsActive: (Bool) -> Void
|
||||
public var canBeginSelection: (CGPoint) -> Bool = { _ in true }
|
||||
public var updateRange: ((NSRange?) -> Void)?
|
||||
public var presentMenu: ((UIView, CGPoint, [ContextMenuAction]) -> Void)?
|
||||
private let present: (ViewController, Any?) -> Void
|
||||
private let rootNode: () -> ASDisplayNode?
|
||||
private let performAction: (NSAttributedString, TextSelectionAction) -> Void
|
||||
@ -713,7 +714,8 @@ public final class TextSelectionNode: ASDisplayNode {
|
||||
self?.performAction(string, .quote(range: adjustedRange.lowerBound ..< adjustedRange.upperBound))
|
||||
self?.cancelSelection()
|
||||
}))
|
||||
} else if self.enableLookup {
|
||||
}
|
||||
if self.enableLookup {
|
||||
actions.append(ContextMenuAction(content: .text(title: self.strings.Conversation_ContextMenuLookUp, accessibilityLabel: self.strings.Conversation_ContextMenuLookUp), action: { [weak self] in
|
||||
self?.performAction(string, .lookup)
|
||||
self?.cancelSelection()
|
||||
@ -753,7 +755,7 @@ public final class TextSelectionNode: ASDisplayNode {
|
||||
|
||||
self.contextMenu?.dismiss()
|
||||
|
||||
let contextMenu = ContextMenuController(actions: actions, catchTapsOutside: false, hasHapticFeedback: false, skipCoordnateConversion: self.menuSkipCoordnateConversion)
|
||||
let contextMenu = makeContextMenuController(actions: actions, catchTapsOutside: false, hasHapticFeedback: false, skipCoordnateConversion: self.menuSkipCoordnateConversion)
|
||||
contextMenu.dismissOnTap = { [weak self] view, point in
|
||||
guard let self else {
|
||||
return true
|
||||
|
Loading…
x
Reference in New Issue
Block a user