Skip to content

Commit 0044bde

Browse files
committed
Various improvements
1 parent 5d9d21e commit 0044bde

File tree

6 files changed

+199
-107
lines changed

6 files changed

+199
-107
lines changed

submodules/TelegramUI/Components/Gifts/GiftAnimationComponent/Sources/GiftCompositionComponent.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public final class GiftCompositionComponent: Component {
3939
let animationOffset: CGPoint?
4040
let animationScale: CGFloat?
4141
let displayAnimationStars: Bool
42+
let animateScaleOnTransition: Bool
43+
let alwaysAnimateTransition: Bool
4244
let revealedAttributes: Set<StarGift.UniqueGift.Attribute.AttributeType>
4345
let externalState: ExternalState?
4446
let requestUpdate: (ComponentTransition) -> Void
@@ -50,6 +52,8 @@ public final class GiftCompositionComponent: Component {
5052
animationOffset: CGPoint? = nil,
5153
animationScale: CGFloat? = nil,
5254
displayAnimationStars: Bool = false,
55+
animateScaleOnTransition: Bool = true,
56+
alwaysAnimateTransition: Bool = false,
5357
revealedAttributes: Set<StarGift.UniqueGift.Attribute.AttributeType> = Set(),
5458
externalState: ExternalState? = nil,
5559
requestUpdate: @escaping (ComponentTransition) -> Void = { _ in }
@@ -60,6 +64,8 @@ public final class GiftCompositionComponent: Component {
6064
self.animationOffset = animationOffset
6165
self.animationScale = animationScale
6266
self.displayAnimationStars = displayAnimationStars
67+
self.animateScaleOnTransition = animateScaleOnTransition
68+
self.alwaysAnimateTransition = alwaysAnimateTransition
6369
self.revealedAttributes = revealedAttributes
6470
self.externalState = externalState
6571
self.requestUpdate = requestUpdate
@@ -84,6 +90,9 @@ public final class GiftCompositionComponent: Component {
8490
if lhs.displayAnimationStars != rhs.displayAnimationStars {
8591
return false
8692
}
93+
if lhs.animateScaleOnTransition != rhs.animateScaleOnTransition {
94+
return false
95+
}
8796
if lhs.revealedAttributes != rhs.revealedAttributes {
8897
return false
8998
}
@@ -767,7 +776,9 @@ public final class GiftCompositionComponent: Component {
767776
}
768777

769778
var animateTransition = false
770-
if self.animatePreviewTransition {
779+
if component.alwaysAnimateTransition {
780+
animateTransition = true
781+
} else if self.animatePreviewTransition {
771782
animateTransition = true
772783
self.animatePreviewTransition = false
773784
} else if let previousComponent, case .preview = previousComponent.subject, case .unique = component.subject {
@@ -788,6 +799,9 @@ public final class GiftCompositionComponent: Component {
788799
bounce = self.previewPatternIndex == -1
789800
background = false
790801
}
802+
if !component.animateScaleOnTransition {
803+
bounce = false
804+
}
791805
backgroundView.animateTransition(background: background, bounce: bounce)
792806
}
793807
if animateBackdropSwipe {

submodules/TelegramUI/Components/Gifts/GiftItemComponent/Sources/GiftItemComponent.swift

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ public final class GiftItemComponent: Component {
168168
let isEditing: Bool
169169
let isDateLocked: Bool
170170
let isPlaceholder: Bool
171+
let animateChanges: Bool
171172
let mode: Mode
172173
let action: (() -> Void)?
173174
let contextAction: ((UIView, ContextGesture) -> Void)?
@@ -193,6 +194,7 @@ public final class GiftItemComponent: Component {
193194
isEditing: Bool = false,
194195
isDateLocked: Bool = false,
195196
isPlaceholder: Bool = false,
197+
animateChanges: Bool = false,
196198
mode: Mode = .generic,
197199
action: (() -> Void)? = nil,
198200
contextAction: ((UIView, ContextGesture) -> Void)? = nil
@@ -217,6 +219,7 @@ public final class GiftItemComponent: Component {
217219
self.isEditing = isEditing
218220
self.isDateLocked = isDateLocked
219221
self.isPlaceholder = isPlaceholder
222+
self.animateChanges = animateChanges
220223
self.mode = mode
221224
self.action = action
222225
self.contextAction = contextAction
@@ -283,6 +286,9 @@ public final class GiftItemComponent: Component {
283286
if lhs.isPlaceholder != rhs.isPlaceholder {
284287
return false
285288
}
289+
if lhs.animateChanges != rhs.animateChanges {
290+
return false
291+
}
286292
if lhs.mode != rhs.mode {
287293
return false
288294
}
@@ -642,12 +648,22 @@ public final class GiftItemComponent: Component {
642648
}
643649

644650
var animationTransition = transition
651+
var animateBackgroundChange = false
645652
if self.animationLayer == nil || self.animationFile?.fileId != animationFile?.fileId, let emoji {
646653
animationTransition = .immediate
647654
self.animationFile = animationFile
655+
var animateAppearance = false
648656
if let animationLayer = self.animationLayer {
649657
self.animationLayer = nil
650-
animationLayer.removeFromSuperlayer()
658+
if component.animateChanges {
659+
animateAppearance = true
660+
animateBackgroundChange = true
661+
animationLayer.animateAlpha(from: 1.0, to: 0.0, duration: 0.25, removeOnCompletion: false, completion: { _ in
662+
animationLayer.removeFromSuperlayer()
663+
})
664+
} else {
665+
animationLayer.removeFromSuperlayer()
666+
}
651667
}
652668
let animationLayer = InlineStickerItemLayer(
653669
context: .account(component.context),
@@ -670,6 +686,9 @@ public final class GiftItemComponent: Component {
670686
} else {
671687
self.layer.insertSublayer(animationLayer, above: self.backgroundLayer)
672688
}
689+
if animateAppearance {
690+
animationLayer.animateAlpha(from: 0.0, to: 1.0, duration: 0.25)
691+
}
673692
}
674693

675694
let animationFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - iconSize.width) / 2.0), y: component.mode == .generic ? animationOffset : (floorToScreenPixels((size.height - iconSize.height) / 2.0) + explicitAnimationOffset)), size: iconSize)
@@ -678,6 +697,11 @@ public final class GiftItemComponent: Component {
678697
}
679698

680699
if let backgroundColor {
700+
if let backgroundView = self.patternView.view as? PeerInfoCoverComponent.View {
701+
if animateBackgroundChange {
702+
backgroundView.animateTransition(background: true, bounce: false)
703+
}
704+
}
681705
let _ = self.patternView.update(
682706
transition: .immediate,
683707
component: AnyComponent(PeerInfoCoverComponent(
@@ -694,7 +718,7 @@ public final class GiftItemComponent: Component {
694718
environment: {},
695719
containerSize: backgroundSize
696720
)
697-
if let backgroundView = self.patternView.view {
721+
if let backgroundView = self.patternView.view as? PeerInfoCoverComponent.View {
698722
if backgroundView.superview == nil {
699723
backgroundView.layer.cornerRadius = cornerRadius
700724
if #available(iOS 13.0, *) {
@@ -1620,7 +1644,7 @@ public final class StarsButtonContentComponent: Component {
16201644
}
16211645
}
16221646

1623-
self.backgroundLayer.backgroundColor = backgroundColor.cgColor
1647+
transition.setBackgroundColor(layer: self.backgroundLayer, color: backgroundColor)
16241648
transition.setFrame(layer: self.backgroundLayer, frame: CGRect(origin: .zero, size: size))
16251649
self.backgroundLayer.cornerRadius = size.height / 2.0
16261650

submodules/TelegramUI/Components/Gifts/GiftOptionsScreen/Sources/GiftOptionsScreen.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ final class GiftOptionsScreenComponent: Component {
692692
action = environment.strings.Gift_Options_Gift_ViewAuction
693693
}
694694
subject = .starGift(gift: gift, price: action)
695-
} else if let availability = gift.availability, availability.remains == 0, let minResaleStars = availability.minResaleStars {
695+
} else if let availability = gift.availability, availability.remains == 0, availability.resale > 0, let minResaleStars = availability.minResaleStars {
696696
let priceString = presentationStringsFormattedNumber(Int32(minResaleStars), environment.dateTimeFormat.groupingSeparator)
697697
if let resaleConfiguration = self.resaleConfiguration, minResaleStars == resaleConfiguration.starGiftResaleMaxStarsAmount || availability.resale == 1 {
698698
subject = .starGift(gift: gift, price: "# \(priceString)")

0 commit comments

Comments
 (0)