mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Shared media update
This commit is contained in:
@@ -68,6 +68,18 @@ public struct ContextMenuActionBadge {
|
||||
}
|
||||
|
||||
public final class ContextMenuActionItem {
|
||||
public final class Action {
|
||||
public let controller: ContextControllerProtocol
|
||||
public let dismissWithResult: (ContextMenuActionResult) -> Void
|
||||
public let updateAction: (ContextMenuActionItem) -> Void
|
||||
|
||||
init(controller: ContextControllerProtocol, dismissWithResult: @escaping (ContextMenuActionResult) -> Void, updateAction: @escaping (ContextMenuActionItem) -> Void) {
|
||||
self.controller = controller
|
||||
self.dismissWithResult = dismissWithResult
|
||||
self.updateAction = updateAction
|
||||
}
|
||||
}
|
||||
|
||||
public let text: String
|
||||
public let textColor: ContextMenuActionItemTextColor
|
||||
public let textFont: ContextMenuActionItemFont
|
||||
@@ -75,9 +87,44 @@ public final class ContextMenuActionItem {
|
||||
public let badge: ContextMenuActionBadge?
|
||||
public let icon: (PresentationTheme) -> UIImage?
|
||||
public let iconSource: ContextMenuActionItemIconSource?
|
||||
public let action: ((ContextControllerProtocol, @escaping (ContextMenuActionResult) -> Void) -> Void)?
|
||||
public let action: ((Action) -> Void)?
|
||||
|
||||
public init(text: String, textColor: ContextMenuActionItemTextColor = .primary, textLayout: ContextMenuActionItemTextLayout = .twoLinesMax, textFont: ContextMenuActionItemFont = .regular, badge: ContextMenuActionBadge? = nil, icon: @escaping (PresentationTheme) -> UIImage?, iconSource: ContextMenuActionItemIconSource? = nil, action: ((ContextControllerProtocol, @escaping (ContextMenuActionResult) -> Void) -> Void)?) {
|
||||
convenience public init(
|
||||
text: String,
|
||||
textColor: ContextMenuActionItemTextColor = .primary,
|
||||
textLayout: ContextMenuActionItemTextLayout = .twoLinesMax,
|
||||
textFont: ContextMenuActionItemFont = .regular,
|
||||
badge: ContextMenuActionBadge? = nil,
|
||||
icon: @escaping (PresentationTheme) -> UIImage?,
|
||||
iconSource: ContextMenuActionItemIconSource? = nil,
|
||||
action: ((ContextControllerProtocol, @escaping (ContextMenuActionResult) -> Void) -> Void)?
|
||||
) {
|
||||
self.init(
|
||||
text: text,
|
||||
textColor: textColor,
|
||||
textLayout: textLayout,
|
||||
textFont: textFont,
|
||||
badge: badge,
|
||||
icon: icon,
|
||||
iconSource: iconSource,
|
||||
action: action.flatMap { action in
|
||||
return { impl in
|
||||
action(impl.controller, impl.dismissWithResult)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
public init(
|
||||
text: String,
|
||||
textColor: ContextMenuActionItemTextColor = .primary,
|
||||
textLayout: ContextMenuActionItemTextLayout = .twoLinesMax,
|
||||
textFont: ContextMenuActionItemFont = .regular,
|
||||
badge: ContextMenuActionBadge? = nil,
|
||||
icon: @escaping (PresentationTheme) -> UIImage?,
|
||||
iconSource: ContextMenuActionItemIconSource? = nil,
|
||||
action: ((Action) -> Void)?
|
||||
) {
|
||||
self.text = text
|
||||
self.textColor = textColor
|
||||
self.textFont = textFont
|
||||
@@ -215,6 +262,7 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi
|
||||
self.contentContainerNode = ContextContentContainerNode()
|
||||
|
||||
var feedbackTap: (() -> Void)?
|
||||
var updateLayout: (() -> Void)?
|
||||
|
||||
var blurBackground = true
|
||||
if case .reference = source {
|
||||
@@ -228,6 +276,8 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi
|
||||
return controller
|
||||
}, actionSelected: { result in
|
||||
beginDismiss(result)
|
||||
}, requestLayout: {
|
||||
updateLayout?()
|
||||
}, feedbackTap: {
|
||||
feedbackTap?()
|
||||
}, blurBackground: blurBackground)
|
||||
@@ -237,6 +287,10 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi
|
||||
feedbackTap = { [weak self] in
|
||||
self?.hapticFeedback.tap()
|
||||
}
|
||||
|
||||
updateLayout = { [weak self] in
|
||||
self?.updateLayout()
|
||||
}
|
||||
|
||||
self.scrollNode.view.delegate = self
|
||||
|
||||
@@ -1059,6 +1113,8 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi
|
||||
return self?.getController()
|
||||
}, actionSelected: { [weak self] result in
|
||||
self?.beginDismiss(result)
|
||||
}, requestLayout: { [weak self] in
|
||||
self?.updateLayout()
|
||||
}, feedbackTap: { [weak self] in
|
||||
self?.hapticFeedback.tap()
|
||||
}, blurBackground: self.blurBackground)
|
||||
@@ -1086,6 +1142,12 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi
|
||||
self.updateLayout(layout: validLayout, transition: .immediate, previousActionsContainerNode: nil, previousActionsContainerFrame: nil)
|
||||
}
|
||||
}
|
||||
|
||||
func updateLayout() {
|
||||
if let layout = self.validLayout {
|
||||
self.updateLayout(layout: layout, transition: .immediate, previousActionsContainerNode: nil)
|
||||
}
|
||||
}
|
||||
|
||||
func updateLayout(layout: ContainerViewLayout, transition: ContainedViewLayoutTransition, previousActionsContainerNode: ContextActionsContainerNode?, previousActionsContainerFrame: CGRect? = nil, previousActionsTransition: ContextController.PreviousActionsTransition = .scale) {
|
||||
if self.isAnimatingOut {
|
||||
@@ -1573,10 +1635,13 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi
|
||||
return nil
|
||||
}
|
||||
let mappedPoint = self.view.convert(point, to: self.scrollNode.view)
|
||||
var maybePassthrough = false
|
||||
if let maybeContentNode = self.contentContainerNode.contentNode {
|
||||
switch maybeContentNode {
|
||||
case .reference:
|
||||
break
|
||||
if let controller = self.getController() as? ContextController {
|
||||
maybePassthrough = controller.passthroughTouchEvents
|
||||
}
|
||||
case let .extracted(contentParentNode, _):
|
||||
if case let .extracted(source) = self.source {
|
||||
if !source.ignoreContentTouches {
|
||||
@@ -1615,6 +1680,11 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi
|
||||
if self.actionsContainerNode.frame.contains(mappedPoint) {
|
||||
return self.actionsContainerNode.hitTest(self.view.convert(point, to: self.actionsContainerNode.view), with: event)
|
||||
}
|
||||
|
||||
if maybePassthrough {
|
||||
self.getController()?.dismiss(completion: nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
return self.dismissNode.view
|
||||
}
|
||||
@@ -1776,6 +1846,8 @@ public final class ContextController: ViewController, StandalonePresentableContr
|
||||
|
||||
public var useComplexItemsTransitionAnimation = false
|
||||
public var immediateItemsTransitionAnimation = false
|
||||
|
||||
public var passthroughTouchEvents = false
|
||||
|
||||
private var shouldBeDismissedDisposable: Disposable?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user