diff --git a/submodules/AttachmentUI/Sources/AttachmentController.swift b/submodules/AttachmentUI/Sources/AttachmentController.swift index 07271caf62..f4d5615c43 100644 --- a/submodules/AttachmentUI/Sources/AttachmentController.swift +++ b/submodules/AttachmentUI/Sources/AttachmentController.swift @@ -28,6 +28,29 @@ public enum AttachmentButtonType: Equatable { case gift case standalone + public var key: String { + switch self { + case .gallery: + return "gallery" + case .file: + return "file" + case .location: + return "location" + case .quickReply: + return "quickReply" + case .contact: + return "contact" + case .poll: + return "poll" + case let .app(bot): + return "app_\(bot.shortName)" + case .gift: + return "gift" + case .standalone: + return "standalone" + } + } + public static func ==(lhs: AttachmentButtonType, rhs: AttachmentButtonType) -> Bool { switch lhs { case .gallery: @@ -207,10 +230,10 @@ public class AttachmentController: ViewController { private let updatedPresentationData: (initial: PresentationData, signal: Signal)? private let chatLocation: ChatLocation? private let isScheduledMessages: Bool - private let buttons: [AttachmentButtonType] + private var buttons: [AttachmentButtonType] private let initialButton: AttachmentButtonType private let fromMenu: Bool - private let hasTextInput: Bool + private var hasTextInput: Bool private let makeEntityInputView: () -> AttachmentTextInputPanelInputView? public var animateAppearance: Bool = false @@ -239,7 +262,7 @@ public class AttachmentController: ViewController { private let makeEntityInputView: () -> AttachmentTextInputPanelInputView? let panel: AttachmentPanel - private var currentType: AttachmentButtonType? + fileprivate var currentType: AttachmentButtonType? private var currentControllers: [AttachmentContainable] = [] private var validLayout: ContainerViewLayout? @@ -368,7 +391,7 @@ public class AttachmentController: ViewController { self.container.interactivelyDismissed = { [weak self] velocity in if let strongSelf = self, let layout = strongSelf.validLayout { - if let controller = strongSelf.controller, controller.shouldMinimizeOnSwipe?() == true, let navigationController = controller.navigationController as? NavigationController { + if let controller = strongSelf.controller, controller.shouldMinimizeOnSwipe?(strongSelf.currentType) == true, let navigationController = controller.navigationController as? NavigationController { let delta = layout.size.height - controller.minimizedTopEdgeOffset let damping: CGFloat = 180 @@ -390,7 +413,6 @@ public class AttachmentController: ViewController { strongSelf.isMinimizing = true strongSelf.container.update(isExpanded: true, force: true, transition: .immediate) -// strongSelf.container.update(isExpanded: true, force: true, transition: .animated(duration: 0.4, curve: .customSpring(damping: 180.0, initialVelocity: initialVelocity))) strongSelf.isMinimizing = false Queue.mainQueue().after(0.45, { @@ -1025,7 +1047,7 @@ public class AttachmentController: ViewController { public var getSourceRect: (() -> CGRect?)? - public var shouldMinimizeOnSwipe: (() -> Bool)? + public var shouldMinimizeOnSwipe: ((AttachmentButtonType?) -> Bool)? public init(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, chatLocation: ChatLocation?, isScheduledMessages: Bool = false, buttons: [AttachmentButtonType], initialButton: AttachmentButtonType = .gallery, fromMenu: Bool = false, hasTextInput: Bool = true, makeEntityInputView: @escaping () -> AttachmentTextInputPanelInputView? = { return nil}) { self.context = context @@ -1061,31 +1083,18 @@ public class AttachmentController: ViewController { return self.buttons.contains(.standalone) } -// private var snapshotView: UIView? -// public override var isMinimized: Bool { -// didSet { -// guard self.isMinimized != oldValue else { -// return -// } -// if self.isMinimized { -// if self.snapshotView == nil, let lastController = self.node.container.container.controllers.last, let snapshotView = lastController.view.snapshotView(afterScreenUpdates: false) { -// snapshotView.isUserInteractionEnabled = false -// self.snapshotView = snapshotView -// lastController.view.addSubview(snapshotView) -// } -// } else { -// if let snapshotView = self.snapshotView { -// self.snapshotView = nil -// Queue.mainQueue().after(0.15) { -// snapshotView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.25, removeOnCompletion: false, completion: { _ in -// snapshotView.removeFromSuperview() -// }) -// } -// } -// } -// } -// } - + public func convertToStandalone() { + guard self.buttons != [.standalone] else { + return + } + if case let .app(bot) = self.node.currentType { + self.title = bot.peer.compactDisplayTitle + } + self.buttons = [.standalone] + self.hasTextInput = false + self.requestLayout(transition: .immediate) + } + public func updateSelectionCount(_ count: Int) { self.node.updateSelectionCount(count, animated: false) } diff --git a/submodules/AttachmentUI/Sources/AttachmentPanel.swift b/submodules/AttachmentUI/Sources/AttachmentPanel.swift index 920159407f..6d9605d02d 100644 --- a/submodules/AttachmentUI/Sources/AttachmentPanel.swift +++ b/submodules/AttachmentUI/Sources/AttachmentPanel.swift @@ -701,7 +701,7 @@ final class AttachmentPanel: ASDisplayNode, ASScrollViewDelegate { private let backgroundNode: NavigationBackgroundNode private let scrollNode: ASScrollNode private let separatorNode: ASDisplayNode - private var buttonViews: [Int: ComponentHostView] = [:] + private var buttonViews: [AnyHashable: ComponentHostView] = [:] private var textInputPanelNode: AttachmentTextInputPanelNode? private var progressNode: LoadingProgressNode? @@ -1169,7 +1169,6 @@ final class AttachmentPanel: ASDisplayNode, ASScrollViewDelegate { } let visibleRect = self.scrollNode.bounds.insetBy(dx: -180.0, dy: 0.0) - var validButtons = Set() var distanceBetweenNodes = layout.size.width / CGFloat(self.buttons.count) let internalWidth = distanceBetweenNodes * CGFloat(self.buttons.count - 1) @@ -1182,26 +1181,29 @@ final class AttachmentPanel: ASDisplayNode, ASScrollViewDelegate { leftNodeOriginX = layout.safeInsets.left + sideInset + buttonWidth / 2.0 } + var validIds = Set() + for i in 0 ..< self.buttons.count { let originX = floor(leftNodeOriginX + CGFloat(i) * distanceBetweenNodes - buttonWidth / 2.0) let buttonFrame = CGRect(origin: CGPoint(x: originX, y: 0.0), size: CGSize(width: buttonWidth, height: buttonSize.height)) if !visibleRect.intersects(buttonFrame) { continue } - validButtons.insert(i) + + let type = self.buttons[i] + let _ = validIds.insert(type.key) var buttonTransition = transition let buttonView: ComponentHostView - if let current = self.buttonViews[i] { + if let current = self.buttonViews[type.key] { buttonView = current } else { buttonTransition = .immediate buttonView = ComponentHostView() - self.buttonViews[i] = buttonView + self.buttonViews[type.key] = buttonView self.scrollNode.view.addSubview(buttonView) } - let type = self.buttons[i] if case let .app(bot) = type { for (name, file) in bot.icons { if [.default, .iOSAnimated, .iOSSettingsStatic, .placeholder].contains(name) { @@ -1285,6 +1287,16 @@ final class AttachmentPanel: ASDisplayNode, ASScrollViewDelegate { buttonView.accessibilityLabel = accessibilityTitle buttonView.accessibilityTraits = [.button] } + var removeIds: [AnyHashable] = [] + for (id, itemView) in self.buttonViews { + if !validIds.contains(id) { + removeIds.append(id) + itemView.removeFromSuperview() + } + } + for id in removeIds { + self.buttonViews.removeValue(forKey: id) + } } private func updateScrollLayoutIfNeeded(force: Bool, transition: ContainedViewLayoutTransition) -> Bool { diff --git a/submodules/TelegramUI/Sources/ChatControllerNode.swift b/submodules/TelegramUI/Sources/ChatControllerNode.swift index 1288fac634..0ac342390c 100644 --- a/submodules/TelegramUI/Sources/ChatControllerNode.swift +++ b/submodules/TelegramUI/Sources/ChatControllerNode.swift @@ -1714,13 +1714,19 @@ class ChatControllerNode: ASDisplayNode, ASScrollViewDelegate { transition.updateFrame(node: backgroundEffectNode, frame: CGRect(origin: CGPoint(), size: layout.size)) } - let wallpaperBounds = CGRect(x: 0.0, y: 0.0, width: layout.size.width - wrappingInsets.left - wrappingInsets.right, height: layout.size.height) + var wallpaperBounds = CGRect(x: 0.0, y: 0.0, width: layout.size.width - wrappingInsets.left - wrappingInsets.right, height: layout.size.height) transition.updateFrame(node: self.backgroundNode, frame: wallpaperBounds) var displayMode: WallpaperDisplayMode = .aspectFill if case .regular = layout.metrics.widthClass, layout.size.height == layout.deviceMetrics.screenSize.width { displayMode = .aspectFit + } else if case .compact = layout.metrics.widthClass { + if layout.size.width < layout.size.height && layout.size.height < layout.deviceMetrics.screenSize.height { + wallpaperBounds.size.height = layout.deviceMetrics.screenSize.height + } else if layout.size.width > layout.size.height && layout.size.height < layout.deviceMetrics.screenSize.width { + wallpaperBounds.size.height = layout.deviceMetrics.screenSize.width + } } self.backgroundNode.updateLayout(size: wallpaperBounds.size, displayMode: displayMode, transition: transition) diff --git a/submodules/TelegramUI/Sources/ChatControllerOpenAttachmentMenu.swift b/submodules/TelegramUI/Sources/ChatControllerOpenAttachmentMenu.swift index 4d69df2e70..2dd53831fb 100644 --- a/submodules/TelegramUI/Sources/ChatControllerOpenAttachmentMenu.swift +++ b/submodules/TelegramUI/Sources/ChatControllerOpenAttachmentMenu.swift @@ -277,6 +277,13 @@ extension ChatControllerImpl { } return EntityInputView(context: strongSelf.context, isDark: false, areCustomEmojiEnabled: strongSelf.presentationInterfaceState.customEmojiAvailable) }) + attachmentController.shouldMinimizeOnSwipe = { [weak attachmentController] button in + if case .app = button { + attachmentController?.convertToStandalone() + return true + } + return false + } attachmentController.didDismiss = { [weak self] in self?.attachmentController = nil self?.canReadHistory.set(true) diff --git a/submodules/WebUI/Sources/WebAppController.swift b/submodules/WebUI/Sources/WebAppController.swift index d6b2115d71..31cbfc89ed 100644 --- a/submodules/WebUI/Sources/WebAppController.swift +++ b/submodules/WebUI/Sources/WebAppController.swift @@ -2182,7 +2182,7 @@ public func standaloneWebAppController( let controller = AttachmentController(context: context, updatedPresentationData: updatedPresentationData, chatLocation: .peer(id: params.peerId), buttons: [.standalone], initialButton: .standalone, fromMenu: params.source == .menu, hasTextInput: false, makeEntityInputView: { return nil }) - controller.getInputContainerNode = getInputContainerNode +// controller.getInputContainerNode = getInputContainerNode controller.requestController = { _, present in let webAppController = WebAppController(context: context, updatedPresentationData: updatedPresentationData, params: params, replyToMessageId: nil, threadId: threadId) webAppController.openUrl = openUrl @@ -2195,12 +2195,8 @@ public func standaloneWebAppController( controller.didDismiss = didDismiss controller.getSourceRect = getSourceRect controller.title = params.botName - controller.shouldMinimizeOnSwipe = { - if params.source != .menu { - return true - } else { - return false - } + controller.shouldMinimizeOnSwipe = { _ in + return true } return controller }