mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Profile preview
This commit is contained in:
@@ -11,18 +11,24 @@ import SliderComponent
|
||||
public final class ListItemSliderSelectorComponent: Component {
|
||||
public let theme: PresentationTheme
|
||||
public let values: [String]
|
||||
public let markPositions: Bool
|
||||
public let selectedIndex: Int
|
||||
public let title: String?
|
||||
public let selectedIndexUpdated: (Int) -> Void
|
||||
|
||||
public init(
|
||||
theme: PresentationTheme,
|
||||
values: [String],
|
||||
markPositions: Bool,
|
||||
selectedIndex: Int,
|
||||
title: String?,
|
||||
selectedIndexUpdated: @escaping (Int) -> Void
|
||||
) {
|
||||
self.theme = theme
|
||||
self.values = values
|
||||
self.markPositions = markPositions
|
||||
self.selectedIndex = selectedIndex
|
||||
self.title = title
|
||||
self.selectedIndexUpdated = selectedIndexUpdated
|
||||
}
|
||||
|
||||
@@ -33,14 +39,21 @@ public final class ListItemSliderSelectorComponent: Component {
|
||||
if lhs.values != rhs.values {
|
||||
return false
|
||||
}
|
||||
if lhs.markPositions != rhs.markPositions {
|
||||
return false
|
||||
}
|
||||
if lhs.selectedIndex != rhs.selectedIndex {
|
||||
return false
|
||||
}
|
||||
if lhs.title != rhs.title {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
public final class View: UIView, ListSectionComponent.ChildView {
|
||||
private var titles: [ComponentView<Empty>] = []
|
||||
private var titles: [Int: ComponentView<Empty>] = [:]
|
||||
private var mainTitle: ComponentView<Empty>?
|
||||
private var slider = ComponentView<Empty>()
|
||||
|
||||
private var component: ListItemSliderSelectorComponent?
|
||||
@@ -67,15 +80,24 @@ public final class ListItemSliderSelectorComponent: Component {
|
||||
|
||||
let titleAreaWidth: CGFloat = availableSize.width - titleSideInset * 2.0
|
||||
|
||||
var validIds: [Int] = []
|
||||
for i in 0 ..< component.values.count {
|
||||
if component.title != nil {
|
||||
if i != 0 && i != component.values.count - 1 {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
validIds.append(i)
|
||||
|
||||
var titleTransition = transition
|
||||
let title: ComponentView<Empty>
|
||||
if self.titles.count > i {
|
||||
title = self.titles[i]
|
||||
if let current = self.titles[i] {
|
||||
title = current
|
||||
} else {
|
||||
titleTransition = titleTransition.withAnimation(.none)
|
||||
title = ComponentView()
|
||||
self.titles.append(title)
|
||||
self.titles[i] = title
|
||||
}
|
||||
let titleSize = title.update(
|
||||
transition: .immediate,
|
||||
@@ -103,11 +125,48 @@ public final class ListItemSliderSelectorComponent: Component {
|
||||
titleTransition.setPosition(view: titleView, position: titleFrame.center)
|
||||
}
|
||||
}
|
||||
if self.titles.count > component.values.count {
|
||||
for i in component.values.count ..< self.titles.count {
|
||||
self.titles[i].view?.removeFromSuperview()
|
||||
var removeIds: [Int] = []
|
||||
for (id, title) in self.titles {
|
||||
if !validIds.contains(id) {
|
||||
removeIds.append(id)
|
||||
title.view?.removeFromSuperview()
|
||||
}
|
||||
}
|
||||
for id in removeIds {
|
||||
self.titles.removeValue(forKey: id)
|
||||
}
|
||||
|
||||
if let title = component.title {
|
||||
let mainTitle: ComponentView<Empty>
|
||||
var mainTitleTransition = transition
|
||||
if let current = self.mainTitle {
|
||||
mainTitle = current
|
||||
} else {
|
||||
mainTitleTransition = mainTitleTransition.withAnimation(.none)
|
||||
mainTitle = ComponentView()
|
||||
self.mainTitle = mainTitle
|
||||
}
|
||||
let mainTitleSize = mainTitle.update(
|
||||
transition: .immediate,
|
||||
component: AnyComponent(MultilineTextComponent(
|
||||
text: .plain(NSAttributedString(string: title, font: Font.regular(16.0), textColor: component.theme.list.itemPrimaryTextColor))
|
||||
)),
|
||||
environment: {},
|
||||
containerSize: CGSize(width: 100.0, height: 100.0)
|
||||
)
|
||||
let mainTitleFrame = CGRect(origin: CGPoint(x: floor((availableSize.width - mainTitleSize.width) * 0.5), y: 10.0), size: mainTitleSize)
|
||||
if let mainTitleView = mainTitle.view {
|
||||
if mainTitleView.superview == nil {
|
||||
self.addSubview(mainTitleView)
|
||||
}
|
||||
mainTitleView.bounds = CGRect(origin: CGPoint(), size: mainTitleFrame.size)
|
||||
mainTitleTransition.setPosition(view: mainTitleView, position: mainTitleFrame.center)
|
||||
}
|
||||
} else {
|
||||
if let mainTitle = self.mainTitle {
|
||||
self.mainTitle = nil
|
||||
mainTitle.view?.removeFromSuperview()
|
||||
}
|
||||
self.titles.removeLast(self.titles.count - component.values.count)
|
||||
}
|
||||
|
||||
let sliderSize = self.slider.update(
|
||||
@@ -115,6 +174,7 @@ public final class ListItemSliderSelectorComponent: Component {
|
||||
component: AnyComponent(SliderComponent(
|
||||
valueCount: component.values.count,
|
||||
value: component.selectedIndex,
|
||||
markPositions: component.markPositions,
|
||||
trackBackgroundColor: component.theme.list.controlSecondaryColor,
|
||||
trackForegroundColor: component.theme.list.itemAccentColor,
|
||||
valueUpdated: { [weak self] value in
|
||||
|
||||
Reference in New Issue
Block a user