@@ -95,7 +95,8 @@ final class GiftStoreScreenComponent: Component {
9595
9696 private var starsStateDisposable : Disposable ?
9797 private var starsState : StarsContext . State ?
98- private var initialCount : Int ?
98+ private var initialCount : Int32 ?
99+ private var showLoading = true
99100
100101 private var component : GiftStoreScreenComponent ?
101102 private( set) weak var state : State ?
@@ -338,7 +339,9 @@ final class GiftStoreScreenComponent: Component {
338339 guard let self else {
339340 return
340341 }
342+ self . showLoading = true
341343 self . state? . starGiftsContext. updateFilterAttributes ( [ ] )
344+ self . scrollToTop ( )
342345 } ,
343346 animateScale: false
344347 )
@@ -357,7 +360,7 @@ final class GiftStoreScreenComponent: Component {
357360 var emptyResultsActionFrame = CGRect (
358361 origin: CGPoint (
359362 x: floorToScreenPixels ( ( availableWidth - emptyResultsActionSize. width) / 2.0 ) ,
360- y: max ( self . scrollView. contentSize. height - 8 .0, availableHeight - bottomInset - emptyResultsActionSize. height - 16.0 )
363+ y: max ( self . scrollView. contentSize. height - 70 .0, availableHeight - bottomInset - emptyResultsActionSize. height - 16.0 )
361364 ) ,
362365 size: emptyResultsActionSize
363366 )
@@ -435,7 +438,7 @@ final class GiftStoreScreenComponent: Component {
435438 if view. superview == nil {
436439 view. alpha = 0.0
437440 fadeTransition. setAlpha ( view: view, alpha: 1.0 )
438- self . insertSubview ( view , belowSubview : self . loadingNode . view)
441+ self . scrollView . addSubview ( view)
439442 }
440443 view. bounds = CGRect ( origin: . zero, size: emptyResultsActionFrame. size)
441444 ComponentTransition . immediate. setPosition ( view: view, position: emptyResultsActionFrame. center)
@@ -451,7 +454,7 @@ final class GiftStoreScreenComponent: Component {
451454 }
452455
453456 let bottomContentOffset = max ( 0.0 , self . scrollView. contentSize. height - self . scrollView. contentOffset. y - self . scrollView. frame. height)
454- if interactive, bottomContentOffset < 320 .0 {
457+ if interactive, bottomContentOffset < 1000 .0 {
455458 self . state? . starGiftsContext. loadMore ( )
456459 }
457460 }
@@ -471,6 +474,7 @@ final class GiftStoreScreenComponent: Component {
471474 guard let self else {
472475 return
473476 }
477+ self . showLoading = true
474478 self . state? . starGiftsContext. updateSorting ( . value)
475479 self . scrollToTop ( )
476480 } ) ) )
@@ -481,6 +485,7 @@ final class GiftStoreScreenComponent: Component {
481485 guard let self else {
482486 return
483487 }
488+ self . showLoading = true
484489 self . state? . starGiftsContext. updateSorting ( . date)
485490 self . scrollToTop ( )
486491 } ) ) )
@@ -491,6 +496,7 @@ final class GiftStoreScreenComponent: Component {
491496 guard let self else {
492497 return
493498 }
499+ self . showLoading = true
494500 self . state? . starGiftsContext. updateSorting ( . number)
495501 self . scrollToTop ( )
496502 } ) ) )
@@ -514,7 +520,13 @@ final class GiftStoreScreenComponent: Component {
514520 } else {
515521 return false
516522 }
517- }
523+ } . sorted ( by: { lhs, rhs in
524+ if case let . model( _, lhsFile, _) = lhs, case let . model( _, rhsFile, _) = rhs, let lhsCount = self . state? . starGiftsState? . attributeCount [ . model( lhsFile. fileId. id) ] , let rhsCount = self . state? . starGiftsState? . attributeCount [ . model( rhsFile. fileId. id) ] {
525+ return lhsCount > rhsCount
526+ } else {
527+ return false
528+ }
529+ } )
518530
519531 let currentFilterAttributes = self . state? . starGiftsState? . filterAttributes ?? [ ]
520532 let selectedModelAttributes = currentFilterAttributes. filter { attribute in
@@ -564,6 +576,7 @@ final class GiftStoreScreenComponent: Component {
564576 updatedFilterAttributes. append ( attribute)
565577 }
566578 }
579+ self . showLoading = true
567580 self . state? . starGiftsContext. updateFilterAttributes ( updatedFilterAttributes)
568581 self . scrollToTop ( )
569582 } ,
@@ -577,6 +590,7 @@ final class GiftStoreScreenComponent: Component {
577590 }
578591 return true
579592 }
593+ self . showLoading = true
580594 self . state? . starGiftsContext. updateFilterAttributes ( updatedFilterAttributes)
581595 self . scrollToTop ( )
582596 }
@@ -607,7 +621,13 @@ final class GiftStoreScreenComponent: Component {
607621 } else {
608622 return false
609623 }
610- }
624+ } . sorted ( by: { lhs, rhs in
625+ if case let . backdrop( _, lhsId, _, _, _, _, _) = lhs, case let . backdrop( _, rhsId, _, _, _, _, _) = rhs, let lhsCount = self . state? . starGiftsState? . attributeCount [ . backdrop( lhsId) ] , let rhsCount = self . state? . starGiftsState? . attributeCount [ . backdrop( rhsId) ] {
626+ return lhsCount > rhsCount
627+ } else {
628+ return false
629+ }
630+ } )
611631
612632 let currentFilterAttributes = self . state? . starGiftsState? . filterAttributes ?? [ ]
613633 let selectedBackdropAttributes = currentFilterAttributes. filter { attribute in
@@ -657,6 +677,7 @@ final class GiftStoreScreenComponent: Component {
657677 updatedFilterAttributes. append ( attribute)
658678 }
659679 }
680+ self . showLoading = true
660681 self . state? . starGiftsContext. updateFilterAttributes ( updatedFilterAttributes)
661682 self . scrollToTop ( )
662683 } ,
@@ -670,6 +691,7 @@ final class GiftStoreScreenComponent: Component {
670691 }
671692 return true
672693 }
694+ self . showLoading = true
673695 self . state? . starGiftsContext. updateFilterAttributes ( updatedFilterAttributes)
674696 self . scrollToTop ( )
675697 }
@@ -700,7 +722,13 @@ final class GiftStoreScreenComponent: Component {
700722 } else {
701723 return false
702724 }
703- }
725+ } . sorted ( by: { lhs, rhs in
726+ if case let . pattern( _, lhsFile, _) = lhs, case let . pattern( _, rhsFile, _) = rhs, let lhsCount = self . state? . starGiftsState? . attributeCount [ . pattern( lhsFile. fileId. id) ] , let rhsCount = self . state? . starGiftsState? . attributeCount [ . pattern( rhsFile. fileId. id) ] {
727+ return lhsCount > rhsCount
728+ } else {
729+ return false
730+ }
731+ } )
704732
705733 let currentFilterAttributes = self . state? . starGiftsState? . filterAttributes ?? [ ]
706734 let selectedPatternAttributes = currentFilterAttributes. filter { attribute in
@@ -750,6 +778,7 @@ final class GiftStoreScreenComponent: Component {
750778 updatedFilterAttributes. append ( attribute)
751779 }
752780 }
781+ self . showLoading = true
753782 self . state? . starGiftsContext. updateFilterAttributes ( updatedFilterAttributes)
754783 self . scrollToTop ( )
755784 } ,
@@ -763,6 +792,7 @@ final class GiftStoreScreenComponent: Component {
763792 }
764793 return true
765794 }
795+ self . showLoading = true
766796 self . state? . starGiftsContext. updateFilterAttributes ( updatedFilterAttributes)
767797 self . scrollToTop ( )
768798 }
@@ -804,6 +834,12 @@ final class GiftStoreScreenComponent: Component {
804834 self . component = component
805835
806836 let isLoading = self . effectiveIsLoading
837+ if case let . ready( loadMore, nextOffset) = self . state? . starGiftsState? . dataState {
838+ if loadMore && nextOffset == nil {
839+ } else {
840+ self . showLoading = false
841+ }
842+ }
807843
808844 let theme = environment. theme
809845 let strings = environment. strings
@@ -812,7 +848,7 @@ final class GiftStoreScreenComponent: Component {
812848 self . backgroundColor = environment. theme. list. blocksBackgroundColor
813849 }
814850
815- let bottomContentInset : CGFloat = 24 .0
851+ let bottomContentInset : CGFloat = 56 .0
816852 let sideInset : CGFloat = 16.0 + environment. safeInsets. left
817853 let headerSideInset : CGFloat = 24.0 + environment. safeInsets. left
818854
@@ -927,7 +963,7 @@ final class GiftStoreScreenComponent: Component {
927963 }
928964
929965 let effectiveCount : Int32
930- if let count = self . effectiveGifts ? . count, count > 0 || self . initialCount != nil {
966+ if let count = self . state ? . starGiftsState ? . count, count > 0 || self . initialCount != nil {
931967 if self . initialCount == nil {
932968 self . initialCount = count
933969 }
@@ -1047,6 +1083,7 @@ final class GiftStoreScreenComponent: Component {
10471083
10481084 let loadingTransition : ComponentTransition = . easeInOut( duration: 0.25 )
10491085
1086+ var showingFilters = false
10501087 let filterSize = self . filterSelector. update (
10511088 transition: transition,
10521089 component: AnyComponent ( FilterSelectorComponent (
@@ -1069,6 +1106,7 @@ final class GiftStoreScreenComponent: Component {
10691106
10701107 if let initialCount = self . initialCount, initialCount >= minimumCountToDisplayFilters {
10711108 loadingTransition. setAlpha ( view: filterSelectorView, alpha: 1.0 )
1109+ showingFilters = true
10721110 }
10731111 }
10741112
@@ -1112,8 +1150,8 @@ final class GiftStoreScreenComponent: Component {
11121150
11131151 self . updateScrolling ( transition: transition)
11141152
1115- if isLoading {
1116- self . loadingNode. update ( size: availableSize, theme: environment. theme, transition: . immediate)
1153+ if isLoading && self . showLoading {
1154+ self . loadingNode. update ( size: availableSize, theme: environment. theme, showFilters : !showingFilters , transition: . immediate)
11171155 loadingTransition. setAlpha ( view: self . loadingNode. view, alpha: 1.0 )
11181156 } else {
11191157 loadingTransition. setAlpha ( view: self . loadingNode. view, alpha: 0.0 )
0 commit comments