1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { 17 Entry, 18 ComponentV2, 19 Local, 20 Scroller, 21 Column, 22 List, 23 Repeat, 24 RepeatItem, 25 ListItem, 26 Row, 27 Text, 28 Button, 29} from '@kit.ArkUI'; 30 31@Entry 32@ComponentV2 33struct MyComponent { 34 @Local arr: Array<string> = []; 35 scroller: Scroller = new Scroller(); 36 build() { 37 Column({ space: 5.0 }) { 38 List({ scroller: this.scroller, space: 5.0, initialIndex: 100.0 }) { 39 Repeat(this.arr) 40 .virtualScroll({ 41 onTotalCount: () => { return 1000.0; }, 42 onLazyLoading: (index: number) => { this.arr[index as int] = index.toString(); } 43 }) 44 .each((obj: RepeatItem<string>) => { 45 ListItem() { 46 Row({ space: 5.0 }) { 47 Text(`${obj.index}: Item_${obj.item}`) 48 } 49 } 50 .height(50.0) 51 }) 52 } 53 .height('80%') 54 .border({ width: 1.0}) 55 Button('ScrollToIndex 500') 56 .onClick(() => { this.scroller.scrollToIndex(500.0); }) 57 } 58 } 59}