@@ -242,26 +242,19 @@ export class Pager extends PagerBase {
242
242
}
243
243
244
244
get lastIndex ( ) : number {
245
- if ( this . items && this . items . length === 0 ) {
246
- return 0 ;
247
- }
248
- return this . circularMode ? this . itemCount - 3 : this . itemCount - 1 ;
245
+ return Math . max ( 0 , this . circularMode ? this . itemCount - 3 : this . itemCount - 1 ) ;
249
246
}
250
247
251
248
get firstDummy ( ) : number {
252
- const count = this . itemCount ;
253
- if ( count === 0 ) {
254
- return 0 ;
255
- }
256
- return this . itemCount - 1 ;
249
+ return Math . max ( 0 , this . itemCount - 1 ) ;
257
250
}
258
251
259
252
get lastDummy ( ) : number {
260
253
return this . lastIndex ;
261
254
}
262
255
263
256
public get _childrenCount ( ) {
264
- return this . items ?. length || this . _childrenViews ?. length || 0 ;
257
+ return this . items ?. length ?? this . _childrenViews ?. length ?? 0 ;
265
258
}
266
259
267
260
public itemTemplateUpdated ( oldData : any , newData : any ) : void { }
@@ -450,18 +443,9 @@ export class Pager extends PagerBase {
450
443
return ;
451
444
}
452
445
const maxMinIndex = Math . min ( Math . max ( 0 , index ) , this . _childrenCount - 1 ) ;
453
- if ( ! this . isLoaded ) {
454
- return selectedIndexProperty . nativeValueChange ( this , maxMinIndex ) ;
455
- }
456
446
const frame = this . page && this . page . frame ;
457
- if ( this . page && frame ) {
458
- if ( frame . _executingContext ) {
459
- if ( frame . _executingContext . entry . resolvedPage !== this . page ) {
460
- return selectedIndexProperty . nativeValueChange ( this , maxMinIndex ) ;
461
- }
462
- } else if ( frame . currentPage !== this . page ) {
463
- return selectedIndexProperty . nativeValueChange ( this , maxMinIndex ) ;
464
- }
447
+ if ( ! this . isLoaded || ( this . page && frame && ( frame . _executingContext ?. entry . resolvedPage !== this . page || frame . currentPage !== this . page ) ) ) {
448
+ return selectedIndexProperty . nativeValueChange ( this , maxMinIndex ) ;
465
449
}
466
450
// dispatch_async(main_queue, () => {
467
451
if ( this . mDataSource . collectionViewNumberOfItemsInSection ( this . nativeViewProtected , 0 ) > maxMinIndex ) {
@@ -480,7 +464,7 @@ export class Pager extends PagerBase {
480
464
}
481
465
482
466
@profile
483
- public refresh ( ) {
467
+ public refresh ( delayUpdateScrollPosition = false ) {
484
468
if ( ! this . isLoaded || ! this . nativeView ) {
485
469
this . _isDataDirty = true ;
486
470
return ;
@@ -500,7 +484,13 @@ export class Pager extends PagerBase {
500
484
// dispatch_async(main_queue, () => {
501
485
this . nativeViewProtected . reloadData ( ) ;
502
486
this . nativeViewProtected . collectionViewLayout . invalidateLayout ( ) ;
503
- this . _updateScrollPosition ( ) ;
487
+ if ( delayUpdateScrollPosition ) {
488
+ setTimeout ( ( ) => {
489
+ this . _updateScrollPosition ( ) ;
490
+ } , 0 ) ;
491
+ } else {
492
+ this . _updateScrollPosition ( ) ;
493
+ }
504
494
this . _initAutoPlay ( this . autoPlay ) ;
505
495
// });
506
496
@@ -675,7 +665,7 @@ export class Pager extends PagerBase {
675
665
// this refresh is just to handle size change
676
666
const layoutKey = this . _effectiveItemWidth + '_' + this . _effectiveItemHeight ;
677
667
if ( this . mLastLayoutKey !== layoutKey ) {
678
- this . refresh ( ) ;
668
+ this . refresh ( true ) ;
679
669
}
680
670
}
681
671
@@ -991,12 +981,12 @@ class UICollectionDelegateImpl extends NSObject implements UICollectionViewDeleg
991
981
const contentSize = scrollView . contentSize ;
992
982
const frameSize = scrollView . frame . size ;
993
983
if ( contentOffset . x <= 0 ) {
994
- scrollView . contentOffset = CGPointMake ( contentSize . width - frameSize . width * 2 , 0 ) ;
984
+ scrollView . contentOffset = CGPointMake ( contentSize . width - frameSize . width * 2 + 2 * owner . _getPeaking ( ) , 0 ) ;
995
985
if ( owner . indicator ) {
996
986
owner . indicator . setSelection ( owner . lastIndex , false ) ;
997
987
}
998
988
} else if ( contentOffset . x + frameSize . width >= contentSize . width ) {
999
- scrollView . contentOffset = CGPointMake ( frameSize . width , 0 ) ;
989
+ scrollView . contentOffset = CGPointMake ( frameSize . width - 2 * owner . _getPeaking ( ) , 0 ) ;
1000
990
if ( owner . indicator ) {
1001
991
owner . indicator . setSelection ( 0 , false ) ;
1002
992
}
0 commit comments