Skip to content

Commit efeef7f

Browse files
committed
fix(ios): circularMode fixes
1 parent 1badfc3 commit efeef7f

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

src/ui-pager/index.ios.ts

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -242,26 +242,19 @@ export class Pager extends PagerBase {
242242
}
243243

244244
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);
249246
}
250247

251248
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);
257250
}
258251

259252
get lastDummy(): number {
260253
return this.lastIndex;
261254
}
262255

263256
public get _childrenCount() {
264-
return this.items?.length || this._childrenViews?.length || 0;
257+
return this.items?.length ?? this._childrenViews?.length ?? 0;
265258
}
266259

267260
public itemTemplateUpdated(oldData: any, newData: any): void {}
@@ -450,18 +443,9 @@ export class Pager extends PagerBase {
450443
return;
451444
}
452445
const maxMinIndex = Math.min(Math.max(0, index), this._childrenCount - 1);
453-
if (!this.isLoaded) {
454-
return selectedIndexProperty.nativeValueChange(this, maxMinIndex);
455-
}
456446
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);
465449
}
466450
// dispatch_async(main_queue, () => {
467451
if (this.mDataSource.collectionViewNumberOfItemsInSection(this.nativeViewProtected, 0) > maxMinIndex) {
@@ -480,7 +464,7 @@ export class Pager extends PagerBase {
480464
}
481465

482466
@profile
483-
public refresh() {
467+
public refresh(delayUpdateScrollPosition = false) {
484468
if (!this.isLoaded || !this.nativeView) {
485469
this._isDataDirty = true;
486470
return;
@@ -500,7 +484,13 @@ export class Pager extends PagerBase {
500484
// dispatch_async(main_queue, () => {
501485
this.nativeViewProtected.reloadData();
502486
this.nativeViewProtected.collectionViewLayout.invalidateLayout();
503-
this._updateScrollPosition();
487+
if (delayUpdateScrollPosition) {
488+
setTimeout(() => {
489+
this._updateScrollPosition();
490+
}, 0);
491+
} else {
492+
this._updateScrollPosition();
493+
}
504494
this._initAutoPlay(this.autoPlay);
505495
// });
506496

@@ -675,7 +665,7 @@ export class Pager extends PagerBase {
675665
// this refresh is just to handle size change
676666
const layoutKey = this._effectiveItemWidth + '_' + this._effectiveItemHeight;
677667
if (this.mLastLayoutKey !== layoutKey) {
678-
this.refresh();
668+
this.refresh(true);
679669
}
680670
}
681671

@@ -991,12 +981,12 @@ class UICollectionDelegateImpl extends NSObject implements UICollectionViewDeleg
991981
const contentSize = scrollView.contentSize;
992982
const frameSize = scrollView.frame.size;
993983
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);
995985
if (owner.indicator) {
996986
owner.indicator.setSelection(owner.lastIndex, false);
997987
}
998988
} 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);
1000990
if (owner.indicator) {
1001991
owner.indicator.setSelection(0, false);
1002992
}

0 commit comments

Comments
 (0)