mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Gift auctions
This commit is contained in:
@@ -381,6 +381,7 @@ public final class ButtonComponent: Component {
|
||||
|
||||
public let background: Background
|
||||
public let content: AnyComponentWithIdentity<Empty>
|
||||
public let fitToContentWidth: Bool
|
||||
public let isEnabled: Bool
|
||||
public let tintWhenDisabled: Bool
|
||||
public let allowActionWhenDisabled: Bool
|
||||
@@ -390,6 +391,7 @@ public final class ButtonComponent: Component {
|
||||
public init(
|
||||
background: Background,
|
||||
content: AnyComponentWithIdentity<Empty>,
|
||||
fitToContentWidth: Bool = false,
|
||||
isEnabled: Bool = true,
|
||||
tintWhenDisabled: Bool = true,
|
||||
allowActionWhenDisabled: Bool = false,
|
||||
@@ -398,6 +400,7 @@ public final class ButtonComponent: Component {
|
||||
) {
|
||||
self.background = background
|
||||
self.content = content
|
||||
self.fitToContentWidth = fitToContentWidth
|
||||
self.isEnabled = isEnabled
|
||||
self.tintWhenDisabled = tintWhenDisabled
|
||||
self.allowActionWhenDisabled = allowActionWhenDisabled
|
||||
@@ -412,6 +415,9 @@ public final class ButtonComponent: Component {
|
||||
if lhs.content != rhs.content {
|
||||
return false
|
||||
}
|
||||
if lhs.fitToContentWidth != rhs.fitToContentWidth {
|
||||
return false
|
||||
}
|
||||
if lhs.isEnabled != rhs.isEnabled {
|
||||
return false
|
||||
}
|
||||
@@ -538,6 +544,12 @@ public final class ButtonComponent: Component {
|
||||
environment: {},
|
||||
containerSize: CGSize(width: availableSize.width - cornerRadius, height: availableSize.height)
|
||||
)
|
||||
|
||||
var size = availableSize
|
||||
if component.fitToContentWidth {
|
||||
size.width = floor(contentSize.width + cornerRadius * 1.5)
|
||||
}
|
||||
|
||||
if let contentView = contentItem.view.view {
|
||||
var animateIn = false
|
||||
var contentTransition = transition
|
||||
@@ -549,7 +561,7 @@ public final class ButtonComponent: Component {
|
||||
|
||||
contentItem.view.parentState = state
|
||||
}
|
||||
let contentFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((availableSize.width - contentSize.width) * 0.5), y: floorToScreenPixels((availableSize.height - contentSize.height) * 0.5)), size: contentSize)
|
||||
let contentFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - contentSize.width) * 0.5), y: floorToScreenPixels((size.height - contentSize.height) * 0.5)), size: contentSize)
|
||||
|
||||
contentTransition.setFrame(view: contentView, frame: contentFrame)
|
||||
contentTransition.setAlpha(view: contentView, alpha: contentAlpha)
|
||||
@@ -557,7 +569,7 @@ public final class ButtonComponent: Component {
|
||||
if animateIn && previousContentItem != nil && !transition.animation.isImmediate {
|
||||
contentView.layer.animateScale(from: 0.4, to: 1.0, duration: 0.35, timingFunction: kCAMediaTimingFunctionSpring)
|
||||
contentView.layer.animateAlpha(from: 0.0, to: contentAlpha, duration: 0.1)
|
||||
contentView.layer.animatePosition(from: CGPoint(x: 0.0, y: -availableSize.height * 0.15), to: CGPoint(), duration: 0.35, timingFunction: kCAMediaTimingFunctionSpring, additive: true)
|
||||
contentView.layer.animatePosition(from: CGPoint(x: 0.0, y: -size.height * 0.15), to: CGPoint(), duration: 0.35, timingFunction: kCAMediaTimingFunctionSpring, additive: true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,7 +579,7 @@ public final class ButtonComponent: Component {
|
||||
previousContentView.layer.animateAlpha(from: contentAlpha, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak previousContentView] _ in
|
||||
previousContentView?.removeFromSuperview()
|
||||
})
|
||||
previousContentView.layer.animatePosition(from: CGPoint(), to: CGPoint(x: 0.0, y: availableSize.height * 0.35), duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, additive: true)
|
||||
previousContentView.layer.animatePosition(from: CGPoint(), to: CGPoint(x: 0.0, y: size.height * 0.35), duration: 0.3, timingFunction: kCAMediaTimingFunctionSpring, removeOnCompletion: false, additive: true)
|
||||
} else {
|
||||
previousContentView.removeFromSuperview()
|
||||
}
|
||||
@@ -587,7 +599,7 @@ public final class ButtonComponent: Component {
|
||||
}
|
||||
let indicatorSize = CGSize(width: 22.0, height: 22.0)
|
||||
transition.setAlpha(view: activityIndicator.view, alpha: 1.0)
|
||||
activityIndicatorTransition.setFrame(view: activityIndicator.view, frame: CGRect(origin: CGPoint(x: floorToScreenPixels((availableSize.width - indicatorSize.width) / 2.0), y: floorToScreenPixels((availableSize.height - indicatorSize.height) / 2.0)), size: indicatorSize))
|
||||
activityIndicatorTransition.setFrame(view: activityIndicator.view, frame: CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - indicatorSize.width) / 2.0), y: floorToScreenPixels((size.height - indicatorSize.height) / 2.0)), size: indicatorSize))
|
||||
} else {
|
||||
if let activityIndicator = self.activityIndicator {
|
||||
self.activityIndicator = nil
|
||||
@@ -608,8 +620,8 @@ public final class ButtonComponent: Component {
|
||||
self.shimmeringView = shimmeringView
|
||||
self.containerView.insertSubview(shimmeringView, at: 0)
|
||||
}
|
||||
shimmeringView.update(size: availableSize, background: component.background, cornerRadius: component.background.cornerRadius, transition: shimmeringTransition)
|
||||
shimmeringTransition.setFrame(view: shimmeringView, frame: CGRect(origin: .zero, size: availableSize))
|
||||
shimmeringView.update(size: size, background: component.background, cornerRadius: component.background.cornerRadius, transition: shimmeringTransition)
|
||||
shimmeringTransition.setFrame(view: shimmeringView, frame: CGRect(origin: .zero, size: size))
|
||||
} else if let shimmeringView = self.shimmeringView {
|
||||
self.shimmeringView = nil
|
||||
shimmeringView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.15, removeOnCompletion: false, completion: { _ in
|
||||
@@ -636,7 +648,7 @@ public final class ButtonComponent: Component {
|
||||
chromeView.alpha = 0.8
|
||||
chromeView.image = GlassBackgroundView.generateForegroundImage(size: CGSize(width: 26.0 * 2.0, height: 26.0 * 2.0), isDark: component.background.color.lightness < 0.36, fillColor: .clear)
|
||||
}
|
||||
chromeTransition.setFrame(view: chromeView, frame: CGRect(origin: .zero, size: availableSize))
|
||||
chromeTransition.setFrame(view: chromeView, frame: CGRect(origin: .zero, size: size))
|
||||
} else if let chromeView = self.chromeView {
|
||||
self.chromeView = nil
|
||||
chromeView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.15, removeOnCompletion: false, completion: { _ in
|
||||
@@ -644,10 +656,10 @@ public final class ButtonComponent: Component {
|
||||
})
|
||||
}
|
||||
|
||||
transition.setPosition(view: self.containerView, position: CGPoint(x: availableSize.width / 2.0, y: availableSize.height / 2.0))
|
||||
transition.setBoundsSize(view: self.containerView, size: availableSize)
|
||||
transition.setPosition(view: self.containerView, position: CGPoint(x: size.width / 2.0, y: size.height / 2.0))
|
||||
transition.setBoundsSize(view: self.containerView, size: size)
|
||||
|
||||
return availableSize
|
||||
return size
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user