@@ -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
0 commit comments