From b5fac5edf9966222c2d88876538c4693bfda2dbb Mon Sep 17 00:00:00 2001 From: Ali <> Date: Tue, 25 Apr 2023 18:41:58 +0400 Subject: [PATCH] [WIP] Stories --- .../MediaNavigationStripComponent.swift | 20 +++++++++++++++---- .../Sources/StoryContainerScreen.swift | 11 +++------- .../Sources/StoryContent.swift | 5 +++++ .../StoryMessageContentComponent.swift | 11 +++++++--- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/MediaNavigationStripComponent.swift b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/MediaNavigationStripComponent.swift index 353d3cb700..21ab7c5442 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/MediaNavigationStripComponent.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/MediaNavigationStripComponent.swift @@ -65,6 +65,8 @@ final class MediaNavigationStripComponent: Component { final class View: UIView { private var visibleItems: [Int: ItemLayer] = [:] + private var component: MediaNavigationStripComponent? + override init(frame: CGRect) { super.init(frame: frame) @@ -76,7 +78,21 @@ final class MediaNavigationStripComponent: Component { fatalError("init(coder:) has not been implemented") } + func updateCurrentItemProgress(value: CGFloat, transition: Transition) { + guard let component = self.component else { + return + } + guard let itemLayer = self.visibleItems[component.index] else { + return + } + + let itemFrame = itemLayer.bounds + transition.setFrame(layer: itemLayer.foregroundLayer, frame: CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: CGSize(width: value * itemFrame.width, height: itemFrame.height))) + } + func update(component: MediaNavigationStripComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment, transition: Transition) -> CGSize { + self.component = component + let spacing: CGFloat = 3.0 let itemHeight: CGFloat = 2.0 let minItemWidth: CGFloat = 10.0 @@ -103,10 +119,6 @@ final class MediaNavigationStripComponent: Component { globalOffset = 0.0 } - //itemWidth * itemCount + (itemCount - 1) * spacing = width - //itemWidth * itemCount + itemCount * spacing - spacing = width - //itemCount * (itemWidth + spacing) = width + spacing - //itemCount = (width + spacing) / (itemWidth + spacing) let potentiallyVisibleCount = Int(ceil((availableSize.width + spacing) / (itemWidth + spacing))) for i in (component.index - potentiallyVisibleCount) ... (component.index + potentiallyVisibleCount) { if i < 0 { diff --git a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContainerScreen.swift b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContainerScreen.swift index 1d994d0eb5..bdc677f629 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContainerScreen.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContainerScreen.swift @@ -291,14 +291,9 @@ private final class StoryContainerScreenComponent: Component { } visibleItem.currentProgress = progress - let _ = self.navigationStrip.updateEnvironment( - transition: .immediate, - environment: { - MediaNavigationStripComponent.EnvironmentType( - currentProgress: progress - ) - } - ) + if let navigationStripView = self.navigationStrip.view as? MediaNavigationStripComponent.View { + navigationStripView.updateCurrentItemProgress(value: progress, transition: .immediate) + } if progress >= 1.0 && !visibleItem.requestedNext { visibleItem.requestedNext = true diff --git a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContent.swift b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContent.swift index 90670cdacc..652110f6d1 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContent.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryContent.swift @@ -11,6 +11,11 @@ public final class StoryContentItem { } } + open class View: UIView { + func setIsProgressPaused(_ isProgressPaused: Bool) { + } + } + public final class Environment: Equatable { public let externalState: ExternalState public let presentationProgressUpdated: (Double) -> Void diff --git a/submodules/TelegramUI/Components/Stories/StoryContentComponent/Sources/StoryMessageContentComponent.swift b/submodules/TelegramUI/Components/Stories/StoryContentComponent/Sources/StoryMessageContentComponent.swift index 8538cce439..76bb610ebf 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContentComponent/Sources/StoryMessageContentComponent.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContentComponent/Sources/StoryMessageContentComponent.swift @@ -82,7 +82,7 @@ final class StoryMessageContentComponent: Component { return fetchSignal ?? .complete() } - final class View: UIView { + final class View: StoryContentItem.View { private let imageNode: TransformImageNode private var videoNode: UniversalVideoNode? @@ -140,6 +140,10 @@ final class StoryMessageContentComponent: Component { ), priority: .gallery ) + + self.videoNode = videoNode + self.addSubnode(videoNode) + videoNode.ownsContentNodeUpdated = { [weak self] value in guard let self else { return @@ -150,8 +154,6 @@ final class StoryMessageContentComponent: Component { } } videoNode.canAttachContent = true - self.videoNode = videoNode - self.addSubnode(videoNode) if update { self.state?.updated(transition: .immediate) } @@ -159,6 +161,9 @@ final class StoryMessageContentComponent: Component { } } + func setIsProgressPaused(_ isProgressPaused: Bool) { + } + func update(component: StoryMessageContentComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment, transition: Transition) -> CGSize { self.component = component self.state = state