mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Giveaway improvements
This commit is contained in:
@@ -11,11 +11,13 @@ public final class List<ChildEnvironment: Equatable>: CombinedComponent {
|
||||
|
||||
private let items: [AnyComponentWithIdentity<ChildEnvironment>]
|
||||
private let direction: Direction
|
||||
private let centerAlignment: Bool
|
||||
private let appear: Transition.Appear
|
||||
|
||||
public init(_ items: [AnyComponentWithIdentity<ChildEnvironment>], direction: Direction = .vertical, appear: Transition.Appear = .default()) {
|
||||
public init(_ items: [AnyComponentWithIdentity<ChildEnvironment>], direction: Direction = .vertical, centerAlignment: Bool = false, appear: Transition.Appear = .default()) {
|
||||
self.items = items
|
||||
self.direction = direction
|
||||
self.centerAlignment = centerAlignment
|
||||
self.appear = appear
|
||||
}
|
||||
|
||||
@@ -26,6 +28,9 @@ public final class List<ChildEnvironment: Equatable>: CombinedComponent {
|
||||
if lhs.direction != rhs.direction {
|
||||
return false
|
||||
}
|
||||
if lhs.centerAlignment != rhs.centerAlignment {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -42,6 +47,10 @@ public final class List<ChildEnvironment: Equatable>: CombinedComponent {
|
||||
transition: context.transition
|
||||
)
|
||||
}
|
||||
|
||||
let maxWidth: CGFloat = updatedChildren.reduce(CGFloat(0.0)) { partialResult, child in
|
||||
return max(partialResult, child.size.width)
|
||||
}
|
||||
|
||||
var nextOrigin: CGFloat = 0.0
|
||||
for child in updatedChildren {
|
||||
@@ -51,7 +60,13 @@ public final class List<ChildEnvironment: Equatable>: CombinedComponent {
|
||||
position = CGPoint(x: nextOrigin + child.size.width / 2.0, y: child.size.height / 2.0)
|
||||
nextOrigin += child.size.width
|
||||
case .vertical:
|
||||
position = CGPoint(x: child.size.width / 2.0, y: nextOrigin + child.size.height / 2.0)
|
||||
let originX: CGFloat
|
||||
if context.component.centerAlignment {
|
||||
originX = maxWidth / 2.0
|
||||
} else {
|
||||
originX = child.size.width / 2.0
|
||||
}
|
||||
position = CGPoint(x: originX, y: nextOrigin + child.size.height / 2.0)
|
||||
nextOrigin += child.size.height
|
||||
}
|
||||
context.add(child
|
||||
@@ -63,8 +78,14 @@ public final class List<ChildEnvironment: Equatable>: CombinedComponent {
|
||||
switch context.component.direction {
|
||||
case .horizontal:
|
||||
return CGSize(width: min(context.availableSize.width, nextOrigin), height: context.availableSize.height)
|
||||
case.vertical:
|
||||
return CGSize(width: context.availableSize.width, height: min(context.availableSize.height, nextOrigin))
|
||||
case .vertical:
|
||||
let width: CGFloat
|
||||
if context.component.centerAlignment {
|
||||
width = maxWidth
|
||||
} else {
|
||||
width = context.availableSize.width
|
||||
}
|
||||
return CGSize(width: width, height: min(context.availableSize.height, nextOrigin))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user