diff --git a/ArkUI/entry/src/main/ets/pages/CombiningListItemGroupAndLazyForEach.ets b/ArkUI/entry/src/main/ets/pages/CombiningListItemGroupAndLazyForEach.ets index 0af59e4565f0926fcf0bf0d989711b26eae90ed7..59e1e214124ea5f1d46709d8e51a622dd85fb16c 100644 --- a/ArkUI/entry/src/main/ets/pages/CombiningListItemGroupAndLazyForEach.ets +++ b/ArkUI/entry/src/main/ets/pages/CombiningListItemGroupAndLazyForEach.ets @@ -43,7 +43,7 @@ struct LazyForEachDemo { aboutToAppear() { for (let date = 1; date < ~~(Math.random() * 30) + 3; date++) { - let dayData = new dateListItem(date + ''); + let dayData = new DateListItem(date + ''); for (let index = 1; index < ~~(Math.random() * 100) + 30; index++) { dayData.orderList.pushData(`hello${index}`); } @@ -54,9 +54,9 @@ struct LazyForEachDemo { build() { Column() { List({ space: 20 }) { - LazyForEach(this.list, (item: dateListItem) => { + LazyForEach(this.list, (item: DateListItem) => { ListItemGroup({ header: this.itemHead(item.date + ''), footer: this.itemFoot(item.orderList.totalCount()) }) { - LazyForEach(item.orderList, (order: string, ) => { + LazyForEach(item.orderList, (order: string,) => { ListItem() { Text(order) .width('100%') @@ -91,7 +91,7 @@ class BasicDataSource implements IDataSource { return 0; } - public getData(index: number): string | dateListItem { + public getData(index: number): string | DateListItem { return this.originDataArray[index]; } @@ -157,28 +157,28 @@ class MyDataSource1 extends BasicDataSource { class MyDataSource2 extends BasicDataSource { - private dataArray: dateListItem[] = []; + private dataArray: DateListItem[] = []; public totalCount(): number { return this.dataArray.length; } - public getData(index: number): dateListItem { + public getData(index: number): DateListItem { return this.dataArray[index]; } - public addData(index: number, data: dateListItem): void { + public addData(index: number, data: DateListItem): void { this.dataArray.splice(index, 0, data); this.notifyDataAdd(index); } - public pushData(data: dateListItem): void { + public pushData(data: DateListItem): void { this.dataArray.push(data); this.notifyDataAdd(this.dataArray.length - 1); } } -class dateListItem { +class DateListItem { date: string; orderList: MyDataSource1; @@ -187,4 +187,5 @@ class dateListItem { this.orderList = new MyDataSource1(); } } + // [End combining_istItemGroup_and_lazyForEach] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/DoubleNestedListsWork.ets b/ArkUI/entry/src/main/ets/pages/DoubleNestedListsWork.ets index fe465edfac4fd5f55615b944cdda7527b9ea2f3f..b2ac271517e5282cbd50b1304bddc3269e36b6c4 100644 --- a/ArkUI/entry/src/main/ets/pages/DoubleNestedListsWork.ets +++ b/ArkUI/entry/src/main/ets/pages/DoubleNestedListsWork.ets @@ -22,7 +22,6 @@ export class BaseDataSource implements IDataSource { private readonly listeners: DataChangeListener[] = []; protected dataset: T[]; - constructor(dataset?: T[]) { this.dataset = dataset ?? []; } @@ -131,28 +130,22 @@ export class BaseDataSource implements IDataSource { } - - class NewPosItemDataSource extends BaseDataSource { private dataArray: string[] = []; - public totalCount(): number { return this.dataArray.length; } - public getData(index: number): string { return this.dataArray[index]; } - public addData(index: number, data: string): void { this.dataArray.splice(index, 0, data); this.notifyDataAdd(index); } - public pushData(data: string): void { this.dataArray.push(data); this.notifyDataAdd(this.dataArray.length - 1); @@ -168,7 +161,6 @@ const rowHeight = 60; struct header { title: string = ''; - build() { Column() { Text(this.title) @@ -184,11 +176,10 @@ struct header { @Component -struct Itemcomponent { +struct ItemComponent { title: string = ''; @Prop datas: string[]; - generateDataSource() { let datasource: NewPosItemDataSource = new NewPosItemDataSource(); for (let index = 0; index < this.datas.length; index++) { @@ -198,7 +189,6 @@ struct Itemcomponent { return datasource; } - build() { Column() { header({ title: this.title }) @@ -214,7 +204,7 @@ struct Itemcomponent { } .height(rowHeight) }, (data: string, index) => { - console.log(`------- ${data + ' - ' + index.toString()}`); + console.info(`------- ${data + ' - ' + index.toString()}`); return data + ' - ' + index.toString(); }) } @@ -244,18 +234,17 @@ struct Index { @State message: string = 'Hello World'; private scroll: Scroller = new Scroller(); - @Builder private mainListView() { List({ scroller: this.scroll }) { ListItem() { - Itemcomponent({ title: 'A', datas: generateData('A', 200) }) + ItemComponent({ title: 'A', datas: generateData('A', 200) }) } // .height(40 + 200 * rowHeight) // After adding the height attribute, the content area of the inner list will be as high as the visible area, causing LazyForEach to become invalid ListItem() { - Itemcomponent({ title: 'B', datas: generateData('B', 20) }) + ItemComponent({ title: 'B', datas: generateData('B', 20) }) } // .height(40 + 20 * rowHeight) // After adding the height attribute, the content area of the inner list will be as high as the visible area, causing LazyForEach to become invalid } @@ -266,7 +255,6 @@ struct Index { .edgeEffect(EdgeEffect.None) } - build() { Column() { this.mainListView() @@ -275,4 +263,5 @@ struct Index { .backgroundColor(Color.White) } } + // [End double_nested_lists_work] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/MonitorFrontAndBackOfApplication.ets b/ArkUI/entry/src/main/ets/pages/MonitorFrontAndBackOfApplication.ets index 6a211145f0348d33b85b82cec4f2b3e41f4b9430..a41faf9accb371468fa7dfca7179c4264c68cf18 100644 --- a/ArkUI/entry/src/main/ets/pages/MonitorFrontAndBackOfApplication.ets +++ b/ArkUI/entry/src/main/ets/pages/MonitorFrontAndBackOfApplication.ets @@ -49,16 +49,17 @@ struct Vid { .fontWeight(FontWeight.Bold) .onClick(() => { this.message += this.isOnForeground; - console.log('' + this.isOnForeground); + console.info('' + this.isOnForeground); }) } change() { if (this.isOnForeground) { - console.log('The component is on foreground.'); + console.info('The component is on foreground.'); } else { - console.log('The component is on background.'); + console.info('The component is on background.'); } } } + // [End monitor_front_and_back_of_application] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/ReusingListItemGroupAndLazyForEachComponents.ets b/ArkUI/entry/src/main/ets/pages/ReusingListItemGroupAndLazyForEachComponents.ets index d58aa8607c3f5e1cf4450fe80375ea5521781514..aae7d6a9d60bf8406ca20c9311673db46ad479ae 100644 --- a/ArkUI/entry/src/main/ets/pages/ReusingListItemGroupAndLazyForEachComponents.ets +++ b/ArkUI/entry/src/main/ets/pages/ReusingListItemGroupAndLazyForEachComponents.ets @@ -23,7 +23,6 @@ struct ListItemGroupAndReusable { data: DataSrc2 = new DataSrc2(); - @Builder itemHead(text: string) { Text(text) @@ -33,7 +32,6 @@ struct ListItemGroupAndReusable { .padding(10) } - aboutToAppear() { for (let i = 0; i < 10000; i++) { let data_1 = new DataSrc1(); @@ -44,7 +42,6 @@ struct ListItemGroupAndReusable { } } - build() { Stack() { List() { @@ -70,14 +67,12 @@ struct ListItemGroupAndReusable { @Reusable @Component struct Inner { - @State str: string = '' - + @State str: string = ''; aboutToReuse(param: ESObject) { this.str = param.str; } - build() { Text(this.str) } @@ -88,17 +83,14 @@ class DataSrc1 implements IDataSource { listeners: DataChangeListener[] = []; Data: string[] = []; - public totalCount(): number { return this.Data.length; } - public getData(index: number): string { return this.Data[index]; } - // This method is called on the framework side to add listener listening to the LazyForEach component at its data source registerDataChangeListener(listener: DataChangeListener): void { if (this.listeners.indexOf(listener) < 0) { @@ -106,7 +98,6 @@ class DataSrc1 implements IDataSource { } } - // This method is called on the framework side to remove listener listening for the corresponding LazyForEach component at the data source unregisterDataChangeListener(listener: DataChangeListener): void { const pos = this.listeners.indexOf(listener); @@ -115,7 +106,6 @@ class DataSrc1 implements IDataSource { } } - // Notify LazyForEach component to reload all child components notifyDataReload(): void { this.listeners.forEach(listener => { @@ -123,7 +113,6 @@ class DataSrc1 implements IDataSource { }) } - // Notify LazyForEach component to add a sub component at the index corresponding to the index notifyDataAdd(index: number): void { this.listeners.forEach(listener => { @@ -131,7 +120,6 @@ class DataSrc1 implements IDataSource { }) } - // Notify LazyForEach component that there is a change in data at the index corresponding to the index, and that the sub component needs to be rebuilt notifyDataChange(index: number): void { this.listeners.forEach(listener => { @@ -139,7 +127,6 @@ class DataSrc1 implements IDataSource { }) } - // Notify LazyForEach component to remove the sub component at the index corresponding to the index notifyDataDelete(index: number): void { this.listeners.forEach(listener => { @@ -147,7 +134,6 @@ class DataSrc1 implements IDataSource { }) } - // Notify LazyForEach component to swap the subcomponents at the from index and to index notifyDataMove(from: number, to: number): void { this.listeners.forEach(listener => { @@ -161,17 +147,14 @@ class DataSrc2 implements IDataSource { listeners: DataChangeListener[] = []; Data: DataSrc1[] = []; - public totalCount(): number { return this.Data.length; } - public getData(index: number): DataSrc1 { return this.Data[index]; } - // This method is called on the framework side to add listener listening to the LazyForEach component at its data source registerDataChangeListener(listener: DataChangeListener): void { if (this.listeners.indexOf(listener) < 0) { @@ -179,7 +162,6 @@ class DataSrc2 implements IDataSource { } } - // This method is called on the framework side to remove listener listening for the corresponding LazyForEach component at the data source unregisterDataChangeListener(listener: DataChangeListener): void { const pos = this.listeners.indexOf(listener); @@ -188,7 +170,6 @@ class DataSrc2 implements IDataSource { } } - // Notify LazyForEach component to reload all child components notifyDataReload(): void { this.listeners.forEach(listener => { @@ -196,7 +177,6 @@ class DataSrc2 implements IDataSource { }) } - // Notify LazyForEach component to add a sub component at the index corresponding to the index notifyDataAdd(index: number): void { this.listeners.forEach(listener => { @@ -204,7 +184,6 @@ class DataSrc2 implements IDataSource { }) } - // Notify LazyForEach component that there is a change in data at the index corresponding to the index, and that the sub component needs to be rebuilt notifyDataChange(index: number): void { this.listeners.forEach(listener => { @@ -212,7 +191,6 @@ class DataSrc2 implements IDataSource { }) } - // Notify LazyForEach component to remove the sub component at the index corresponding to the index notifyDataDelete(index: number): void { this.listeners.forEach(listener => { @@ -220,7 +198,6 @@ class DataSrc2 implements IDataSource { }) } - // Notify LazyForEach component to swap the subcomponents at the from index and to index notifyDataMove(from: number, to: number): void { this.listeners.forEach(listener => { @@ -228,4 +205,5 @@ class DataSrc2 implements IDataSource { }) } } + // [End reusing_listItemGroup_and_lazyForEach_components] \ No newline at end of file