mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 14:45:21 +00:00
Temp
This commit is contained in:
@@ -7,46 +7,80 @@ import LegacyComponents
|
||||
import ComponentFlow
|
||||
|
||||
public final class SliderComponent: Component {
|
||||
public let valueCount: Int
|
||||
public let value: Int
|
||||
public let markPositions: Bool
|
||||
public final class Discrete: Equatable {
|
||||
public let valueCount: Int
|
||||
public let value: Int
|
||||
public let markPositions: Bool
|
||||
public let valueUpdated: (Int) -> Void
|
||||
|
||||
public init(valueCount: Int, value: Int, markPositions: Bool, valueUpdated: @escaping (Int) -> Void) {
|
||||
self.valueCount = valueCount
|
||||
self.value = value
|
||||
self.markPositions = markPositions
|
||||
self.valueUpdated = valueUpdated
|
||||
}
|
||||
|
||||
public static func ==(lhs: Discrete, rhs: Discrete) -> Bool {
|
||||
if lhs.valueCount != rhs.valueCount {
|
||||
return false
|
||||
}
|
||||
if lhs.value != rhs.value {
|
||||
return false
|
||||
}
|
||||
if lhs.markPositions != rhs.markPositions {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
public final class Continuous: Equatable {
|
||||
public let value: CGFloat
|
||||
public let valueUpdated: (CGFloat) -> Void
|
||||
|
||||
public init(value: CGFloat, valueUpdated: @escaping (CGFloat) -> Void) {
|
||||
self.value = value
|
||||
self.valueUpdated = valueUpdated
|
||||
}
|
||||
|
||||
public static func ==(lhs: Continuous, rhs: Continuous) -> Bool {
|
||||
if lhs.value != rhs.value {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
public enum Content: Equatable {
|
||||
case discrete(Discrete)
|
||||
case continuous(Continuous)
|
||||
}
|
||||
|
||||
public let content: Content
|
||||
public let trackBackgroundColor: UIColor
|
||||
public let trackForegroundColor: UIColor
|
||||
public let knobSize: CGFloat?
|
||||
public let knobColor: UIColor?
|
||||
public let valueUpdated: (Int) -> Void
|
||||
public let isTrackingUpdated: ((Bool) -> Void)?
|
||||
|
||||
public init(
|
||||
valueCount: Int,
|
||||
value: Int,
|
||||
markPositions: Bool,
|
||||
content: Content,
|
||||
trackBackgroundColor: UIColor,
|
||||
trackForegroundColor: UIColor,
|
||||
knobSize: CGFloat? = nil,
|
||||
knobColor: UIColor? = nil,
|
||||
valueUpdated: @escaping (Int) -> Void,
|
||||
isTrackingUpdated: ((Bool) -> Void)? = nil
|
||||
) {
|
||||
self.valueCount = valueCount
|
||||
self.value = value
|
||||
self.markPositions = markPositions
|
||||
self.content = content
|
||||
self.trackBackgroundColor = trackBackgroundColor
|
||||
self.trackForegroundColor = trackForegroundColor
|
||||
self.knobSize = knobSize
|
||||
self.knobColor = knobColor
|
||||
self.valueUpdated = valueUpdated
|
||||
self.isTrackingUpdated = isTrackingUpdated
|
||||
}
|
||||
|
||||
public static func ==(lhs: SliderComponent, rhs: SliderComponent) -> Bool {
|
||||
if lhs.valueCount != rhs.valueCount {
|
||||
return false
|
||||
}
|
||||
if lhs.value != rhs.value {
|
||||
return false
|
||||
}
|
||||
if lhs.markPositions != rhs.markPositions {
|
||||
if lhs.content != rhs.content {
|
||||
return false
|
||||
}
|
||||
if lhs.trackBackgroundColor != rhs.trackBackgroundColor {
|
||||
@@ -122,10 +156,16 @@ public final class SliderComponent: Component {
|
||||
sliderView.minimumValue = 0.0
|
||||
sliderView.startValue = 0.0
|
||||
sliderView.disablesInteractiveTransitionGestureRecognizer = true
|
||||
sliderView.maximumValue = CGFloat(component.valueCount - 1)
|
||||
sliderView.positionsCount = component.valueCount
|
||||
sliderView.useLinesForPositions = true
|
||||
sliderView.markPositions = component.markPositions
|
||||
|
||||
switch component.content {
|
||||
case let .discrete(discrete):
|
||||
sliderView.maximumValue = CGFloat(discrete.valueCount - 1)
|
||||
sliderView.positionsCount = discrete.valueCount
|
||||
sliderView.useLinesForPositions = true
|
||||
sliderView.markPositions = discrete.markPositions
|
||||
case .continuous:
|
||||
sliderView.maximumValue = 1.0
|
||||
}
|
||||
|
||||
sliderView.backgroundColor = nil
|
||||
sliderView.isOpaque = false
|
||||
@@ -162,7 +202,12 @@ public final class SliderComponent: Component {
|
||||
self.sliderView = sliderView
|
||||
self.addSubview(sliderView)
|
||||
}
|
||||
sliderView.value = CGFloat(component.value)
|
||||
switch component.content {
|
||||
case let .discrete(discrete):
|
||||
sliderView.value = CGFloat(discrete.value)
|
||||
case let .continuous(continuous):
|
||||
sliderView.value = continuous.value
|
||||
}
|
||||
sliderView.interactionBegan = {
|
||||
internalIsTrackingUpdated?(true)
|
||||
}
|
||||
@@ -180,7 +225,12 @@ public final class SliderComponent: Component {
|
||||
guard let component = self.component, let sliderView = self.sliderView else {
|
||||
return
|
||||
}
|
||||
component.valueUpdated(Int(sliderView.value))
|
||||
switch component.content {
|
||||
case let .discrete(discrete):
|
||||
discrete.valueUpdated(Int(sliderView.value))
|
||||
case let .continuous(continuous):
|
||||
continuous.valueUpdated(sliderView.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user