File tree Expand file tree Collapse file tree 4 files changed +28
-3
lines changed Expand file tree Collapse file tree 4 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -180,6 +180,7 @@ export abstract class CollectionViewBase extends View implements CollectionViewD
180180 public abstract refreshVisibleItems ( ) ;
181181 public abstract isItemAtIndexVisible ( index : number ) ;
182182 public abstract findFirstVisibleItemIndex ( ) : number ;
183+ public abstract findLastVisibleItemIndex ( ) : number ;
183184 public abstract scrollToIndex ( index : number , animated : boolean ) ;
184185 public abstract scrollToOffset ( value : number , animated ?: boolean ) : any ;
185186
Original file line number Diff line number Diff line change @@ -979,6 +979,17 @@ export class CollectionView extends CollectionViewBase {
979979 }
980980 return - 1 ;
981981 }
982+ public findLastVisibleItemIndex ( ) {
983+ const view = this . nativeViewProtected ;
984+ if ( ! view ) {
985+ return - 1 ;
986+ }
987+ const layoutManager = this . layoutManager as androidx . recyclerview . widget . LinearLayoutManager ;
988+ if ( layoutManager [ 'findLastVisibleItemPosition' ] ) {
989+ return layoutManager . findLastVisibleItemPosition ( ) ;
990+ }
991+ return - 1 ;
992+ }
982993
983994 _layedOut = false ;
984995 @profile
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ export class CollectionView extends CollectionViewBase {
1515 public refreshVisibleItems ( ) ;
1616 public isItemAtIndexVisible ( index : number ) : boolean ;
1717 public findFirstVisibleItemIndex ( ) : number ;
18+ public findLastVisibleItemIndex ( ) : number ;
1819 public scrollToIndex ( index : number , animated ?: boolean , snap ?: SnapPosition = SnapPosition . START ) ;
1920 public scrollToOffset ( value : number , animation ?: boolean ) ;
2021 public getViewForItemAtIndex ( index : number ) : View ;
Original file line number Diff line number Diff line change @@ -679,11 +679,23 @@ export class CollectionView extends CollectionViewBase {
679679 if ( ! view ) {
680680 return - 1 ;
681681 }
682- const indexes = Array . from < NSIndexPath > ( view . indexPathsForVisibleItems )
682+
683+ return this . getRowIndexPath ( view ) [ 0 ] ?? - 1 ;
684+ }
685+ public findLastVisibleItemIndex ( ) {
686+ const view = this . nativeViewProtected ;
687+ if ( ! view ) {
688+ return - 1 ;
689+ }
690+ return this . getRowIndexPath ( view ) . at ( - 1 ) ?? - 1 ;
691+ }
692+
693+ private getRowIndexPath ( view : UICollectionView ) {
694+ return Array . from < NSIndexPath > ( view . indexPathsForVisibleItems )
683695 . map ( ( e ) => e . row )
684- . sort ( ) ;
685- return indexes [ 0 ] ?? - 1 ;
696+ . sort ( ( a , b ) => a - b ) ;
686697 }
698+
687699 @profile
688700 public refresh ( ) {
689701 if ( ! this . isLoaded || ! this . nativeView ) {
You can’t perform that action at this time.
0 commit comments