mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-25 17:43:18 +00:00
Attachment menu improvements
This commit is contained in:
parent
ac543cb093
commit
e70f17ff2d
@ -311,7 +311,7 @@ final class AttachmentContainer: ASDisplayNode, UIGestureRecognizerDelegate {
|
|||||||
}
|
}
|
||||||
transition.updateFrame(node: self.wrappingNode, frame: CGRect(origin: CGPoint(x: 0.0, y: topInset), size: layout.size))
|
transition.updateFrame(node: self.wrappingNode, frame: CGRect(origin: CGPoint(x: 0.0, y: topInset), size: layout.size))
|
||||||
|
|
||||||
let modalProgress = isLandscape ? 0.0 : (1.0 - topInset / defaultTopInset)
|
let modalProgress = isLandscape ? 0.0 : (1.0 - topInset / defaultTopInset)
|
||||||
self.updateModalProgress?(modalProgress, transition)
|
self.updateModalProgress?(modalProgress, transition)
|
||||||
|
|
||||||
let containerLayout: ContainerViewLayout
|
let containerLayout: ContainerViewLayout
|
||||||
|
|||||||
@ -66,15 +66,18 @@ public class AttachmentController: ViewController {
|
|||||||
private let container: AttachmentContainer
|
private let container: AttachmentContainer
|
||||||
let panel: AttachmentPanel
|
let panel: AttachmentPanel
|
||||||
|
|
||||||
private var validLayout: ContainerViewLayout?
|
|
||||||
private var modalProgress: CGFloat = 0.0
|
|
||||||
|
|
||||||
private var currentType: AttachmentButtonType?
|
private var currentType: AttachmentButtonType?
|
||||||
private var currentController: AttachmentContainable?
|
private var currentController: AttachmentContainable?
|
||||||
|
|
||||||
private let captionDisposable = MetaDisposable()
|
private var validLayout: ContainerViewLayout?
|
||||||
|
private var modalProgress: CGFloat = 0.0
|
||||||
|
private var isDismissing = false
|
||||||
|
|
||||||
|
private let captionDisposable = MetaDisposable()
|
||||||
private let mediaSelectionCountDisposable = MetaDisposable()
|
private let mediaSelectionCountDisposable = MetaDisposable()
|
||||||
|
|
||||||
|
private var selectionCount: Int = 0
|
||||||
|
|
||||||
fileprivate var mediaPickerContext: AttachmentMediaPickerContext? {
|
fileprivate var mediaPickerContext: AttachmentMediaPickerContext? {
|
||||||
didSet {
|
didSet {
|
||||||
if let mediaPickerContext = self.mediaPickerContext {
|
if let mediaPickerContext = self.mediaPickerContext {
|
||||||
@ -113,7 +116,7 @@ public class AttachmentController: ViewController {
|
|||||||
self.addSubnode(self.dim)
|
self.addSubnode(self.dim)
|
||||||
|
|
||||||
self.container.updateModalProgress = { [weak self] progress, transition in
|
self.container.updateModalProgress = { [weak self] progress, transition in
|
||||||
if let strongSelf = self, let layout = strongSelf.validLayout {
|
if let strongSelf = self, let layout = strongSelf.validLayout, !strongSelf.isDismissing {
|
||||||
strongSelf.controller?.updateModalStyleOverlayTransitionFactor(progress, transition: transition)
|
strongSelf.controller?.updateModalStyleOverlayTransitionFactor(progress, transition: transition)
|
||||||
|
|
||||||
strongSelf.modalProgress = progress
|
strongSelf.modalProgress = progress
|
||||||
@ -195,7 +198,6 @@ public class AttachmentController: ViewController {
|
|||||||
self.switchToController(.gallery, false)
|
self.switchToController(.gallery, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var selectionCount: Int = 0
|
|
||||||
private func updateSelectionCount(_ count: Int) {
|
private func updateSelectionCount(_ count: Int) {
|
||||||
self.selectionCount = count
|
self.selectionCount = count
|
||||||
if let layout = self.validLayout {
|
if let layout = self.validLayout {
|
||||||
@ -209,29 +211,6 @@ public class AttachmentController: ViewController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
|
|
||||||
if let controller = self.controller, controller.isInteractionDisabled() {
|
|
||||||
return self.view
|
|
||||||
} else {
|
|
||||||
return super.hitTest(point, with: event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func dismiss(animated: Bool, completion: @escaping () -> Void = {}) {
|
|
||||||
if animated {
|
|
||||||
let positionTransition: ContainedViewLayoutTransition = .animated(duration: 0.25, curve: .easeInOut)
|
|
||||||
positionTransition.updatePosition(node: self.container, position: CGPoint(x: self.container.position.x, y: self.bounds.height + self.container.bounds.height / 2.0 + self.bounds.height), beginWithCurrentState: true, completion: { [weak self] _ in
|
|
||||||
let _ = self?.container.dismiss(transition: .immediate, completion: completion)
|
|
||||||
})
|
|
||||||
let alphaTransition: ContainedViewLayoutTransition = .animated(duration: 0.25, curve: .easeInOut)
|
|
||||||
alphaTransition.updateAlpha(node: self.dim, alpha: 0.0)
|
|
||||||
|
|
||||||
self.controller?.updateModalStyleOverlayTransitionFactor(0.0, transition: positionTransition)
|
|
||||||
} else {
|
|
||||||
self.controller?.dismiss(animated: false, completion: nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func switchToController(_ type: AttachmentButtonType, _ ascending: Bool) {
|
func switchToController(_ type: AttachmentButtonType, _ ascending: Bool) {
|
||||||
guard self.currentType != type else {
|
guard self.currentType != type else {
|
||||||
if let controller = self.currentController {
|
if let controller = self.currentController {
|
||||||
@ -286,16 +265,44 @@ public class AttachmentController: ViewController {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func animateIn(transition: ContainedViewLayoutTransition) {
|
func animateIn() {
|
||||||
ContainedViewLayoutTransition.animated(duration: 0.3, curve: .linear).updateAlpha(node: self.dim, alpha: 1.0)
|
ContainedViewLayoutTransition.animated(duration: 0.3, curve: .linear).updateAlpha(node: self.dim, alpha: 1.0)
|
||||||
|
|
||||||
transition.animatePositionAdditive(node: self.container, offset: CGPoint(x: 0.0, y: self.bounds.height + self.container.bounds.height / 2.0 - (self.container.position.y - self.bounds.height)))
|
let targetPosition = self.container.position
|
||||||
|
let startPosition = targetPosition.offsetBy(dx: 0.0, dy: self.bounds.height)
|
||||||
|
|
||||||
|
self.container.position = startPosition
|
||||||
|
let transition = ContainedViewLayoutTransition.animated(duration: 0.4, curve: .spring)
|
||||||
|
transition.animateView({
|
||||||
|
self.container.position = targetPosition
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func animateOut(completion: @escaping () -> Void = {}) {
|
||||||
|
self.isDismissing = true
|
||||||
|
|
||||||
|
let positionTransition: ContainedViewLayoutTransition = .animated(duration: 0.25, curve: .easeInOut)
|
||||||
|
positionTransition.updatePosition(node: self.container, position: CGPoint(x: self.container.position.x, y: self.bounds.height + self.container.bounds.height / 2.0), completion: { [weak self] _ in
|
||||||
|
let _ = self?.container.dismiss(transition: .immediate, completion: completion)
|
||||||
|
})
|
||||||
|
let alphaTransition: ContainedViewLayoutTransition = .animated(duration: 0.25, curve: .easeInOut)
|
||||||
|
alphaTransition.updateAlpha(node: self.dim, alpha: 0.0)
|
||||||
|
|
||||||
|
self.controller?.updateModalStyleOverlayTransitionFactor(0.0, transition: positionTransition)
|
||||||
}
|
}
|
||||||
|
|
||||||
func scrollToTop() {
|
func scrollToTop() {
|
||||||
self.currentController?.scrollToTop?()
|
self.currentController?.scrollToTop?()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
|
||||||
|
if let controller = self.controller, controller.isInteractionDisabled() {
|
||||||
|
return self.view
|
||||||
|
} else {
|
||||||
|
return super.hitTest(point, with: event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private var isCollapsed: Bool = false
|
private var isCollapsed: Bool = false
|
||||||
private var isUpdatingContainer = false
|
private var isUpdatingContainer = false
|
||||||
private var switchingController = false
|
private var switchingController = false
|
||||||
@ -318,7 +325,7 @@ public class AttachmentController: ViewController {
|
|||||||
}
|
}
|
||||||
panelTransition.updateFrame(node: self.panel, frame: CGRect(origin: CGPoint(x: 0.0, y: layout.size.height - panelHeight), size: CGSize(width: layout.size.width, height: panelHeight)))
|
panelTransition.updateFrame(node: self.panel, frame: CGRect(origin: CGPoint(x: 0.0, y: layout.size.height - panelHeight), size: CGSize(width: layout.size.width, height: panelHeight)))
|
||||||
|
|
||||||
if !self.isUpdatingContainer {
|
if !self.isUpdatingContainer && !self.isDismissing {
|
||||||
self.isUpdatingContainer = true
|
self.isUpdatingContainer = true
|
||||||
|
|
||||||
let containerTransition: ContainedViewLayoutTransition
|
let containerTransition: ContainedViewLayoutTransition
|
||||||
@ -341,7 +348,7 @@ public class AttachmentController: ViewController {
|
|||||||
self.addSubnode(self.container)
|
self.addSubnode(self.container)
|
||||||
self.container.addSubnode(self.panel)
|
self.container.addSubnode(self.panel)
|
||||||
|
|
||||||
self.animateIn(transition: transition)
|
self.animateIn()
|
||||||
}
|
}
|
||||||
|
|
||||||
self.isUpdatingContainer = false
|
self.isUpdatingContainer = false
|
||||||
@ -387,8 +394,8 @@ public class AttachmentController: ViewController {
|
|||||||
public override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
|
public override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
|
||||||
self.view.endEditing(true)
|
self.view.endEditing(true)
|
||||||
if flag {
|
if flag {
|
||||||
self.node.dismiss(animated: true, completion: {
|
self.node.animateOut(completion: {
|
||||||
super.dismiss(animated: flag, completion: {})
|
super.dismiss(animated: false, completion: {})
|
||||||
completion?()
|
completion?()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -284,11 +284,9 @@ public class InteractiveCheckNode: CheckNode {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if highlighted {
|
if highlighted {
|
||||||
let transition: ContainedViewLayoutTransition = .animated(duration: 0.3, curve: .spring)
|
strongSelf.layer.animateScale(from: 1.0, to: 0.85, duration: 0.15, removeOnCompletion: false)
|
||||||
transition.updateTransformScale(node: strongSelf, scale: 0.85)
|
} else if let presentationLayer = strongSelf.layer.presentation() {
|
||||||
} else {
|
strongSelf.layer.animateScale(from: CGFloat((presentationLayer.value(forKeyPath: "transform.scale.y") as? NSNumber)?.floatValue ?? 1.0), to: 1.0, duration: 0.25, removeOnCompletion: false)
|
||||||
let transition: ContainedViewLayoutTransition = .animated(duration: 0.5, curve: .spring)
|
|
||||||
transition.updateTransformScale(node: strongSelf, scale: 1.0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11185,6 +11185,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
|||||||
|> deliverOnMainQueue).start(next: { [weak self] configuration in
|
|> deliverOnMainQueue).start(next: { [weak self] configuration in
|
||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
let controller = WebSearchController(context: strongSelf.context, updatedPresentationData: strongSelf.updatedPresentationData, peer: EnginePeer(peer), chatLocation: strongSelf.chatLocation, configuration: configuration, mode: .media(attachment: attachment, completion: { [weak self] results, selectionState, editingState, silentPosting in
|
let controller = WebSearchController(context: strongSelf.context, updatedPresentationData: strongSelf.updatedPresentationData, peer: EnginePeer(peer), chatLocation: strongSelf.chatLocation, configuration: configuration, mode: .media(attachment: attachment, completion: { [weak self] results, selectionState, editingState, silentPosting in
|
||||||
|
self?.attachmentController?.dismiss(animated: true, completion: nil)
|
||||||
legacyEnqueueWebSearchMessages(selectionState, editingState, enqueueChatContextResult: { [weak self] result in
|
legacyEnqueueWebSearchMessages(selectionState, editingState, enqueueChatContextResult: { [weak self] result in
|
||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
strongSelf.enqueueChatContextResult(results, result, hideVia: true)
|
strongSelf.enqueueChatContextResult(results, result, hideVia: true)
|
||||||
|
|||||||
@ -65,7 +65,7 @@ private func preparedTransition(from fromEntries: [WebSearchEntry], to toEntries
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func gridNodeLayoutForContainerLayout(size: CGSize, insets: UIEdgeInsets) -> GridNodeLayoutType {
|
private func gridNodeLayoutForContainerLayout(size: CGSize, insets: UIEdgeInsets) -> GridNodeLayoutType {
|
||||||
let side = floorToScreenPixels((size.width - insets.left - insets.right - 3.0) / 4.0)
|
let side = floorToScreenPixels((size.width - insets.left - insets.right - 2.0) / 3.0)
|
||||||
return .fixed(itemSize: CGSize(width: side, height: side), fillWidth: true, lineSpacing: 1.0, itemSpacing: 1.0)
|
return .fixed(itemSize: CGSize(width: side, height: side), fillWidth: true, lineSpacing: 1.0, itemSpacing: 1.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user