Skip to content

Commit 14c5612

Browse files
committed
Various fixes
1 parent 008a1a0 commit 14c5612

File tree

5 files changed

+80
-38
lines changed

5 files changed

+80
-38
lines changed

submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/BadgeLabelView.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import UIKit
33
import Display
44
import ComponentFlow
55

6+
private let nondigitsCharacterSet = CharacterSet(charactersIn: "0123456789").inverted
7+
68
private let labelWidth: CGFloat = 16.0
79
private let labelHeight: CGFloat = 36.0
810
private let labelSize = CGSize(width: labelWidth, height: labelHeight)
@@ -100,23 +102,30 @@ final class BadgeLabelView: UIView {
100102

101103

102104
func update(value: String, transition: ComponentTransition) -> CGSize {
103-
if value.contains(" ") {
105+
let alphaTransition = ComponentTransition.easeInOut(duration: 0.15)
106+
if value.rangeOfCharacter(from: nondigitsCharacterSet) != nil {
104107
for (_, view) in self.itemViews {
105-
view.isHidden = true
108+
alphaTransition.setAlpha(view: view, alpha: 0.0)
106109
}
107110

108111
if self.staticLabel.superview == nil {
109112
self.staticLabel.textColor = self.color
110113
self.staticLabel.font = font
111-
112114
self.addSubview(self.staticLabel)
113115
}
116+
alphaTransition.setAlpha(view: self.staticLabel, alpha: 1.0)
117+
114118

115119
self.staticLabel.text = value
116120
let size = self.staticLabel.sizeThatFits(CGSize(width: 100.0, height: 100.0))
117121
self.staticLabel.frame = CGRect(origin: .zero, size: CGSize(width: size.width, height: labelHeight))
118122

119123
return CGSize(width: ceil(self.staticLabel.bounds.width), height: ceil(self.staticLabel.bounds.height))
124+
} else {
125+
for (_, view) in self.itemViews {
126+
alphaTransition.setAlpha(view: view, alpha: 1.0)
127+
}
128+
alphaTransition.setAlpha(view: self.staticLabel, alpha: 0.0)
120129
}
121130

122131
let string = value

submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftAuctionBidScreen.swift

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private final class BadgeComponent: Component {
229229
self.badgeForeground.bounds = CGRect(origin: CGPoint(), size: CGSize(width: 600.0, height: badgeFullSize.height + 10.0))
230230

231231
self.badgeIcon.frame = CGRect(x: 10.0, y: 9.0, width: 30.0, height: 30.0)
232-
self.badgeLabelMaskView.frame = CGRect(x: 0.0, y: 0.0, width: 100.0, height: 36.0)
232+
self.badgeLabelMaskView.frame = CGRect(x: 0.0, y: 0.0, width: 140.0, height: 36.0)
233233

234234
self.badgeView.alpha = 1.0
235235

@@ -1732,11 +1732,43 @@ private final class GiftAuctionBidScreenComponent: Component {
17321732
return
17331733
}
17341734
self.commitBid(value: value)
1735+
},
1736+
cancel: { [weak self] in
1737+
guard let self else {
1738+
return
1739+
}
1740+
self.resetSliderValue()
1741+
self.state?.updated()
17351742
}
17361743
)
17371744
self.environment?.controller()?.present(controller, in: .window(.root))
17381745
}
17391746

1747+
func resetSliderValue() {
1748+
guard let state = self.giftAuctionState else {
1749+
return
1750+
}
1751+
var minBidAmount: Int64 = 100
1752+
var maxBidAmount: Int64 = 50000
1753+
if case let .ongoing(_, _, _, auctionMinBidAmount, bidLevels, _, _, _, _, _) = state.auctionState {
1754+
minBidAmount = auctionMinBidAmount
1755+
if let firstLevel = bidLevels.first(where: { $0.position == 1 }) {
1756+
maxBidAmount = max(maxBidAmount, Int64(Double(firstLevel.amount) * 1.5))
1757+
}
1758+
}
1759+
var currentValue = max(Int(minBidAmount), 100)
1760+
if let myBidAmount = state.myState.bidAmount {
1761+
currentValue = Int(myBidAmount)
1762+
}
1763+
1764+
var minAllowedRealValue: Int64 = minBidAmount
1765+
if let myBidAmount = state.myState.bidAmount {
1766+
minAllowedRealValue = myBidAmount
1767+
}
1768+
1769+
self.amount = Amount(realValue: currentValue, minRealValue: Int(minBidAmount), minAllowedRealValue: Int(minAllowedRealValue), maxRealValue: Int(maxBidAmount), maxSliderValue: 999, isLogarithmic: true)
1770+
}
1771+
17401772
func update(component: GiftAuctionBidScreenComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment<ViewControllerComponentContainer.Environment>, transition: ComponentTransition) -> CGSize {
17411773
self.isUpdating = true
17421774
defer {
@@ -1833,26 +1865,7 @@ private final class GiftAuctionBidScreenComponent: Component {
18331865

18341866
if isFirstTime {
18351867
peerIds.append(context.account.peerId)
1836-
1837-
var minBidAmount: Int64 = 100
1838-
var maxBidAmount: Int64 = 50000
1839-
if case let .ongoing(_, _, _, auctionMinBidAmount, bidLevels, _, _, _, _, _) = state?.auctionState {
1840-
minBidAmount = auctionMinBidAmount
1841-
if let firstLevel = bidLevels.first(where: { $0.position == 1 }) {
1842-
maxBidAmount = max(maxBidAmount, Int64(Double(firstLevel.amount) * 1.5))
1843-
}
1844-
}
1845-
var currentValue = max(Int(minBidAmount), 100)
1846-
if let myBidAmount = state?.myState.bidAmount {
1847-
currentValue = Int(myBidAmount)
1848-
}
1849-
1850-
var minAllowedRealValue: Int64 = minBidAmount
1851-
if let myBidAmount = state?.myState.bidAmount {
1852-
minAllowedRealValue = myBidAmount
1853-
}
1854-
1855-
self.amount = Amount(realValue: currentValue, minRealValue: Int(minBidAmount), minAllowedRealValue: Int(minAllowedRealValue), maxRealValue: Int(maxBidAmount), maxSliderValue: 999, isLogarithmic: true)
1868+
self.resetSliderValue()
18561869
transition = .immediate
18571870
}
18581871

@@ -1940,6 +1953,10 @@ private final class GiftAuctionBidScreenComponent: Component {
19401953

19411954
if sliderValue == 1.0 && self.previousSliderValue != 1.0 {
19421955
self.presentCustomBidController()
1956+
HapticFeedback().tap()
1957+
if let sliderView = self.slider.view as? SliderComponent.View {
1958+
sliderView.cancelGestures()
1959+
}
19431960
}
19441961

19451962
self.previousSliderValue = sliderValue
@@ -1967,7 +1984,14 @@ private final class GiftAuctionBidScreenComponent: Component {
19671984
let sliderPlusSize = self.sliderPlus.update(
19681985
transition: .immediate,
19691986
component: AnyComponent(
1970-
MultilineTextComponent(text: .plain(NSAttributedString(string: "+", font: Font.with(size: 26.0, design: .round, weight: .regular), textColor: environment.theme.list.itemSecondaryTextColor.withAlphaComponent(0.5))))
1987+
Button(
1988+
content: AnyComponent(
1989+
MultilineTextComponent(text: .plain(NSAttributedString(string: "+", font: Font.with(size: 26.0, design: .round, weight: .regular), textColor: environment.theme.list.itemSecondaryTextColor.withAlphaComponent(0.5))))
1990+
),
1991+
action: { [weak self] in
1992+
self?.presentCustomBidController()
1993+
}
1994+
).minSize(CGSize(width: 30.0, height: 30.0))
19711995
),
19721996
environment: {},
19731997
containerSize: availableSize
@@ -1977,7 +2001,7 @@ private final class GiftAuctionBidScreenComponent: Component {
19772001

19782002
let sliderFrame = CGRect(origin: CGPoint(x: sliderInset, y: contentHeight), size: sliderSize)
19792003
let sliderBackgroundFrame = CGRect(origin: CGPoint(x: sliderFrame.minX - 8.0, y: sliderFrame.minY + 7.0), size: CGSize(width: sliderFrame.width + 16.0, height: sliderFrame.height - 14.0))
1980-
let sliderPlusFrame = CGRect(origin: CGPoint(x: sliderBackgroundFrame.maxX - sliderPlusSize.width - 6.0, y: sliderBackgroundFrame.minY - 3.0 + UIScreenPixel), size: sliderPlusSize)
2004+
let sliderPlusFrame = CGRect(origin: CGPoint(x: sliderBackgroundFrame.maxX - sliderPlusSize.width + 1.0, y: sliderBackgroundFrame.minY - 3.0 + UIScreenPixel), size: sliderPlusSize)
19812005

19822006
let progressFraction: CGFloat = CGFloat(self.amount.sliderValue) / CGFloat(self.amount.maxSliderValue)
19832007

@@ -2022,8 +2046,6 @@ private final class GiftAuctionBidScreenComponent: Component {
20222046
self.scrollContentView.addSubview(sliderBackgroundView)
20232047
self.scrollContentView.addSubview(sliderView)
20242048
self.scrollContentView.addSubview(sliderPlusView)
2025-
2026-
sliderPlusView.isUserInteractionEnabled = false
20272049
}
20282050
transition.setFrame(view: sliderView, frame: sliderFrame)
20292051

@@ -2032,13 +2054,12 @@ private final class GiftAuctionBidScreenComponent: Component {
20322054
transition.setFrame(view: sliderPlusView, frame: sliderPlusFrame)
20332055

20342056
var subtitle: String?
2035-
let badgeValue: String = "\(self.amount.realValue)"
2057+
var badgeValue: String = "\(self.amount.realValue)"
20362058
var subtitleOnTop = false
20372059

2038-
// if self.amount.sliderValue == self.amount.maxSliderValue {
2039-
// badgeValue = "Custom"
2040-
// } else
2041-
if let myBidAmount = self.giftAuctionState?.myState.bidAmount {
2060+
if self.amount.sliderValue == self.amount.maxSliderValue {
2061+
badgeValue = environment.strings.Gift_AuctionBid_Custom
2062+
} else if let myBidAmount = self.giftAuctionState?.myState.bidAmount {
20422063
if self.amount.realValue > myBidAmount {
20432064
subtitle = "+\(self.amount.realValue - Int(myBidAmount))"
20442065
subtitleOnTop = true

submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftAuctionCustomBidController.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,15 @@ private final class GiftAuctionCustomBidAlertContentNode: AlertContentNode {
297297
}
298298
}
299299

300-
func giftAuctionCustomBidController(context: AccountContext, title: String, text: String, placeholder: String, action: String, minValue: Int64, value: Int64, apply: @escaping (Int64) -> Void) -> AlertController {
300+
func giftAuctionCustomBidController(context: AccountContext, title: String, text: String, placeholder: String, action: String, minValue: Int64, value: Int64, apply: @escaping (Int64) -> Void, cancel: @escaping () -> Void) -> AlertController {
301301
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
302302

303303
var dismissImpl: ((Bool) -> Void)?
304304
var applyImpl: (() -> Void)?
305305

306306
let actions: [TextAlertAction] = [TextAlertAction(type: .genericAction, title: presentationData.strings.Common_Cancel, action: {
307307
dismissImpl?(true)
308+
cancel()
308309
}), TextAlertAction(type: .defaultAction, title: action, action: {
309310
applyImpl?()
310311
})]
@@ -330,8 +331,11 @@ func giftAuctionCustomBidController(context: AccountContext, title: String, text
330331
let presentationDataDisposable = context.sharedContext.presentationData.start(next: { [weak controller] presentationData in
331332
controller?.theme = AlertControllerTheme(presentationData: presentationData)
332333
})
333-
controller.dismissed = { _ in
334+
controller.dismissed = { byTapOutside in
334335
presentationDataDisposable.dispose()
336+
if byTapOutside {
337+
cancel()
338+
}
335339
}
336340
dismissImpl = { [weak controller, weak contentNode] animated in
337341
contentNode?.deactivateInput()

submodules/TelegramUI/Components/GlassBarButtonComponent/Sources/GlassBarButtonComponent.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ public final class GlassBarButtonComponent: Component {
9595
guard let self else {
9696
return
9797
}
98-
//let transition = ComponentTransition(animation: .curve(duration: highlighted ? 0.25 : 0.35, curve: .spring))
9998
if highlighted {
10099
self.containerView.layer.animateSpring(from: CGFloat((self.containerView.layer.presentation()?.value(forKeyPath: "transform.scale.y") as? NSNumber)?.floatValue ?? 1.0) as NSNumber, to: 1.3636 as NSNumber, keyPath: "transform.scale", duration: 0.5, removeOnCompletion: false)
101100
} else {
@@ -177,7 +176,7 @@ public final class GlassBarButtonComponent: Component {
177176
switch effectiveState {
178177
case .generic:
179178
genericAlpha = 1.0
180-
glassAlpha = 0.0
179+
glassAlpha = 0.001
181180
case .glass, .tintedGlass:
182181
glassAlpha = 1.0
183182
genericAlpha = 0.0
@@ -193,7 +192,7 @@ public final class GlassBarButtonComponent: Component {
193192
transition.setAlpha(view: self.genericContainerView, alpha: genericAlpha)
194193
transition.setFrame(view: self.genericContainerView, frame: bounds)
195194

196-
transition.setAlpha(view: self.glassBackgroundView, alpha: glassAlpha)
195+
transition.setAlpha(view: self.glassContainerView, alpha: glassAlpha)
197196
transition.setFrame(view: self.glassContainerView, frame: bounds)
198197

199198
transition.setFrame(view: self.genericBackgroundView, frame: bounds)

submodules/TelegramUI/Components/SliderComponent/Sources/SliderComponent.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@ public final class SliderComponent: Component {
140140
fatalError("init(coder:) has not been implemented")
141141
}
142142

143+
public func cancelGestures() {
144+
if let sliderView = self.sliderView, let gestureRecognizers = sliderView.gestureRecognizers {
145+
for gestureRecognizer in gestureRecognizers {
146+
gestureRecognizer.isEnabled = false
147+
gestureRecognizer.isEnabled = true
148+
}
149+
}
150+
}
151+
143152
func update(component: SliderComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: ComponentTransition) -> CGSize {
144153
self.component = component
145154
self.state = state

0 commit comments

Comments
 (0)