diff --git a/submodules/AttachmentUI/Sources/AttachmentController.swift b/submodules/AttachmentUI/Sources/AttachmentController.swift index 4c8837c227..8564c2c7f0 100644 --- a/submodules/AttachmentUI/Sources/AttachmentController.swift +++ b/submodules/AttachmentUI/Sources/AttachmentController.swift @@ -392,7 +392,10 @@ 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?(strongSelf.currentType) == true { - let delta = layout.size.height - controller.minimizedTopEdgeOffset + var delta = layout.size.height + if let minimizedTopEdgeOffset = controller.minimizedTopEdgeOffset { + delta -= minimizedTopEdgeOffset + } let damping: CGFloat = 180.0 let initialVelocity: CGFloat = delta > 0.0 ? velocity / delta : 0.0 diff --git a/submodules/BrowserUI/BUILD b/submodules/BrowserUI/BUILD index 2112ef8200..9bc316a4a8 100644 --- a/submodules/BrowserUI/BUILD +++ b/submodules/BrowserUI/BUILD @@ -26,6 +26,7 @@ swift_library( "//submodules/Components/MultilineTextComponent:MultilineTextComponent", "//submodules/Components/BundleIconComponent:BundleIconComponent", "//submodules/Components/BlurredBackgroundComponent:BlurredBackgroundComponent", + "//submodules/TelegramUI/Components/MinimizedContainer", ], visibility = [ "//visibility:public", diff --git a/submodules/BrowserUI/Sources/BrowserScreen.swift b/submodules/BrowserUI/Sources/BrowserScreen.swift index 71dbde446a..2c0c2250eb 100644 --- a/submodules/BrowserUI/Sources/BrowserScreen.swift +++ b/submodules/BrowserUI/Sources/BrowserScreen.swift @@ -13,6 +13,7 @@ import BundleIconComponent import TelegramUIPreferences import OpenInExternalAppUI import MultilineTextComponent +import MinimizedContainer private let settingsTag = GenericComponentViewTag() @@ -291,6 +292,7 @@ public class BrowserScreen: ViewController { guard let strongSelf = self else { return } + strongSelf.controller?.title = state.title strongSelf.contentState = state strongSelf.requestLayout(transition: .immediate) }).strict() @@ -318,7 +320,7 @@ public class BrowserScreen: ViewController { } self.controller?.present(shareController, in: .window(.root)) case .minimize: - break + self.minimize() case .openIn: self.context.sharedContext.applicationBindings.openUrl(url) case .openSettings: @@ -441,6 +443,23 @@ public class BrowserScreen: ViewController { self.requestLayout(transition: animated ? .easeInOut(duration: 0.2) : .immediate) } + func minimize() { + guard let controller = self.controller, let navigationController = controller.navigationController as? NavigationController else { + return + } + navigationController.minimizeViewController(controller, damping: nil, setupContainer: { [weak self] current in + let minimizedContainer: MinimizedContainerImpl? + if let current = current as? MinimizedContainerImpl { + minimizedContainer = current + } else if let context = self?.controller?.context { + minimizedContainer = MinimizedContainerImpl(sharedContext: context.sharedContext) + } else { + minimizedContainer = nil + } + return minimizedContainer + }, animated: true) + } + func openSettings() { guard let referenceView = self.componentHost.findTaggedView(tag: settingsTag) as? ReferenceButtonComponent.View else { return @@ -535,7 +554,8 @@ public class BrowserScreen: ViewController { self.context.sharedContext.applicationBindings.openUrl(openInUrl) } action(.default) - }))] + })) + ] let contextController = ContextController(presentationData: self.presentationData, source: source, items: .single(ContextController.Items(content: .list(items)))) self.controller?.present(contextController, in: .window(.root)) diff --git a/submodules/BrowserUI/Sources/BrowserToolbarComponent.swift b/submodules/BrowserUI/Sources/BrowserToolbarComponent.swift index afe73f5737..ad57dc233e 100644 --- a/submodules/BrowserUI/Sources/BrowserToolbarComponent.swift +++ b/submodules/BrowserUI/Sources/BrowserToolbarComponent.swift @@ -104,7 +104,9 @@ final class BrowserToolbarComponent: CombinedComponent { transition.animatePosition(view: view, from: CGPoint(x: 0.0, y: size.height), to: .zero, additive: true) })) .disappear(ComponentTransition.Disappear({ view, transition, completion in - transition.animatePosition(view: view, from: .zero, to: CGPoint(x: 0.0, y: size.height), additive: true, completion: { _ in + let from = view.center + view.center = from.offsetBy(dx: 0.0, dy: size.height) + transition.animatePosition(view: view, from: from, to: view.center, completion: { _ in completion() }) })) @@ -224,12 +226,12 @@ final class NavigationToolbarContentComponent: CombinedComponent { component: Button( content: AnyComponent( BundleIconComponent( - name: "Chat/Context Menu/Browser", + name: "Instant View/Minimize", tintColor: context.component.textColor ) ), action: { - performAction.invoke(.openIn) + performAction.invoke(.minimize) } ).minSize(buttonSize), availableSize: buttonSize, diff --git a/submodules/DebugSettingsUI/Sources/DebugController.swift b/submodules/DebugSettingsUI/Sources/DebugController.swift index 0db2b467cb..4caad38b0e 100644 --- a/submodules/DebugSettingsUI/Sources/DebugController.swift +++ b/submodules/DebugSettingsUI/Sources/DebugController.swift @@ -1453,9 +1453,13 @@ private func debugControllerEntries(sharedContext: SharedAccountContext, present entries.append(.experimentalCompatibility(experimentalSettings.experimentalCompatibility)) entries.append(.enableDebugDataDisplay(experimentalSettings.enableDebugDataDisplay)) entries.append(.acceleratedStickers(experimentalSettings.acceleratedStickers)) + #if DEBUG + entries.append(.browserExperiment(experimentalSettings.browserExperiment)) + #else if sharedContext.applicationBindings.appBuildType == .internal { entries.append(.browserExperiment(experimentalSettings.browserExperiment)) } + #endif entries.append(.localTranscription(experimentalSettings.localTranscription)) if case .internal = sharedContext.applicationBindings.appBuildType { entries.append(.enableReactionOverrides(experimentalSettings.enableReactionOverrides)) diff --git a/submodules/Display/Source/Navigation/MinimizedContainer.swift b/submodules/Display/Source/Navigation/MinimizedContainer.swift index 1167fd4837..8460e77ce3 100644 --- a/submodules/Display/Source/Navigation/MinimizedContainer.swift +++ b/submodules/Display/Source/Navigation/MinimizedContainer.swift @@ -4,11 +4,13 @@ import AsyncDisplayKit public protocol MinimizedContainer: ASDisplayNode { var navigationController: NavigationController? { get set } var controllers: [ViewController] { get } + var isExpanded: Bool { get } var willMaximize: (() -> Void)? { get set } func addController(_ viewController: ViewController, transition: ContainedViewLayoutTransition) func maximizeController(_ viewController: ViewController, animated: Bool, completion: @escaping (Bool) -> Void) + func collapse() func dismissAll(completion: @escaping () -> Void) func updateLayout(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) diff --git a/submodules/Display/Source/Navigation/NavigationController.swift b/submodules/Display/Source/Navigation/NavigationController.swift index 0b75f59ac3..8423ad324b 100644 --- a/submodules/Display/Source/Navigation/NavigationController.swift +++ b/submodules/Display/Source/Navigation/NavigationController.swift @@ -1335,7 +1335,9 @@ open class NavigationController: UINavigationController, ContainableController, if let _ = self.inCallStatusBar { self.inCallNavigate?() } else if let rootContainer = self.rootContainer { - if let modalContainer = self.modalContainers.last { + if let minimizedContainer = self.minimizedContainer, minimizedContainer.isExpanded { + minimizedContainer.collapse() + } else if let modalContainer = self.modalContainers.last { modalContainer.container.controllers.last?.scrollToTop?() } else { switch rootContainer { diff --git a/submodules/Display/Source/ViewController.swift b/submodules/Display/Source/ViewController.swift index 6e97f25dca..b2baf23eb6 100644 --- a/submodules/Display/Source/ViewController.swift +++ b/submodules/Display/Source/ViewController.swift @@ -230,7 +230,7 @@ public protocol CustomViewControllerNavigationDataSummary: AnyObject { private var navigationBarOrigin: CGFloat = 0.0 - public var minimizedTopEdgeOffset: CGFloat = 0.0 + public var minimizedTopEdgeOffset: CGFloat? public var minimizedBounds: CGRect? open var isMinimized: Bool = false diff --git a/submodules/PremiumUI/Sources/IncreaseLimitHeaderItem.swift b/submodules/PremiumUI/Sources/IncreaseLimitHeaderItem.swift index ff7bcf55f4..f203973b74 100644 --- a/submodules/PremiumUI/Sources/IncreaseLimitHeaderItem.swift +++ b/submodules/PremiumUI/Sources/IncreaseLimitHeaderItem.swift @@ -196,7 +196,7 @@ class IncreaseLimitHeaderItemNode: ListViewItemNode { badgeIconName: badgeIconName, badgeText: "\(item.count)", badgePosition: CGFloat(item.count) / CGFloat(item.premiumCount), - badgeGraphPosition: CGFloat(item.count) / CGFloat(item.premiumCount), + badgeGraphPosition: CGFloat(item.limit) / CGFloat(item.premiumCount), isPremiumDisabled: item.isPremiumDisabled )) let containerSize = CGSize(width: layout.size.width - params.leftInset - params.rightInset, height: 200.0) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/InactiveChannels.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/InactiveChannels.swift index 9837949190..3a8881c801 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/InactiveChannels.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/InactiveChannels.swift @@ -41,7 +41,7 @@ func _internal_inactiveChannelList(network: Network) -> Signal<[InactiveChannel] } var inactive: [InactiveChannel] = [] for (i, channel) in channels.enumerated() { - inactive.append(InactiveChannel(peer: channel, lastActivityDate: dates[i], participantsCount: participantsCounts[channel.id])) + inactive.append(InactiveChannel(peer: channel, lastActivityDate: i < dates.count ? dates[i] : 0, participantsCount: participantsCounts[channel.id])) } return inactive } diff --git a/submodules/TelegramUI/Components/MinimizedContainer/Sources/MinimizedContainer.swift b/submodules/TelegramUI/Components/MinimizedContainer/Sources/MinimizedContainer.swift index 90e32c607c..7c130707a9 100644 --- a/submodules/TelegramUI/Components/MinimizedContainer/Sources/MinimizedContainer.swift +++ b/submodules/TelegramUI/Components/MinimizedContainer/Sources/MinimizedContainer.swift @@ -212,7 +212,9 @@ public class MinimizedContainerImpl: ASDisplayNode, MinimizedContainer, ASScroll topInset += 10.0 } self.containerNode.frame = CGRect(origin: .zero, size: size) - self.containerNode.subnodeTransform = CATransform3DMakeTranslation(0.0, -topInset, 0.0) + if let _ = self.item.controller.minimizedTopEdgeOffset { + self.containerNode.subnodeTransform = CATransform3DMakeTranslation(0.0, -topInset, 0.0) + } self.snapshotContainerView.frame = CGRect(origin: .zero, size: size) @@ -234,11 +236,15 @@ public class MinimizedContainerImpl: ASDisplayNode, MinimizedContainer, ASScroll var requiresBlur = false var blurFrame = snapshotFrame if snapshotView.frame.width * 1.1 < size.width { - snapshotFrame = snapshotFrame.offsetBy(dx: 0.0, dy: -66.0) + if let _ = self.item.controller.minimizedTopEdgeOffset { + snapshotFrame = snapshotFrame.offsetBy(dx: 0.0, dy: -66.0) + } blurFrame = CGRect(origin: CGPoint(x: 0.0, y: snapshotFrame.minY), size: CGSize(width: size.width, height: snapshotFrame.height)) requiresBlur = true } else if snapshotView.frame.width > size.width * 1.5 { - snapshotFrame = snapshotFrame.offsetBy(dx: 0.0, dy: 66.0) + if let _ = self.item.controller.minimizedTopEdgeOffset { + snapshotFrame = snapshotFrame.offsetBy(dx: 0.0, dy: 66.0) + } blurFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - snapshotView.frame.width) / 2.0), y: snapshotFrame.minY), size: CGSize(width: snapshotFrame.width, height: size.height)) requiresBlur = true } @@ -282,7 +288,7 @@ public class MinimizedContainerImpl: ASDisplayNode, MinimizedContainer, ASScroll private var presentationData: PresentationData private var presentationDataDisposable: Disposable? - var isExpanded: Bool = false + public private(set) var isExpanded: Bool = false public var willMaximize: (() -> Void)? private let bottomEdgeView: UIImageView @@ -552,6 +558,12 @@ public class MinimizedContainerImpl: ASDisplayNode, MinimizedContainer, ASScroll self.requestUpdate(transition: .animated(duration: 0.4, curve: .spring)) } } + + public func collapse() { + self.isExpanded = false + self.currentTransition = .collapse + self.requestUpdate(transition: .animated(duration: 0.4, curve: .spring)) + } public func scrollViewDidScroll(_ scrollView: UIScrollView) { guard self.isExpanded, let layout = self.validLayout else { @@ -824,7 +836,10 @@ public class MinimizedContainerImpl: ASDisplayNode, MinimizedContainer, ASScroll itemNode.animateIn() - var initialOffset = insets.top + itemNode.item.controller.minimizedTopEdgeOffset + var initialOffset = insets.top + if let minimizedTopEdgeOffset = itemNode.item.controller.minimizedTopEdgeOffset { + initialOffset += minimizedTopEdgeOffset + } if layout.size.width < layout.size.height { initialOffset += 10.0 } diff --git a/submodules/TelegramUI/Components/PeerManagement/OldChannelsController/Sources/OldChannelsController.swift b/submodules/TelegramUI/Components/PeerManagement/OldChannelsController/Sources/OldChannelsController.swift index 1dc627c391..96e46e2053 100644 --- a/submodules/TelegramUI/Components/PeerManagement/OldChannelsController/Sources/OldChannelsController.swift +++ b/submodules/TelegramUI/Components/PeerManagement/OldChannelsController/Sources/OldChannelsController.swift @@ -187,7 +187,7 @@ private struct OldChannelsState: Equatable { private func oldChannelsEntries(presentationData: PresentationData, state: OldChannelsState, isPremium: Bool, isPremiumDisabled: Bool, limit: Int32, premiumLimit: Int32, peers: [InactiveChannel]?, intent: OldChannelsControllerIntent) -> [OldChannelsEntry] { var entries: [OldChannelsEntry] = [] - let count = max(limit, Int32(peers?.count ?? 0)) + let count = max(isPremium ? premiumLimit : limit, Int32(peers?.count ?? 0)) var text: String? if count >= premiumLimit { switch intent { @@ -359,7 +359,7 @@ public func oldChannelsController(context: AccountContext, updatedPresentationDa } let footerItem: IncreaseLimitFooterItem? - if (state.isSearching || premiumConfiguration.isPremiumDisabled) && state.selectedPeers.count == 0 { + if (state.isSearching || premiumConfiguration.isPremiumDisabled || isPremium) && state.selectedPeers.count == 0 { footerItem = nil } else { footerItem = IncreaseLimitFooterItem(theme: presentationData.theme, title: buttonText, colorful: colorful, action: {