MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / _scrollToIndex

Method _scrollToIndex

packages/core/ui/list-view/index.ios.ts:650–668  ·  view source on GitHub ↗
(index: number, animated = true)

Source from the content-addressed store, hash-verified

648 }
649
650 private _scrollToIndex(index: number, animated = true) {
651 if (!this.nativeViewProtected) {
652 return;
653 }
654
655 const itemsLength = this.items ? this.items.length : 0;
656 // mimic Android behavior that silently coerces index values within [0, itemsLength - 1] range
657 if (itemsLength > 0) {
658 if (index < 0) {
659 index = 0;
660 } else if (index >= itemsLength) {
661 index = itemsLength - 1;
662 }
663
664 this.nativeViewProtected.scrollToRowAtIndexPathAtScrollPositionAnimated(NSIndexPath.indexPathForItemInSection(index, 0), UITableViewScrollPosition.Top, animated);
665 } else if (Trace.isEnabled()) {
666 Trace.write(`Cannot scroll listview to index ${index} when listview items not set`, Trace.categories.Binding);
667 }
668 }
669
670 public refresh() {
671 // clear bindingContext when it is not observable because otherwise bindings to items won't reevaluate

Callers 2

scrollToIndexMethod · 0.95
scrollToIndexAnimatedMethod · 0.95

Calls 2

isEnabledMethod · 0.80
writeMethod · 0.65

Tested by

no test coverage detected