diff --git a/ComponentReuse/negative/build-profile.json5 b/ComponentReuse/negative/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6bd6457a2fed846cc10698666fa1268219f1bee1 --- /dev/null +++ b/ComponentReuse/negative/build-profile.json5 @@ -0,0 +1,33 @@ +{ + "apiType": "stageMode", + "buildOption": { + "resOptions": { + "copyCodeResource": { + "enable": false + } + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/ComponentReuse/negative/oh-package.json5 b/ComponentReuse/negative/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3c409fae6359c99d9e16e6933be27125bd4a0c6d --- /dev/null +++ b/ComponentReuse/negative/oh-package.json5 @@ -0,0 +1,10 @@ +{ + "name": "negative", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/ComponentReuse/negative/src/main/ets/common/CommonConstants.ets b/ComponentReuse/negative/src/main/ets/common/CommonConstants.ets new file mode 100644 index 0000000000000000000000000000000000000000..ea750ff3d4bc1e2a90d6c02d065f956baf4f3ee1 --- /dev/null +++ b/ComponentReuse/negative/src/main/ets/common/CommonConstants.ets @@ -0,0 +1,9 @@ +export class CommonConstants { + static readonly Full_WIDTH: string = '100%'; + static readonly Full_HIIGHT: string = '100%'; + static readonly INDEX_CONTENT_WIDTH: string = '91.1%'; + static readonly DIVIDER_HEIGHT: number = 0.5; + static readonly DIVIDER_WIDTH: string = '93%'; + static readonly INDEX_TITLE_HEIGHT: number = 112; + static readonly LIST_CONTENT_HEIGHT: string = '110%'; +} \ No newline at end of file diff --git a/ComponentReuse/negative/src/main/ets/common/CustomRoutes.ets b/ComponentReuse/negative/src/main/ets/common/CustomRoutes.ets new file mode 100644 index 0000000000000000000000000000000000000000..10c501a284879cb669cc4fff93a19fd47e160d85 --- /dev/null +++ b/ComponentReuse/negative/src/main/ets/common/CustomRoutes.ets @@ -0,0 +1,52 @@ +export class CustomRoutes { + static readonly ROUTES: Route[] = [ + { + title: '未使用组件复用', + child: [ + { text: '场景1', title: '"总-分式"简单结构', to: 'NoReuseSence1' }, + { text: '场景1', title: '"总-分式"简单结构', to: 'NoReuseSence2' }, + { text: '场景1', title: '"总-分式"简单结构', to: 'NoReuseSence3' }, + { text: '场景1', title: '"总-分式"简单结构', to: 'NoReuseSence4' } + ] + }, + { + title: '未使用组件复用', + child: [ + { text: '场景1', title: '"总-分式"简单结构', to: 'NoReuseSence1' }, + { text: '场景1', title: '"总-分式"简单结构', to: 'NoReuseSence1' }, + { text: '场景1', title: '"总-分式"简单结构', to: 'NoReuseSence1' }, + { text: '场景1', title: '"总-分式"简单结构', to: 'NoReuseSence1' } + ] + }, + { + title: '未使用组件复用', + child: [ + { text: '场景1', title: '"总-分式"简单结构', to: 'NoReuseSence1' }, + { text: '场景1', title: '"总-分式"简单结构', to: 'NoReuseSence1' }, + { text: '场景1', title: '"总-分式"简单结构', to: 'NoReuseSence1' }, + { text: '场景1', title: '"总-分式"简单结构', to: 'NoReuseSence1' } + ] + }, + { + title: '未使用组件复用', + child: [ + { text: '场景1', title: '"总-分式"简单结构', to: 'NoReuseSence1' }, + { text: '场景1', title: '"总-分式"简单结构', to: 'NoReuseSence1' }, + { text: '场景1', title: '"总-分式"简单结构', to: 'NoReuseSence1' }, + { text: '场景1', title: '"总-分式"简单结构', to: 'NoReuseSence1' } + ] + } + ] +} + +export interface Route { + title: string | Resource; + child: Array; +} + +export interface ChildRoute { + text: string | Resource; + title?: string | Resource | null; + description?: string; + to: string; +} \ No newline at end of file diff --git a/ComponentReuse/negative/src/main/ets/common/MockData.ets b/ComponentReuse/negative/src/main/ets/common/MockData.ets new file mode 100644 index 0000000000000000000000000000000000000000..8e0a668e5ea427987d431575ec7f3dfcbb2df81e --- /dev/null +++ b/ComponentReuse/negative/src/main/ets/common/MockData.ets @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ItemData } from '../model/ItemData'; + +export const TAB_TITLES: string[] = ['News', 'Hot', 'Video', 'Tech', 'Travel']; + +const NEWS_TITLES: string[] = + ['Embark on the journey of integrating intelligence and innovation, join hands to build a new generation of demonstration cities, collaborate on creation, provide new solutions, and create a new era', + 'In the era of data awakening, redefining data storage', + 'High end all flash memory won the top recommendation on annual storage data list, ranking first in the recommendation list', + 'Deeply integrating new technologies with the aviation industry, based on cloud, data, and intelligence as the core of the digital base, jointly cooperating to create solutions to help aviation efficiency', + 'Innovation leads, with actions and words, to jointly build new high-quality communication and new development', + 'To jointly build new high-quality communication and new development']; + +const NEWS_FROMS: string[] = ['Comment', 'News', 'Discuss']; + +let imageArray: Resource[] = [$r("app.media.img0"), $r("app.media.img1"), + $r("app.media.img2"), $r("app.media.img3"), $r("app.media.img4"), $r("app.media.img5")]; + +let PREVIEW_IMAGES: Resource[] = [$r("app.media.img6"), $r("app.media.img7"), + $r("app.media.img8")]; + +export function genMockItemData(size: number): ItemData[] { + const res: ItemData[] = []; + for (let i = 0; i < size; i++) { + const data = new ItemData('' + i, i % 3); + data.title = NEWS_TITLES[Math.floor(Math.random() * NEWS_TITLES.length)]; + data.from = NEWS_FROMS[Math.floor(Math.random() * NEWS_FROMS.length)]; + data.tail = '15 minutes ago'; + imageArray = shuffleArray(imageArray); + data.pics = imageArray; + data.preview = PREVIEW_IMAGES[Math.floor(Math.random() * PREVIEW_IMAGES.length)]; + data.duration = '03:12'; + res.push(data); + } + return res; +} + +function shuffleArray(array: T[]): T[] { + const shuffled = [...array]; + for (let i = shuffled.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + const tmp = shuffled[i]; + shuffled[i] = shuffled[j]; + shuffled[j] = tmp; + } + return shuffled; +} diff --git a/ComponentReuse/negative/src/main/ets/common/MockDataV2.ets b/ComponentReuse/negative/src/main/ets/common/MockDataV2.ets new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/ComponentReuse/negative/src/main/ets/common/TestCount.ets b/ComponentReuse/negative/src/main/ets/common/TestCount.ets new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/ComponentReuse/negative/src/main/ets/model/ItemData.ets b/ComponentReuse/negative/src/main/ets/model/ItemData.ets new file mode 100644 index 0000000000000000000000000000000000000000..113eccbd7bde15caefdabb51720ec150931bf0a4 --- /dev/null +++ b/ComponentReuse/negative/src/main/ets/model/ItemData.ets @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@Observed +export class ItemData { + id: string = ''; + title: string | Resource = ''; + content: string = ''; + from: string | Resource = ''; + tail: string | Resource = ''; + type: number = 0; + pics: Resource[] = []; + preview: Resource | string = ''; + duration: string = ''; + + constructor(id: string, type: number) { + this.id = id; + this.type = type; + } +} \ No newline at end of file diff --git a/ComponentReuse/negative/src/main/ets/model/ItemDataSource.ets b/ComponentReuse/negative/src/main/ets/model/ItemDataSource.ets new file mode 100644 index 0000000000000000000000000000000000000000..0056109375c97c16fa7075b877c94013a6d7fa4a --- /dev/null +++ b/ComponentReuse/negative/src/main/ets/model/ItemDataSource.ets @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ItemData } from './ItemData'; + +export class ItemDataSource implements IDataSource { + private listeners: DataChangeListener[] = []; + private originDataArray: ItemData[] = []; + + public totalCount(): number { + return this.originDataArray.length; + } + + public getData(index: number): ItemData { + return this.originDataArray[index]; + } + + registerDataChangeListener(listener: DataChangeListener): void { + if (this.listeners.indexOf(listener) < 0) { + this.listeners.push(listener); + } + } + + unregisterDataChangeListener(listener: DataChangeListener): void { + const pos = this.listeners.indexOf(listener); + if (pos >= 0) { + this.listeners.splice(pos, 1); + } + } + + notifyDataReload(): void { + this.listeners.forEach(listener => { + listener.onDataReloaded(); + }); + } + + notifyDataAdd(index: number): void { + this.listeners.forEach(listener => { + listener.onDataAdd(index); + }); + } + + notifyDataChange(index: number): void { + this.listeners.forEach(listener => { + listener.onDataChange(index); + }); + } + + notifyDataDelete(index: number): void { + this.listeners.forEach(listener => { + listener.onDataDelete(index); + }); + } + + notifyDataMove(from: number, to: number): void { + this.listeners.forEach(listener => { + listener.onDataMove(from, to); + }); + } + + notifyDatasetChange(operations: DataOperation[]): void { + this.listeners.forEach(listener => { + listener.onDatasetChange(operations); + }); + } + + public pushArray(newData: ItemData[]): void { + this.originDataArray.push(...newData); + this.notifyDataReload(); + } + + public addItems(items: ItemData[]) { + this.originDataArray.push(...items); + this.notifyDataReload(); + } + + public add1stItem(item: ItemData): void { + this.originDataArray.splice(0, 0, item); + this.notifyDataAdd(0); + } + + public addLastItem(item: ItemData): void { + this.originDataArray.splice(this.originDataArray.length, 0, item); + this.notifyDataAdd(this.originDataArray.length - 1); + } + + public addItem(index: number, item: ItemData): void { + this.originDataArray.splice(index, 0, item); + this.notifyDataAdd(index); + } + + public delete1stItem(): void { + this.originDataArray.splice(0, 1); + this.notifyDataDelete(0); + } + + public delete2ndItem(): void { + this.originDataArray.splice(1, 1); + this.notifyDataDelete(1); + } + + public deleteLastItem(): void { + this.originDataArray.splice(-1, 1); + this.notifyDataDelete(this.originDataArray.length); + } + + public reload() { + this.originDataArray.splice(1, 1); + this.originDataArray.splice(3, 2); + this.reload(); + } +} \ No newline at end of file diff --git a/ComponentReuse/negative/src/main/ets/model/TitleDataSource.ets b/ComponentReuse/negative/src/main/ets/model/TitleDataSource.ets new file mode 100644 index 0000000000000000000000000000000000000000..d37993baa67ef5cbe2331a50ded9a41334922b00 --- /dev/null +++ b/ComponentReuse/negative/src/main/ets/model/TitleDataSource.ets @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export class TitleDataSource implements IDataSource { + private listeners: DataChangeListener[] = []; + private originDataArray: string[] = []; + + totalCount(): number { + return this.originDataArray.length; + } + + getData(index: number): string { + return this.originDataArray[index]; + } + + public addItem(title: string): void { + this.originDataArray.push(title); + this.notifyDataAdd(this.originDataArray.length - 1); + } + + notifyDataAdd(index: number): void { + this.listeners.forEach(listener => { + listener.onDataAdd(index); + }) + } + + registerDataChangeListener(listener: DataChangeListener): void { + if (this.listeners.indexOf(listener) < 0) { + this.listeners.push(listener); + } + } + + unregisterDataChangeListener(listener: DataChangeListener): void { + const pos = this.listeners.indexOf(listener); + if (pos > 0) { + this.listeners.splice(pos, 1); + } + } +} \ No newline at end of file diff --git a/ComponentReuse/negative/src/main/ets/negativeability/NegativeAbility.ets b/ComponentReuse/negative/src/main/ets/negativeability/NegativeAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..378c80689b73b5c93437f136dddc27ad5311f0be --- /dev/null +++ b/ComponentReuse/negative/src/main/ets/negativeability/NegativeAbility.ets @@ -0,0 +1,43 @@ +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class NegativeAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/ComponentReuse/negative/src/main/ets/pages/ImproperReuseOfComponentsScene1.ets b/ComponentReuse/negative/src/main/ets/pages/ImproperReuseOfComponentsScene1.ets new file mode 100644 index 0000000000000000000000000000000000000000..68ab04d8b5c808682d18638bf9c8eff40a14f19a --- /dev/null +++ b/ComponentReuse/negative/src/main/ets/pages/ImproperReuseOfComponentsScene1.ets @@ -0,0 +1,139 @@ +import { ItemDataSource } from '../model/ItemDataSource'; +import { ItemData } from '../model/ItemData'; +import { genMockItemData } from '../common/MockData'; + +function count() { + for (let index = 0; index < 10000; index++) { + console.debug('fun index:' + index); + } +} + +@Builder +function buildImproperReuseOfComponentsScene1() { + ImproperReuseOfComponentsScene1() +} + +// 父组件未使用复用,子组件使用复用 +@Component +struct ImproperReuseOfComponentsScene1 { + private dataSource: ItemDataSource = new ItemDataSource(); + + aboutToAppear(): void { + this.dataSource.pushArray(genMockItemData(1000)); + } + + build() { + NavDestination() { + Column() { + List() { + LazyForEach(this.dataSource, (item: ItemData) => { + ListItem() { + NewsContent({ item: item }) + } + }, (item: ItemData) => item.id.toString()) + } + .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM]) + .cachedCount(1) + .width('100%') + .height('100%') + } + .width('100%') + .height('100%') + } + } +} + +@Component +struct NewsContent { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + @Builder + myBuilder(item: ItemData) { + TopView({ item: item }) + MiddleSingleImageView({ item: item }) + BottomView({ item: item }) + } + + build() { + Column() { + this.myBuilder(this.item) + } + .alignItems(HorizontalAlign.Start) + .padding({ + top: 16, + bottom: 12, + left: 16, + right: 16 + }) + .margin({ + top: 12, + left: 16, + right: 16 + }) + .borderRadius(12) + .backgroundColor(Color.White) + } +} + +@Reusable +@Component +struct TopView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Text(this.item.title) + .fontSize(16) + .fontWeight(FontWeight.Medium) + .fontColor(Color.Black) + .maxLines(2) + .lineHeight(22) + .opacity(0.9) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .width('100%') + } +} + +@Reusable +@Component +struct BottomView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Text(this.item.tail) + .fontSize(12) + .opacity(0.4) + .fontWeight(FontWeight.Regular) + .margin({ left: 6, top: 12 }) + .width('100%') + } +} + +@Reusable +@Component +struct MiddleSingleImageView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Image(this.item.preview) + .width(158) + .height(96) + .borderRadius(8) + .margin({ top: 8 }) + } +} \ No newline at end of file diff --git a/ComponentReuse/negative/src/main/ets/pages/ImproperReuseOfComponentsScene2.ets b/ComponentReuse/negative/src/main/ets/pages/ImproperReuseOfComponentsScene2.ets new file mode 100644 index 0000000000000000000000000000000000000000..e370ac236772b2c5c6eb3c16abc4cd4f60da9785 --- /dev/null +++ b/ComponentReuse/negative/src/main/ets/pages/ImproperReuseOfComponentsScene2.ets @@ -0,0 +1,140 @@ +import { ItemDataSource } from '../model/ItemDataSource'; +import { ItemData } from '../model/ItemData'; +import { genMockItemData } from '../common/MockData'; + +function count() { + for (let index = 0; index < 10000; index++) { + console.debug('fun index:' + index); + } +} + +@Builder +function buildImproperReuseOfComponentsScene2() { + ImproperReuseOfComponentsScene2() +} + +// 复用嵌套 +@Component +struct ImproperReuseOfComponentsScene2 { + private dataSource: ItemDataSource = new ItemDataSource(); + + aboutToAppear(): void { + this.dataSource.pushArray(genMockItemData(1000)); + } + + build() { + NavDestination() { + Column() { + List() { + LazyForEach(this.dataSource, (item: ItemData) => { + ListItem() { + NewsContent({ item: item }) + } + }, (item: ItemData) => item.id.toString()) + } + .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM]) + .cachedCount(1) + .width('100%') + .height('100%') + } + .width('100%') + .height('100%') + } + } +} + +@Reusable +@Component +struct NewsContent { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + @Builder + myBuilder(item: ItemData) { + TopView({ item: item }) + MiddleSingleImageView({ item: item }) + BottomView({ item: item }) + } + + build() { + Column() { + this.myBuilder(this.item) + } + .alignItems(HorizontalAlign.Start) + .padding({ + top: 16, + bottom: 12, + left: 16, + right: 16 + }) + .margin({ + top: 12, + left: 16, + right: 16 + }) + .borderRadius(12) + .backgroundColor(Color.White) + } +} + +@Reusable +@Component +struct TopView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Text(this.item.title) + .fontSize(16) + .fontWeight(FontWeight.Medium) + .fontColor(Color.Black) + .maxLines(2) + .lineHeight(22) + .opacity(0.9) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .width('100%') + } +} + +@Reusable +@Component +struct BottomView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Text(this.item.tail) + .fontSize(12) + .opacity(0.4) + .fontWeight(FontWeight.Regular) + .margin({ left: 6, top: 12 }) + .width('100%') + } +} + +@Reusable +@Component +struct MiddleSingleImageView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Image(this.item.preview) + .width(158) + .height(96) + .borderRadius(8) + .margin({ top: 8 }) + } +} \ No newline at end of file diff --git a/ComponentReuse/negative/src/main/ets/pages/ImproperReuseOfComponentsScene3.ets b/ComponentReuse/negative/src/main/ets/pages/ImproperReuseOfComponentsScene3.ets new file mode 100644 index 0000000000000000000000000000000000000000..211643f8d64af6da625cc76911061e0c5b455e7d --- /dev/null +++ b/ComponentReuse/negative/src/main/ets/pages/ImproperReuseOfComponentsScene3.ets @@ -0,0 +1,203 @@ +import { ItemDataSource } from '../model/ItemDataSource'; +import { ItemData } from '../model/ItemData'; +import { genMockItemData } from '../common/MockData'; + +function count() { + for (let index = 0; index < 10000; index++) { + console.debug('fun index:' + index); + } +} + +@Builder +function buildImproperReuseOfComponentsScene3() { + ImproperReuseOfComponentsScene3() +} + +// reuseId分类过粗 +@Component +struct ImproperReuseOfComponentsScene3 { + private dataSource: ItemDataSource = new ItemDataSource(); + + aboutToAppear(): void { + this.dataSource.pushArray(genMockItemData(1000)); + } + + build() { + NavDestination() { + Column() { + List() { + LazyForEach(this.dataSource, (item: ItemData) => { + ListItem() { + NewsContent({ item: item }) + } + }, (item: ItemData) => item.id.toString()) + } + .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM]) + .cachedCount(1) + .width('100%') + .height('100%') + } + .width('100%') + .height('100%') + } + } +} + +@Reusable +@Component +struct NewsContent { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + @Builder + myBuilder(item: ItemData) { + TopView({ item: item }) + // MiddleSingleImageView({ item: item }) + if (item.type === 0) { + MiddleSingleImageView({ item: item }) + } else if (item.type === 1) { + MiddleThreeImageView({ item: item }) + } else { + MiddleVideoView({ item: item }) + } + BottomView({ item: item }) + } + + build() { + Column() { + this.myBuilder(this.item) + } + .alignItems(HorizontalAlign.Start) + .padding({ + top: 16, + bottom: 12, + left: 16, + right: 16 + }) + .margin({ + top: 12, + left: 16, + right: 16 + }) + .borderRadius(12) + .backgroundColor(Color.White) + } +} + +@Component +struct TopView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Text(this.item.title) + .fontSize(16) + .fontWeight(FontWeight.Medium) + .fontColor(Color.Black) + .maxLines(2) + .lineHeight(22) + .opacity(0.9) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .width('100%') + } +} + +@Component +struct BottomView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Text(this.item.tail) + .fontSize(12) + .opacity(0.4) + .fontWeight(FontWeight.Regular) + .margin({ left: 6, top: 12 }) + .width('100%') + } +} + +@Component +struct MiddleSingleImageView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Image(this.item.preview) + .width(158) + .height(96) + .borderRadius(8) + .margin({ top: 8 }) + } +} + +@Component +struct MiddleThreeImageView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Row() { + Image(this.item.pics[0]) + .layoutWeight(1) + .height(98) + .borderRadius({ topLeft: 8, bottomLeft: 8 }) + Divider().width(2) + Image(this.item.pics[1]) + .layoutWeight(1) + .height(98) + .borderRadius({ topLeft: 8, bottomLeft: 8 }) + Divider().width(2) + Image(this.item.pics[2]) + .layoutWeight(1) + .height(98) + .borderRadius({ topLeft: 8, bottomLeft: 8 }) + } + .margin({ top: 8 }) + } +} + +@Component +struct MiddleVideoView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Stack() { + Image(this.item.preview) + .width(112) + .height(112) + .borderRadius(8) + .margin({ top: 8 }) + + Row() { + Image($r('app.media.play_fill')) + .width(12).height(12) + Text(this.item.duration) + .fontColor(Color.White) + .fontSize(11) + .margin({ left: 2 }) + .fontWeight(FontWeight.Medium) + } + .margin(6) + } + } +} \ No newline at end of file diff --git a/ComponentReuse/negative/src/main/ets/pages/Index.ets b/ComponentReuse/negative/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..52045a82adf6f8f0cd3b289bef69a8e5c892b396 --- /dev/null +++ b/ComponentReuse/negative/src/main/ets/pages/Index.ets @@ -0,0 +1,111 @@ +import { CustomRoutes, Route, ChildRoute } from '../common/CustomRoutes'; +import { CommonConstants } from '../common/CommonConstants'; + +@Entry +@Component +struct Index { + private routes: Route[] = CustomRoutes.ROUTES; + pathStack: NavPathStack = new NavPathStack(); + + @Builder + buildList() { + ForEach(this.routes, (item: Route) => { + Row() { + Text(item.title) + .width(CommonConstants.INDEX_CONTENT_WIDTH) + .fontSize(18) + .fontColor(Color.Black) + } + .height(20) + + Column() { + ForEach(item.child, (itemChild: ChildRoute, index: number) => { + Column() { + Row() { + Text(itemChild.text) + .height(48) + .fontWeight(FontWeight.Medium) + .padding({ left: 12 }) + .fontSize(16) + .fontColor($r('app.color.black_E6')) + Column().layoutWeight(1) + + Text(itemChild.title ?? '') + .height(48) + .textAlign(TextAlign.End) + .fontWeight(FontWeight.Normal) + .fontSize(14) + .fontColor($r('app.color.black_99')) + + Image($r('app.media.app_icon')) + .width(24) + .height(24) + .margin({ right: 8 }) + .fillColor($r('app.color.black_33')) + } + .justifyContent(FlexAlign.Start) + .alignItems(VerticalAlign.Center) + + Text(itemChild.description) + .fontWeight(FontWeight.Medium) + .fontColor($r('app.color.gray_3')) + .padding({ + left: 12, + right: 12, + bottom: (itemChild.description ?? '').length > 0 ? 10 : 0 + }) + .fontSize(12) + + Stack() { + if (item.child.length - 1 !== index) { + Row() + .backgroundColor($r('app.color.gray_6')) + .width(CommonConstants.DIVIDER_WIDTH) + .height(CommonConstants.DIVIDER_HEIGHT) + } + } + } + .onClick(() => { + this.pathStack.pushPathByName(itemChild.to, null); + }) + .width(CommonConstants.INDEX_CONTENT_WIDTH) + }, (item: ChildRoute, index: number) => JSON.stringify(item) + index) + } + .margin({ top: 14, bottom: 18 }) + .borderRadius(18) + .backgroundColor(Color.White) + }, (item: Route, index: number) => JSON.stringify(item) + index) + } + + build() { + Navigation(this.pathStack) { + Column() { + Row() { + Text('组件复用使用示例') + .fontWeight(FontWeight.Bold) + .fontSize(30) + .width('100%') + .fontColor('#FF333333') + } + .width(CommonConstants.INDEX_CONTENT_WIDTH) + .height(CommonConstants.INDEX_TITLE_HEIGHT) + + Scroll() { + Column() { + this.buildList() + } + .padding({ bottom: 200 }) + } + .scrollBar(BarState.Off) + .width(CommonConstants.Full_WIDTH) + .scrollable(ScrollDirection.Vertical) + } + .alignItems(HorizontalAlign.Center) + } + .hideNavBar(true) + .backgroundColor('#FFF5F5F5') + .mode(NavigationMode.Stack) + .width(CommonConstants.Full_WIDTH) + .height(CommonConstants.Full_HIIGHT) + } +} \ No newline at end of file diff --git a/ComponentReuse/negative/src/main/ets/pages/NoReuseScene1.ets b/ComponentReuse/negative/src/main/ets/pages/NoReuseScene1.ets new file mode 100644 index 0000000000000000000000000000000000000000..42634dd8d9d4d4bc66a73fbb331033dbef82cc42 --- /dev/null +++ b/ComponentReuse/negative/src/main/ets/pages/NoReuseScene1.ets @@ -0,0 +1,136 @@ +import { ItemDataSource } from '../model/ItemDataSource'; +import { ItemData } from '../model/ItemData'; +import { genMockItemData } from '../common/MockData'; + +function count() { + for (let index = 0; index < 10000; index++) { + console.debug('fun index:' + index); + } +} + +@Builder +function buildNoReuseScene1() { + NoReuseScene1() +} + +// 未使用组件复用:场景1 +@Component +struct NoReuseScene1 { + private dataSource: ItemDataSource = new ItemDataSource(); + + aboutToAppear(): void { + this.dataSource.pushArray(genMockItemData(1000)); + } + + build() { + NavDestination() { + Column() { + List() { + LazyForEach(this.dataSource, (item: ItemData) => { + ListItem() { + NewsContent({ item: item }) + } + }, (item: ItemData) => item.id.toString()) + } + .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM]) + .cachedCount(1) + .width('100%') + .height('100%') + } + .width('100%') + .height('100%') + } + } +} + +@Component +struct NewsContent { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + @Builder + myBuilder(item: ItemData) { + TopView({ item: item }) + MiddleSingleImageView({ item: item }) + BottomView({ item: item }) + } + + build() { + Column() { + this.myBuilder(this.item) + } + .alignItems(HorizontalAlign.Start) + .padding({ + top: 16, + bottom: 12, + left: 16, + right: 16 + }) + .margin({ + top: 12, + left: 16, + right: 16 + }) + .borderRadius(12) + .backgroundColor(Color.White) + } +} + +@Component +struct TopView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Text(this.item.title) + .fontSize(16) + .fontWeight(FontWeight.Medium) + .fontColor(Color.Black) + .maxLines(2) + .lineHeight(22) + .opacity(0.9) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .width('100%') + } +} + +@Component +struct BottomView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Text(this.item.tail) + .fontSize(12) + .opacity(0.4) + .fontWeight(FontWeight.Regular) + .margin({ left: 6, top: 12 }) + .width('100%') + } +} + +@Component +struct MiddleSingleImageView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Image(this.item.preview) + .width(158) + .height(96) + .borderRadius(8) + .margin({ top: 8 }) + } +} \ No newline at end of file diff --git a/ComponentReuse/negative/src/main/ets/pages/NoReuseScene2_StructureOne.ets b/ComponentReuse/negative/src/main/ets/pages/NoReuseScene2_StructureOne.ets new file mode 100644 index 0000000000000000000000000000000000000000..67f930392b5f9f2a3b14d03824ce59fc1411c3a0 --- /dev/null +++ b/ComponentReuse/negative/src/main/ets/pages/NoReuseScene2_StructureOne.ets @@ -0,0 +1,202 @@ +import { ItemDataSource } from '../model/ItemDataSource'; +import { ItemData } from '../model/ItemData'; +import { genMockItemData } from '../common/MockData'; + +function count() { + for (let index = 0; index < 10000; index++) { + console.debug('fun index:' + index); + } +} + +@Builder +function buildNoReuseScene2_StructureOne() { + NoReuseScene2_StructureOne() +} + +// 未使用组件复用:场景2 结构一 +@Component +struct NoReuseScene2_StructureOne { + private dataSource: ItemDataSource = new ItemDataSource(); + + aboutToAppear(): void { + this.dataSource.pushArray(genMockItemData(1000)); + } + + build() { + NavDestination() { + Column() { + List() { + LazyForEach(this.dataSource, (item: ItemData) => { + ListItem() { + NewsContent({ item: item }) + } + }, (item: ItemData) => item.id.toString()) + } + .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM]) + .cachedCount(1) + .width('100%') + .height('100%') + } + .width('100%') + .height('100%') + } + } +} + +@Component +struct NewsContent { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + @Builder + myBuilder(item: ItemData) { + TopView({ item: item }) + // MiddleSingleImageView({ item: item }) + if (item.type === 0) { + MiddleSingleImageView({ item: item }) + } else if (item.type === 1) { + MiddleThreeImageView({ item: item }) + } else { + MiddleVideoView({ item: item }) + } + BottomView({ item: item }) + } + + build() { + Column() { + this.myBuilder(this.item) + } + .alignItems(HorizontalAlign.Start) + .padding({ + top: 16, + bottom: 12, + left: 16, + right: 16 + }) + .margin({ + top: 12, + left: 16, + right: 16 + }) + .borderRadius(12) + .backgroundColor(Color.White) + } +} + +@Component +struct TopView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Text(this.item.title) + .fontSize(16) + .fontWeight(FontWeight.Medium) + .fontColor(Color.Black) + .maxLines(2) + .lineHeight(22) + .opacity(0.9) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .width('100%') + } +} + +@Component +struct BottomView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Text(this.item.tail) + .fontSize(12) + .opacity(0.4) + .fontWeight(FontWeight.Regular) + .margin({ left: 6, top: 12 }) + .width('100%') + } +} + +@Component +struct MiddleSingleImageView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Image(this.item.preview) + .width(158) + .height(96) + .borderRadius(8) + .margin({ top: 8 }) + } +} + +@Component +struct MiddleThreeImageView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Row() { + Image(this.item.pics[0]) + .layoutWeight(1) + .height(98) + .borderRadius({ topLeft: 8, bottomLeft: 8 }) + Divider().width(2) + Image(this.item.pics[1]) + .layoutWeight(1) + .height(98) + .borderRadius({ topLeft: 8, bottomLeft: 8 }) + Divider().width(2) + Image(this.item.pics[2]) + .layoutWeight(1) + .height(98) + .borderRadius({ topLeft: 8, bottomLeft: 8 }) + } + .margin({ top: 8 }) + } +} + +@Component +struct MiddleVideoView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Stack() { + Image(this.item.preview) + .width(112) + .height(112) + .borderRadius(8) + .margin({ top: 8 }) + + Row() { + Image($r('app.media.play_fill')) + .width(12).height(12) + Text(this.item.duration) + .fontColor(Color.White) + .fontSize(11) + .margin({ left: 2 }) + .fontWeight(FontWeight.Medium) + } + .margin(6) + } + } +} \ No newline at end of file diff --git a/ComponentReuse/negative/src/main/ets/pages/NoReuseScene2_StructureTwo.ets b/ComponentReuse/negative/src/main/ets/pages/NoReuseScene2_StructureTwo.ets new file mode 100644 index 0000000000000000000000000000000000000000..007c266e0920c98566345eee67806425ab89e0ed --- /dev/null +++ b/ComponentReuse/negative/src/main/ets/pages/NoReuseScene2_StructureTwo.ets @@ -0,0 +1,273 @@ +import { ItemDataSource } from '../model/ItemDataSource'; +import { ItemData } from '../model/ItemData'; +import { genMockItemData } from '../common/MockData'; + +function count() { + for (let index = 0; index < 10000; index++) { + console.debug('fun index:' + index); + } +} + +@Builder +function buildNoReuseScene2_StructureTwo() { + NoReuseScene2_StructureTwo() +} + +// 未使用组件复用:场景2 结构二 +@Component +struct NoReuseScene2_StructureTwo { + private dataSource: ItemDataSource = new ItemDataSource(); + + aboutToAppear(): void { + this.dataSource.pushArray(genMockItemData(1000)); + } + + build() { + NavDestination() { + Column() { + List() { + LazyForEach(this.dataSource, (item: ItemData) => { + ListItem() { + if (item.type === 0) { + SingleImageNewsContent({ item: item }) + } else if (item.type === 1) { + ThreeImageNewsContent({ item: item }) + } else { + VideoNewsContent({ item: item }) + } + } + }, (item: ItemData) => item.id.toString()) + } + .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM]) + .cachedCount(1) + .width('100%') + .height('100%') + } + .width('100%') + .height('100%') + } + } +} + +@Component +struct SingleImageNewsContent { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + @Builder + myBuilder(item: ItemData) { + TopView({ item: item }) + MiddleSingleImageView({ item: item }) + BottomView({ item: item }) + } + + build() { + Column() { + this.myBuilder(this.item) + } + .alignItems(HorizontalAlign.Start) + .padding({ + top: 16, + bottom: 12, + left: 16, + right: 16 + }) + .margin({ + top: 12, + left: 16, + right: 16 + }) + .borderRadius(12) + .backgroundColor(Color.White) + } +} + +@Component +struct ThreeImageNewsContent { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + @Builder + myBuilder(item: ItemData) { + TopView({ item: item }) + MiddleThreeImageView({ item: item }) + BottomView({ item: item }) + } + + build() { + Column() { + this.myBuilder(this.item) + } + .alignItems(HorizontalAlign.Start) + .padding({ + top: 16, + bottom: 12, + left: 16, + right: 16 + }) + .margin({ + top: 12, + left: 16, + right: 16 + }) + .borderRadius(12) + .backgroundColor(Color.White) + } +} + +@Component +struct VideoNewsContent { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + @Builder + myBuilder(item: ItemData) { + TopView({ item: item }) + MiddleVideoView({ item: item }) + BottomView({ item: item }) + } + + build() { + Column() { + this.myBuilder(this.item) + } + .alignItems(HorizontalAlign.Start) + .padding({ + top: 16, + bottom: 12, + left: 16, + right: 16 + }) + .margin({ + top: 12, + left: 16, + right: 16 + }) + .borderRadius(12) + .backgroundColor(Color.White) + } +} + +@Component +struct TopView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Text(this.item.title) + .fontSize(16) + .fontWeight(FontWeight.Medium) + .fontColor(Color.Black) + .maxLines(2) + .lineHeight(22) + .opacity(0.9) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .width('100%') + } +} + +@Component +struct BottomView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Text(this.item.tail) + .fontSize(12) + .opacity(0.4) + .fontWeight(FontWeight.Regular) + .margin({ left: 6, top: 12 }) + .width('100%') + } +} + +@Component +struct MiddleSingleImageView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Image(this.item.preview) + .width(158) + .height(96) + .borderRadius(8) + .margin({ top: 8 }) + } +} + +@Component +struct MiddleThreeImageView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Row() { + Image(this.item.pics[0]) + .layoutWeight(1) + .height(98) + .borderRadius({ topLeft: 8, bottomLeft: 8 }) + Divider().width(2) + Image(this.item.pics[1]) + .layoutWeight(1) + .height(98) + .borderRadius({ topLeft: 8, bottomLeft: 8 }) + Divider().width(2) + Image(this.item.pics[2]) + .layoutWeight(1) + .height(98) + .borderRadius({ topLeft: 8, bottomLeft: 8 }) + } + .margin({ top: 8 }) + } +} + +@Component +struct MiddleVideoView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Stack() { + Image(this.item.preview) + .width(112) + .height(112) + .borderRadius(8) + .margin({ top: 8 }) + + Row() { + Image($r('app.media.play_fill')) + .width(12).height(12) + Text(this.item.duration) + .fontColor(Color.White) + .fontSize(11) + .margin({ left: 2 }) + .fontWeight(FontWeight.Medium) + } + .margin(6) + } + } +} \ No newline at end of file diff --git a/ComponentReuse/negative/src/main/ets/pages/NoReuseScene3.ets b/ComponentReuse/negative/src/main/ets/pages/NoReuseScene3.ets new file mode 100644 index 0000000000000000000000000000000000000000..81c50610463a492ebd03f7d5a06984c39d240cde --- /dev/null +++ b/ComponentReuse/negative/src/main/ets/pages/NoReuseScene3.ets @@ -0,0 +1,270 @@ +import { ItemDataSource } from '../model/ItemDataSource'; +import { ItemData } from '../model/ItemData'; +import { genMockItemData } from '../common/MockData'; + +function count() { + for (let index = 0; index < 10000; index++) { + console.debug('fun index:' + index); + } +} + +@Builder +function buildNoReuseScene3() { + NoReuseScene3() +} + +// 未使用组件复用:场景3 +@Component +struct NoReuseScene3 { + private dataSource: ItemDataSource = new ItemDataSource(); + + aboutToAppear(): void { + this.dataSource.pushArray(genMockItemData(1000)); + } + + @Builder + itemBuilderSingleImage(item: ItemData) { + Column() { + TopView({ item: item }) + MiddleSingleImageView({ item: item }) + BottomView({ item: item }) + } + .alignItems(HorizontalAlign.Start) + .padding({ + top: 16, + bottom: 12, + left: 16, + right: 16 + }) + .margin({ + top: 12, + left: 16, + right: 16 + }) + .borderRadius(12) + .backgroundColor(Color.White) + } + + @Builder + itemBuilderThreeImage(item: ItemData) { + Column() { + TopView({ item: item }) + MiddleThreeImageView({ item: item }) + BottomView({ item: item }) + } + .alignItems(HorizontalAlign.Start) + .padding({ + top: 16, + bottom: 12, + left: 16, + right: 16 + }) + .margin({ + top: 12, + left: 16, + right: 16 + }) + .borderRadius(12) + .backgroundColor(Color.White) + } + + @Builder + itemBuilderVideo(item: ItemData) { + Column() { + TopView({ item: item }) + MiddleVideoView({ item: item }) + BottomView({ item: item }) + } + .alignItems(HorizontalAlign.Start) + .padding({ + top: 16, + bottom: 12, + left: 16, + right: 16 + }) + .margin({ + top: 12, + left: 16, + right: 16 + }) + .borderRadius(12) + .backgroundColor(Color.White) + } + + build() { + NavDestination() { + Column() { + List() { + LazyForEach(this.dataSource, (item: ItemData) => { + ListItem() { + if (item.type === 0) { + this.itemBuilderSingleImage(item) + } else if (item.type === 1) { + this.itemBuilderThreeImage(item) + } else { + this.itemBuilderVideo(item) + } + } + }, (item: ItemData) => item.id.toString()) + } + .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.BOTTOM]) + .cachedCount(1) + .width('100%') + .height('100%') + } + .width('100%') + .height('100%') + } + } +} + +@Component +struct NewsContent { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + @Builder + myBuilder(item: ItemData) { + TopView({ item: item }) + MiddleSingleImageView({ item: item }) + BottomView({ item: item }) + } + + build() { + Column() { + this.myBuilder(this.item) + } + .alignItems(HorizontalAlign.Start) + .padding({ + top: 16, + bottom: 12, + left: 16, + right: 16 + }) + .margin({ + top: 12, + left: 16, + right: 16 + }) + .borderRadius(12) + .backgroundColor(Color.White) + } +} + +@Component +struct TopView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Text(this.item.title) + .fontSize(16) + .fontWeight(FontWeight.Medium) + .fontColor(Color.Black) + .maxLines(2) + .lineHeight(22) + .opacity(0.9) + .textOverflow({ overflow: TextOverflow.Ellipsis }) + .width('100%') + } +} + +@Component +struct BottomView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Text(this.item.tail) + .fontSize(12) + .opacity(0.4) + .fontWeight(FontWeight.Regular) + .margin({ left: 6, top: 12 }) + .width('100%') + } +} + +@Component +struct MiddleSingleImageView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Image(this.item.preview) + .width(158) + .height(96) + .borderRadius(8) + .margin({ top: 8 }) + } +} + +@Component +struct MiddleThreeImageView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Row() { + Image(this.item.pics[0]) + .layoutWeight(1) + .height(98) + .borderRadius({ topLeft: 8, bottomLeft: 8 }) + Divider().width(2) + Image(this.item.pics[1]) + .layoutWeight(1) + .height(98) + .borderRadius({ topLeft: 8, bottomLeft: 8 }) + Divider().width(2) + Image(this.item.pics[2]) + .layoutWeight(1) + .height(98) + .borderRadius({ topLeft: 8, bottomLeft: 8 }) + } + .margin({ top: 8 }) + } +} + +@Component +struct MiddleVideoView { + @ObjectLink item: ItemData; + + aboutToAppear(): void { + count(); + } + + build() { + Stack() { + Image(this.item.preview) + .width(112) + .height(112) + .borderRadius(8) + .margin({ top: 8 }) + + Row() { + Image($r('app.media.play_fill')) + .width(12).height(12) + Text(this.item.duration) + .fontColor(Color.White) + .fontSize(11) + .margin({ left: 2 }) + .fontWeight(FontWeight.Medium) + } + .margin(6) + } + } +} \ No newline at end of file diff --git a/ComponentReuse/negative/src/main/resources/base/element/color.json b/ComponentReuse/negative/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3a0c6cea26e20e4f98146759d70e7e24da0e1d83 --- /dev/null +++ b/ComponentReuse/negative/src/main/resources/base/element/color.json @@ -0,0 +1,60 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "text", + "value": "#2c2c2c" + }, + { + "name": "home_background_color", + "value": "#F1F3F5" + }, + { + "name": "gray_3", + "value": "#FF333333" + }, + { + "name": "gray_6", + "value": "#FF666666" + }, + { + "name": "gray_9", + "value": "#FF999999" + }, + { + "name": "black_03", + "value": "#0D000000" + }, + { + "name": "black_0D", + "value": "#0D000000" + }, + { + "name": "black_12", + "value": "#12000000" + }, + { + "name": "black_33", + "value": "#33000000" + }, + { + "name": "black_66", + "value": "#66000000" + }, + { + "name": "black_80", + "value": "#80000000" + }, + { + "name": "black_99", + "value": "#99000000" + }, + { + "name": "black_E6", + "value": "#E6000000" + } + ] +} \ No newline at end of file diff --git a/ComponentReuse/negative/src/main/resources/base/element/float.json b/ComponentReuse/negative/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/ComponentReuse/negative/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/ComponentReuse/negative/src/main/resources/base/element/string.json b/ComponentReuse/negative/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..08a0271a9ca15cb687d645897035e239ccab8e1a --- /dev/null +++ b/ComponentReuse/negative/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "NegativeAbility_desc", + "value": "description" + }, + { + "name": "NegativeAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/ComponentReuse/negative/src/main/resources/base/media/background.png b/ComponentReuse/negative/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/ComponentReuse/negative/src/main/resources/base/media/background.png differ diff --git a/ComponentReuse/negative/src/main/resources/base/media/foreground.png b/ComponentReuse/negative/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/ComponentReuse/negative/src/main/resources/base/media/foreground.png differ diff --git a/ComponentReuse/negative/src/main/resources/base/media/img0.png b/ComponentReuse/negative/src/main/resources/base/media/img0.png new file mode 100644 index 0000000000000000000000000000000000000000..1d967400f83bb0f5e2df4581415ed2e4cbb564d4 Binary files /dev/null and b/ComponentReuse/negative/src/main/resources/base/media/img0.png differ diff --git a/ComponentReuse/negative/src/main/resources/base/media/img1.png b/ComponentReuse/negative/src/main/resources/base/media/img1.png new file mode 100644 index 0000000000000000000000000000000000000000..b254fba00dcee070e90baf945e920a8f2f0646c6 Binary files /dev/null and b/ComponentReuse/negative/src/main/resources/base/media/img1.png differ diff --git a/ComponentReuse/negative/src/main/resources/base/media/img2.jpg b/ComponentReuse/negative/src/main/resources/base/media/img2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4d36c1f9f8435424323ff12df2b0992bb09f8af5 Binary files /dev/null and b/ComponentReuse/negative/src/main/resources/base/media/img2.jpg differ diff --git a/ComponentReuse/negative/src/main/resources/base/media/img3.png b/ComponentReuse/negative/src/main/resources/base/media/img3.png new file mode 100644 index 0000000000000000000000000000000000000000..89214745c537495119e0e78c49e602f1c4933baa Binary files /dev/null and b/ComponentReuse/negative/src/main/resources/base/media/img3.png differ diff --git a/ComponentReuse/negative/src/main/resources/base/media/img4.png b/ComponentReuse/negative/src/main/resources/base/media/img4.png new file mode 100644 index 0000000000000000000000000000000000000000..54e59fc403d92d11911498f7d3c7d39d6e437cf5 Binary files /dev/null and b/ComponentReuse/negative/src/main/resources/base/media/img4.png differ diff --git a/ComponentReuse/negative/src/main/resources/base/media/img5.png b/ComponentReuse/negative/src/main/resources/base/media/img5.png new file mode 100644 index 0000000000000000000000000000000000000000..a38a0eaab71c8c6ba4b94bff09b7d86e96510043 Binary files /dev/null and b/ComponentReuse/negative/src/main/resources/base/media/img5.png differ diff --git a/ComponentReuse/negative/src/main/resources/base/media/img6.png b/ComponentReuse/negative/src/main/resources/base/media/img6.png new file mode 100644 index 0000000000000000000000000000000000000000..c1175890f2f43f92082e40299d7bda81094e9c06 Binary files /dev/null and b/ComponentReuse/negative/src/main/resources/base/media/img6.png differ diff --git a/ComponentReuse/negative/src/main/resources/base/media/img7.png b/ComponentReuse/negative/src/main/resources/base/media/img7.png new file mode 100644 index 0000000000000000000000000000000000000000..cd29997cfc3b0f30e1d393d49961da58d691ab2f Binary files /dev/null and b/ComponentReuse/negative/src/main/resources/base/media/img7.png differ diff --git a/ComponentReuse/negative/src/main/resources/base/media/img8.png b/ComponentReuse/negative/src/main/resources/base/media/img8.png new file mode 100644 index 0000000000000000000000000000000000000000..1cff5e45d286fb3bc058d326fc9b31caf690ac63 Binary files /dev/null and b/ComponentReuse/negative/src/main/resources/base/media/img8.png differ diff --git a/ComponentReuse/negative/src/main/resources/base/media/layered_image.json b/ComponentReuse/negative/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/ComponentReuse/negative/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/ComponentReuse/negative/src/main/resources/base/media/play_fill.svg b/ComponentReuse/negative/src/main/resources/base/media/play_fill.svg new file mode 100644 index 0000000000000000000000000000000000000000..d1750a9cc4dc77103c03b7e11674b4e0b2b278d9 --- /dev/null +++ b/ComponentReuse/negative/src/main/resources/base/media/play_fill.svg @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/ComponentReuse/negative/src/main/resources/base/media/startIcon.png b/ComponentReuse/negative/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/ComponentReuse/negative/src/main/resources/base/media/startIcon.png differ diff --git a/ComponentReuse/negative/src/main/resources/base/profile/main_pages.json b/ComponentReuse/negative/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/ComponentReuse/negative/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/ComponentReuse/negative/src/main/resources/base/profile/route_map.json b/ComponentReuse/negative/src/main/resources/base/profile/route_map.json new file mode 100644 index 0000000000000000000000000000000000000000..96d1b687ea92dc43fb6985b9c69dc89711a5b930 --- /dev/null +++ b/ComponentReuse/negative/src/main/resources/base/profile/route_map.json @@ -0,0 +1,39 @@ +{ + "routerMap": [ + { + "name": "NoReuseScene1", + "pageSourceFile": "src/main/ets/pages/NoReuseScene1.ets", + "buildFunction": "buildNoReuseScene1" + }, + { + "name": "NoReuseScene2_StructureOne", + "pageSourceFile": "src/main/ets/pages/NoReuseScene2_StructureOne.ets", + "buildFunction": "buildNoReuseScene2_StructureOne" + }, + { + "name": "NoReuseScene2_StructureTwo", + "pageSourceFile": "src/main/ets/pages/NoReuseScene2_StructureTwo.ets", + "buildFunction": "buildNoReuseScene2_StructureTwo" + }, + { + "name": "NoReuseScene3", + "pageSourceFile": "src/main/ets/pages/NoReuseScene3.ets", + "buildFunction": "buildNoReuseScene3" + }, + { + "name": "ImproperReuseOfComponentsScene1", + "pageSourceFile": "src/main/ets/pages/ImproperReuseOfComponentsScene1.ets", + "buildFunction": "buildImproperReuseOfComponentsScene1" + }, + { + "name": "ImproperReuseOfComponentsScene2", + "pageSourceFile": "src/main/ets/pages/ImproperReuseOfComponentsScene2.ets", + "buildFunction": "buildImproperReuseOfComponentsScene2" + }, + { + "name": "ImproperReuseOfComponentsScene3", + "pageSourceFile": "src/main/ets/pages/ImproperReuseOfComponentsScene3.ets", + "buildFunction": "buildImproperReuseOfComponentsScene3" + } + ] +} \ No newline at end of file