mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-03 21:16:35 +00:00
Update header for profile stories
This commit is contained in:
parent
3ec2d62783
commit
85d6ff7987
@ -60,7 +60,7 @@ public final class StoryContentItem {
|
||||
}
|
||||
|
||||
public let id: AnyHashable
|
||||
public let position: Int
|
||||
public let position: Int?
|
||||
public let component: AnyComponent<StoryContentItem.Environment>
|
||||
public let centerInfoComponent: AnyComponent<Empty>?
|
||||
public let rightInfoComponent: AnyComponent<Empty>?
|
||||
@ -70,7 +70,7 @@ public final class StoryContentItem {
|
||||
|
||||
public init(
|
||||
id: AnyHashable,
|
||||
position: Int,
|
||||
position: Int?,
|
||||
component: AnyComponent<StoryContentItem.Environment>,
|
||||
centerInfoComponent: AnyComponent<Empty>?,
|
||||
rightInfoComponent: AnyComponent<Empty>?,
|
||||
|
||||
@ -2136,12 +2136,10 @@ public final class StoryItemSetContainerComponent: Component {
|
||||
self.ignoreScrolling = false
|
||||
self.updateScrolling(transition: transition)
|
||||
|
||||
if let focusedItem, let visibleItem = self.visibleItems[focusedItem.storyItem.id] {
|
||||
if let focusedItem, let visibleItem = self.visibleItems[focusedItem.storyItem.id], let index = focusedItem.position {
|
||||
let navigationStripSideInset: CGFloat = 8.0
|
||||
let navigationStripTopInset: CGFloat = 8.0
|
||||
|
||||
let index = focusedItem.position
|
||||
|
||||
let _ = self.navigationStrip.update(
|
||||
transition: transition,
|
||||
component: AnyComponent(MediaNavigationStripComponent(
|
||||
|
||||
@ -1122,16 +1122,16 @@ public final class PeerStoryListContentContextImpl: StoryContentContext {
|
||||
additionalPeerData: additionalPeerData,
|
||||
item: StoryContentItem(
|
||||
id: AnyHashable(item.id),
|
||||
position: focusedIndex,
|
||||
position: nil,
|
||||
component: AnyComponent(StoryItemContentComponent(
|
||||
context: context,
|
||||
peer: peer,
|
||||
item: item
|
||||
)),
|
||||
centerInfoComponent: AnyComponent(StoryAuthorInfoComponent(
|
||||
centerInfoComponent: AnyComponent(StoryPositionInfoComponent(
|
||||
context: context,
|
||||
peer: peer,
|
||||
timestamp: item.timestamp
|
||||
position: focusedIndex,
|
||||
totalCount: state.totalCount
|
||||
)),
|
||||
rightInfoComponent: AnyComponent(StoryAvatarInfoComponent(
|
||||
context: context,
|
||||
|
||||
@ -0,0 +1,88 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import Display
|
||||
import ComponentFlow
|
||||
import AccountContext
|
||||
import TelegramCore
|
||||
import TelegramStringFormatting
|
||||
|
||||
final class StoryPositionInfoComponent: Component {
|
||||
let context: AccountContext
|
||||
let position: Int
|
||||
let totalCount: Int
|
||||
|
||||
init(context: AccountContext, position: Int, totalCount: Int) {
|
||||
self.context = context
|
||||
self.position = position
|
||||
self.totalCount = totalCount
|
||||
}
|
||||
|
||||
static func ==(lhs: StoryPositionInfoComponent, rhs: StoryPositionInfoComponent) -> Bool {
|
||||
if lhs.context !== rhs.context {
|
||||
return false
|
||||
}
|
||||
if lhs.position != rhs.position {
|
||||
return false
|
||||
}
|
||||
if lhs.totalCount != rhs.totalCount {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
final class View: UIView {
|
||||
private let title = ComponentView<Empty>()
|
||||
|
||||
private var component: StoryPositionInfoComponent?
|
||||
private weak var state: EmptyComponentState?
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
|
||||
self.isUserInteractionEnabled = false
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func update(component: StoryPositionInfoComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: Transition) -> CGSize {
|
||||
self.component = component
|
||||
self.state = state
|
||||
|
||||
let size = availableSize
|
||||
|
||||
let presentationData = component.context.sharedContext.currentPresentationData.with({ $0 })
|
||||
|
||||
let position = max(0, min(component.position + 1, component.totalCount))
|
||||
let title = presentationData.strings.Items_NOfM("\(position)", "\(component.totalCount)").string
|
||||
let titleSize = self.title.update(
|
||||
transition: .immediate,
|
||||
component: AnyComponent(Text(text: title, font: Font.with(size: 17.0, weight: .semibold, traits: .monospacedNumbers), color: .white)),
|
||||
environment: {},
|
||||
containerSize: availableSize
|
||||
)
|
||||
|
||||
let contentHeight: CGFloat = titleSize.height
|
||||
let titleFrame = CGRect(origin: CGPoint(x: floor((availableSize.width - titleSize.width) * 0.5), y: floor((availableSize.height - contentHeight) * 0.5)), size: titleSize)
|
||||
|
||||
if let titleView = self.title.view {
|
||||
if titleView.superview == nil {
|
||||
titleView.isUserInteractionEnabled = false
|
||||
self.addSubview(titleView)
|
||||
}
|
||||
transition.setFrame(view: titleView, frame: titleFrame)
|
||||
}
|
||||
|
||||
return size
|
||||
}
|
||||
}
|
||||
|
||||
func makeView() -> View {
|
||||
return View(frame: CGRect())
|
||||
}
|
||||
|
||||
func update(view: View, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: Transition) -> CGSize {
|
||||
return view.update(component: self, availableSize: availableSize, state: state, environment: environment, transition: transition)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user