已合并
fix: 修复ArkUI示例代码拼写错误及部分逻辑问题 #10429
fix: 修复ArkUI示例代码拼写错误及部分逻辑问题 #10429
已合并
chenyuchi创建于 7月7日
21 个文件变更+54-52
@@ -39,7 +39,7 @@ struct updaterDemo {
39 .height(50)39 .height(50)
40 .backgroundColor('#2787D9')40 .backgroundColor('#2787D9')
41 .onClick(() => {41 .onClick(() => {
42- // 调用updateConstructorParams方法,直接更新组件的构造参数42+ // 调用updateConstructorParams属性,直接更新组件的构造参数
43 this.modifier.updateConstructorParams('Update');43 this.modifier.updateConstructorParams('Update');
44 })44 })
45 }45 }
@@ -79,7 +79,6 @@ class MyNodeController extends NodeController {
79@Entry79@Entry
80@Component80@Component
81struct Index {81struct Index {
82- @State message: string = 'Hello World';
83 controller = new NodeContentCtrl(this.getUIContext());82 controller = new NodeContentCtrl(this.getUIContext());
84 myNodeController = new MyNodeController();83 myNodeController = new MyNodeController();
85 84 
@@ -67,7 +67,7 @@ class TextNodeController extends NodeController {
67 }67 }
68 68 
69 makeNode(context: UIContext): FrameNode | null {69 makeNode(context: UIContext): FrameNode | null {
70- return this.textNode?.getFrameNode() ? this.textNode?.getFrameNode() : null;70+ return this.textNode?.getFrameNode() ?? null;
71 }71 }
72 72 
73 createNode(context: UIContext) {73 createNode(context: UIContext) {
@@ -115,7 +115,7 @@ export struct RepeatVirtualScrollFreeze {
115@ComponentV2({ freezeWhenInactive: true })115@ComponentV2({ freezeWhenInactive: true })
116struct FreezeBuildNode {116struct FreezeBuildNode {
117 storage: Params = Params.instance();117 storage: Params = Params.instance();
118- @Param @Require message: string ;118+ @Param @Require message: string;
119 @Param @Require bgColor: Color;119 @Param @Require bgColor: Color;
120 @Monitor('storage.bgColor')120 @Monitor('storage.bgColor')
121 onBgColorChange(monitor: IMonitor) {121 onBgColorChange(monitor: IMonitor) {
@@ -133,10 +133,10 @@ struct BuildNodeChild {
133 storage: Params = Params.instance();133 storage: Params = Params.instance();
134 @Param message: string = '';134 @Param message: string = '';
135 135 
136- // 使用@Monitor装饰器监听storage.message的变化。136+ // 使用@Monitor装饰器监听storage.bgColor的变化。
137 @Monitor('storage.bgColor')137 @Monitor('storage.bgColor')
138- onMessageChange(monitor: IMonitor) {138+ onBgColorChange(monitor: IMonitor) {
139- hilog.info(0xF811, 'testTag', '%{public}s',`FreezeBuildNode buildNodeChild message callback func ${this.message}`);139+ hilog.info(0xF811, 'testTag', '%{public}s',`FreezeBuildNode buildNodeChild bgColor change from ${monitor.value()?.before} to ${monitor.value()?.now}`);
140 }140 }
141 141 
142 build() {142 build() {
@@ -98,7 +98,7 @@ struct Index {
98 Button('modify ArkTS-FrameNode')98 Button('modify ArkTS-FrameNode')
99 .onClick(() => {99 .onClick(() => {
100 // 获取到的是当前页面中的开发者创建的FrameNode对象,该节点可修改。即节点大小与位置。100 // 获取到的是当前页面中的开发者创建的FrameNode对象,该节点可修改。即节点大小与位置。
101- hilog.info(0x0000, `Check the weather the node can be modified ${this.myNodeController?.frameNode101+ hilog.info(0x0000, `Check the whether the node can be modified ${this.myNodeController?.frameNode
102 ?.isModifiable()}`, 'isClicked');102 ?.isModifiable()}`, 'isClicked');
103 this.myNodeController.modifyNode(this.myNodeController?.frameNode, { width: 150, height: 100 }, {103 this.myNodeController.modifyNode(this.myNodeController?.frameNode, { width: 150, height: 100 }, {
104 x: 100,104 x: 100,
@@ -108,7 +108,7 @@ struct Index {
108 Button('modify FrameNode get by BuilderNode')108 Button('modify FrameNode get by BuilderNode')
109 .onClick(() => {109 .onClick(() => {
110 // 获取到的是当前页面中的BuilderNode的根节点,该节点不可修改。即节点大小与位置未发生改变。110 // 获取到的是当前页面中的BuilderNode的根节点,该节点不可修改。即节点大小与位置未发生改变。
111- hilog.info(0x0000, `Check the weather the node can be modified111+ hilog.info(0x0000, `Check the whether the node can be modified
112 ${this.myNodeController?.buttonNode?.getFrameNode()112 ${this.myNodeController?.buttonNode?.getFrameNode()
113 ?.isModifiable()}`, 'isClicked');113 ?.isModifiable()}`, 'isClicked');
114 this.myNodeController.modifyNode(this.myNodeController?.buttonNode?.getFrameNode(), {114 this.myNodeController.modifyNode(this.myNodeController?.buttonNode?.getFrameNode(), {
@@ -120,7 +120,7 @@ struct Index {
120 .onClick(() => {120 .onClick(() => {
121 // rootNode调用getParent()获取到的是当前页面中的NodeContainer节点,该节点不可修改。即节点大小与位置未发生改变。121 // rootNode调用getParent()获取到的是当前页面中的NodeContainer节点,该节点不可修改。即节点大小与位置未发生改变。
122 hilog.info(0x0000,122 hilog.info(0x0000,
123- `Check the weather the node can be modified ${this.myNodeController?.rootNode?.getParent()123+ `Check the whether the node can be modified ${this.myNodeController?.rootNode?.getParent()
124 ?.isModifiable()}`, 'isClicked');124 ?.isModifiable()}`, 'isClicked');
125 this.myNodeController.modifyNode(this.myNodeController?.rootNode?.getParent(), {125 this.myNodeController.modifyNode(this.myNodeController?.rootNode?.getParent(), {
126 width: 500,126 width: 500,
@@ -144,9 +144,9 @@ struct Index {
144 Button('add click event to ArkTS-FrameNode')144 Button('add click event to ArkTS-FrameNode')
145 .onClick(() => {145 .onClick(() => {
146 // 获取到的是当前页面中的开发者创建的FrameNode对象,该节点可增加点击事件。146 // 获取到的是当前页面中的开发者创建的FrameNode对象,该节点可增加点击事件。
147- // 增加的点击事件参与事件竞争,即点击事件会在该节点被消费且不再向父组件冒泡。147+ // 增加的点击事件参与事件竞争,即点击事件会在该节点被消费且不再向父组件冒泡。
148 hilog.info(0x0000,148 hilog.info(0x0000,
149- `Check the weather the node can be modified ${this.myNodeController?.rootNode?.getParent()149+ `Check the whether the node can be modified ${this.myNodeController?.rootNode?.getParent()
150 ?.isModifiable()}`, 'isClicked');150 ?.isModifiable()}`, 'isClicked');
151 this.myNodeController.addClickEvent(this.myNodeController?.frameNode);151 this.myNodeController.addClickEvent(this.myNodeController?.frameNode);
152 })152 })
@@ -154,7 +154,7 @@ struct Index {
154 .onClick(() => {154 .onClick(() => {
155 // 获取到的是当前页面中的BuilderNode的根节点,该类节点可增加点击事件。155 // 获取到的是当前页面中的BuilderNode的根节点,该类节点可增加点击事件。
156 // 点击的时候优先回调通过系统组件接口设置的click事件回调,然后回调通过commonEvent增加的click监听。156 // 点击的时候优先回调通过系统组件接口设置的click事件回调,然后回调通过commonEvent增加的click监听。
157- hilog.info(0x0000, `Check the weather the node can be modified157+ hilog.info(0x0000, `Check the whether the node can be modified
158 ${this.myNodeController?.buttonNode?.getFrameNode()158 ${this.myNodeController?.buttonNode?.getFrameNode()
159 ?.isModifiable()}`, 'isClicked');159 ?.isModifiable()}`, 'isClicked');
160 this.myNodeController.addClickEvent(this.myNodeController?.buttonNode?.getFrameNode());160 this.myNodeController.addClickEvent(this.myNodeController?.buttonNode?.getFrameNode());
@@ -163,7 +163,7 @@ struct Index {
163 .onClick(() => {163 .onClick(() => {
164 // rootNode调用getParent()获取到的是当前页面中的NodeContainer节点,该类节点可增加点击事件。164 // rootNode调用getParent()获取到的是当前页面中的NodeContainer节点,该类节点可增加点击事件。
165 hilog.info(0x0000,165 hilog.info(0x0000,
166- `Check the weather the node can be modified ${this.myNodeController?.rootNode?.getParent()166+ `Check the whether the node can be modified ${this.myNodeController?.rootNode?.getParent()
167 ?.isModifiable()}`, 'isClicked');167 ?.isModifiable()}`, 'isClicked');
168 this.myNodeController.addClickEvent(this.myNodeController?.rootNode?.getParent());168 this.myNodeController.addClickEvent(this.myNodeController?.rootNode?.getParent());
169 })169 })
@@ -32,7 +32,7 @@ struct Index {
32 if (isOnRenderTree) {32 if (isOnRenderTree) {
33 hilog.info(1, 'frameNode', 'is on render tree');33 hilog.info(1, 'frameNode', 'is on render tree');
34 } else {34 } else {
35- hilog.info(1, 'frameNode', 'is not no render tree');35+ hilog.info(1, 'frameNode', 'is not on render tree');
36 }36 }
37 }37 }
38 38 
@@ -66,7 +66,7 @@ struct Index {
66 let textNode1 = this.getUIContext().getFrameNodeById('hello1');66 let textNode1 = this.getUIContext().getFrameNodeById('hello1');
67 if (textNode1 != null) {67 if (textNode1 != null) {
68 let isOnRenderTree = textNode1!.isInRenderState();68 let isOnRenderTree = textNode1!.isInRenderState();
69- isOnRenderTree ? this.message = 'is on render tree' : this.message = 'is not on render tree';69+ this.message = isOnRenderTree ? 'is on render tree' : 'is not on render tree';
70 hilog.info(1, 'frameNode', 'is hello1 on RenderTree: %{public}s', isOnRenderTree);70 hilog.info(1, 'frameNode', 'is hello1 on RenderTree: %{public}s', isOnRenderTree);
71 }71 }
72 })72 })
@@ -46,7 +46,7 @@ class MyNodeAdapter extends NodeAdapter {
46 // 刷新数据46 // 刷新数据
47 refreshData(): void {47 refreshData(): void {
48 let items = this.getAllAvailableItems()48 let items = this.getAllAvailableItems()
49- hilog.info(0x0000, `TEST_TAG ' get All items:' + ${items.length}`, 'isCLicked');49+ hilog.info(0x0000, `${TEST_TAG} get All items: ${items.length}`, 'isClicked');
50 this.totalNodeCount -= 1;50 this.totalNodeCount -= 1;
51 this.reloadAllItems();51 this.reloadAllItems();
52 }52 }
@@ -116,7 +116,7 @@ class MyNodeAdapter extends NodeAdapter {
116 }116 }
117 117 
118 onCreateChild(index: number): FrameNode {118 onCreateChild(index: number): FrameNode {
119- hilog.info(0x0000, `TEST_TAG + ' onCreateChild:' + ${index}`, 'onCreateChild');119+ hilog.info(0x0000, `${TEST_TAG} onCreateChild: ${index}`, 'onCreateChild');
120 // 缓存池有可用节点时,优先复用120 // 缓存池有可用节点时,优先复用
121 if (this.cachePool.length > 0) {121 if (this.cachePool.length > 0) {
122 let cacheNode = this.cachePool.pop();122 let cacheNode = this.cachePool.pop();
@@ -202,7 +202,7 @@ class MyNodeController extends NodeController {
202 202 
203 getChildWithExpand() {203 getChildWithExpand() {
204 const childNode = this.rootNode!.getChild(3, ExpandMode.EXPAND);204 const childNode = this.rootNode!.getChild(3, ExpandMode.EXPAND);
205- hilog.info(0x0000, `${TEST_TAG} getChild(3, ExpandMode.EXPAND): childNode!.getId()`, 'getId');205+ hilog.info(0x0000, `${TEST_TAG} getChild(3, ExpandMode.EXPAND): ${childNode!.getId()}`, 'getId');
206 if (childNode!.getId() === 'N3') {206 if (childNode!.getId() === 'N3') {
207 hilog.info(0x0000, `${TEST_TAG} getChild(3, ExpandMode.EXPAND) result: success.`, 'success');207 hilog.info(0x0000, `${TEST_TAG} getChild(3, ExpandMode.EXPAND) result: success.`, 'success');
208 } else {208 } else {
@@ -212,7 +212,7 @@ class MyNodeController extends NodeController {
212 212 
213 getChildWithLazyExpand() {213 getChildWithLazyExpand() {
214 const childNode = this.rootNode!.getChild(3, ExpandMode.LAZY_EXPAND);214 const childNode = this.rootNode!.getChild(3, ExpandMode.LAZY_EXPAND);
215- hilog.info(0x0000, `${TEST_TAG} getChild(3, ExpandMode.LAZY_EXPAND): childNode!.getId()`, 'getId');215+ hilog.info(0x0000, `${TEST_TAG} getChild(3, ExpandMode.LAZY_EXPAND): ${childNode!.getId()}`, 'getId');
216 if (childNode!.getId() === 'N3') {216 if (childNode!.getId() === 'N3') {
217 hilog.info(0x0000, `${TEST_TAG} getChild(3, ExpandMode.LAZY_EXPAND) result: success.`, 'success');217 hilog.info(0x0000, `${TEST_TAG} getChild(3, ExpandMode.LAZY_EXPAND) result: success.`, 'success');
218 } else {218 } else {
@@ -121,7 +121,7 @@ class MyNodeController extends NodeController {
121 frameNode?.clearChildren();121 frameNode?.clearChildren();
122 hilog.info(0x0000, `${TEST_TAG} clearChildren success `, 'success');122 hilog.info(0x0000, `${TEST_TAG} clearChildren success `, 'success');
123 } catch (err) {123 } catch (err) {
124- hilog.error(0x0000, `${TEST_TAG} clearChildren fail: (err as BusinessError).code:124+ hilog.error(0x0000, `${TEST_TAG} clearChildren fail: ${(err as BusinessError).code}:
125 ${(err as BusinessError).message}`, 'clearChildren error');125 ${(err as BusinessError).message}`, 'clearChildren error');
126 }126 }
127 }, 4000)127 }, 4000)
@@ -249,10 +249,10 @@ struct Index {
249 .fontSize(16)249 .fontSize(16)
250 .width(400)250 .width(400)
251 .onClick(() => {251 .onClick(() => {
252- // 对FrameNode节点进行进行查询。当前节点为NodeContainer的子节点。252+ // 对FrameNode节点进行查询。当前节点为NodeContainer的子节点。
253 this.result = this.myNodeController.testInterfaceAboutSearch(this.myNodeController?.rootNode);253 this.result = this.myNodeController.testInterfaceAboutSearch(this.myNodeController?.rootNode);
254 setTimeout(() => {254 setTimeout(() => {
255- // 对FrameNode节点进行进行查询。rootNode下的第一个子节点。255+ // 对FrameNode节点进行查询。rootNode下的第一个子节点。
256 this.result = this.myNodeController.testInterfaceAboutSearch(this.myNodeController?.frameNode);256 this.result = this.myNodeController.testInterfaceAboutSearch(this.myNodeController?.frameNode);
257 }, 2000)257 }, 2000)
258 })258 })
@@ -87,7 +87,7 @@ struct ArticleCardChangeChild {
87 .margin({ bottom: 8 })87 .margin({ bottom: 8 })
88 88 
89 Row() {89 Row() {
90- // 此处app.media.iconLiked','app.media.iconUnLiked'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。90+ // 此处'app.media.iconLiked','app.media.iconUnLiked'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。
91 Image(this.article.isLiked ? $r('app.media.iconLiked') : $r('app.media.iconUnLiked'))91 Image(this.article.isLiked ? $r('app.media.iconLiked') : $r('app.media.iconUnLiked'))
92 .width(24)92 .width(24)
93 .height(24)93 .height(24)
@@ -105,7 +105,7 @@ struct ArticleCardChangeData {
105 .margin({ bottom: 8 })105 .margin({ bottom: 8 })
106 106 
107 Row() {107 Row() {
108- // 此处app.media.iconLiked','app.media.iconUnLiked'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。108+ // 此处'app.media.iconLiked','app.media.iconUnLiked'仅作示例,请开发者自行替换,否则imageSource创建失败会导致后续无法正常执行。
109 Image(this.article.isLiked ? $r('app.media.iconLiked') : $r('app.media.iconUnLiked'))109 Image(this.article.isLiked ? $r('app.media.iconLiked') : $r('app.media.iconUnLiked'))
110 .width(24)110 .width(24)
111 .height(24)111 .height(24)
@@ -30,7 +30,7 @@ struct ReducedRenderingPerformance {
30 }30 }
31 .onClick(() => {31 .onClick(() => {
32 this.simpleList.splice(1, 0, 'new item');32 this.simpleList.splice(1, 0, 'new item');
33- hilog.info(DOMAIN, 'testTag', '[onClick]: simpleList is [${this.simpleList.join(', ')}]');33+ hilog.info(DOMAIN, 'testTag', `[onClick]: simpleList is [${this.simpleList.join(', ')}]`);
34 })34 })
35 35 
36 ForEach(this.simpleList, (item: string) => {36 ForEach(this.simpleList, (item: string) => {
@@ -49,7 +49,7 @@ struct ReducedChildItem {
49 @Prop item: string;49 @Prop item: string;
50 50 
51 aboutToAppear() {51 aboutToAppear() {
52- hilog.info(DOMAIN, TAG, '[aboutToAppear]: item is ${this.item}');52+ hilog.info(DOMAIN, TAG, `[aboutToAppear]: item is ${this.item}`);
53 }53 }
54 54 
55 build() {55 build() {
@@ -78,7 +78,7 @@ struct ImageFlickeringDuringRerenders {
78 78 
79@Component79@Component
80struct ImageFlickeringChildComponent {80struct ImageFlickeringChildComponent {
81- // 用状态变量来驱动UI刷新,而不是通过Lazyforeach的api来驱动UI刷新81+ // 用状态变量来驱动UI刷新,而不是通过LazyForEach的api来驱动UI刷新
82 @ObjectLink data: ImageFliceringStringData;82 @ObjectLink data: ImageFliceringStringData;
83 83 
84 build() {84 build() {
@@ -38,7 +38,7 @@ struct RepeatExampleWithTemplates {
38 .key((item: string, index: number): string => JSON.stringify(item)) // 键值生成函数38 .key((item: string, index: number): string => JSON.stringify(item)) // 键值生成函数
39 .virtualScroll({ totalCount: this.dataArr.length }) // 打开懒加载,totalCount为期望加载的数据长度39 .virtualScroll({ totalCount: this.dataArr.length }) // 打开懒加载,totalCount为期望加载的数据长度
40 .templateId((item: string, index: number): string => { // 根据返回值寻找对应的模板子组件进行渲染40 .templateId((item: string, index: number): string => { // 根据返回值寻找对应的模板子组件进行渲染
41- return index <= 4 ? 'A' : (index <= 10 ? 'B' : ''); // 前5个节点模板为A,接下来的5个为B,其余为默认模板41+ return index <= 4 ? 'A' : (index <= 10 ? 'B' : ''); // 前5个节点模板为A,接下来的6个为B,其余为默认模板
42 })42 })
43 .template('A', (ri: RepeatItem<string>) => { // 'A'模板43 .template('A', (ri: RepeatItem<string>) => { // 'A'模板
44 ListItem() {44 ListItem() {
@@ -120,23 +120,27 @@ struct RepeatVirtualScroll {
120 })120 })
121 .virtualScroll({ totalCount: this.simpleList.length })121 .virtualScroll({ totalCount: this.simpleList.length })
122 .templateId((item: Repeat006Clazz, index: number) => {122 .templateId((item: Repeat006Clazz, index: number) => {
123- return (index % 2 === 0) ? 'odd' : 'even';123+ return (index % 2 === 0) ? 'even' : 'odd';
124 })124 })
125 .template('odd', (ri) => {125 .template('odd', (ri) => {
126- Text(`[odd] index${ri.index}: ${ri.item.message}`)126+ ListItem() {
127- .fontSize(25)127+ Text(`[odd] index${ri.index}: ${ri.item.message}`)
128- .fontColor(Color.Blue)128+ .fontSize(25)
129- .onClick(() => {129+ .fontColor(Color.Blue)
130- this.handleExchange(ri.index);130+ .onClick(() => {
131- })131+ this.handleExchange(ri.index);
132+ })
133+ }
132 }, { cachedCount: 3 })134 }, { cachedCount: 3 })
133 .template('even', (ri) => {135 .template('even', (ri) => {
134- Text(`[even] index${ri.index}: ${ri.item.message}`)136+ ListItem() {
135- .fontSize(25)137+ Text(`[even] index${ri.index}: ${ri.item.message}`)
136- .fontColor(Color.Green)138+ .fontSize(25)
137- .onClick(() => {139+ .fontColor(Color.Green)
138- this.handleExchange(ri.index);140+ .onClick(() => {
139- })141+ this.handleExchange(ri.index);
142+ })
143+ }
140 }, { cachedCount: 1 })144 }, { cachedCount: 1 })
141 }145 }
142 .cachedCount(2)146 .cachedCount(2)
@@ -75,7 +75,7 @@ napi_value NodeManager::CreateNativeNode(napi_env env, napi_callback_info info)
75 // [End contentslot_add]75 // [End contentslot_add]
76 // [StartExclude contentslot_native]76 // [StartExclude contentslot_native]
77 // [Start contentslot_insert]77 // [Start contentslot_insert]
78- size_t position = 0;78+ int32_t position = 0;
79 ArkUI_NodeHandle component1 = CreateNodeHandle();79 ArkUI_NodeHandle component1 = CreateNodeHandle();
80 // 将组件插入nodeContent管理器对应位置80 // 将组件插入nodeContent管理器对应位置
81 OH_ArkUI_NodeContent_InsertNode(nodeContentHandle_, component1, position);81 OH_ArkUI_NodeContent_InsertNode(nodeContentHandle_, component1, position);
@@ -134,7 +134,7 @@ void NodeManager::RegisterEvent()
134 userData = nullptr;134 userData = nullptr;
135 }135 }
136 // [EndExclude contentslot_register_event]136 // [EndExclude contentslot_register_event]
137- };137+ }
138 };138 };
139 // 将该事件注册到nodeContent上139 // 将该事件注册到nodeContent上
140 OH_ArkUI_NodeContent_RegisterCallback(nodeContentHandle_, nodeContentEvent);140 OH_ArkUI_NodeContent_RegisterCallback(nodeContentHandle_, nodeContentEvent);
@@ -106,7 +106,7 @@ struct ListItemView {
106 @State item: string = '';106 @State item: string = '';
107 107 
108 aboutToAppear(): void {108 aboutToAppear(): void {
109- // 点击 update,首次进入,上下滑动,由于Foreach折叠展开属性,无法复用。109+ // 点击 update,首次进入,上下滑动,由于ForEach折叠展开属性,无法复用。
110 hilog.info(DOMAIN, TAG, BUNDLE + '=====aboutToAppear=====ListItemView==创建了==' + this.item);110 hilog.info(DOMAIN, TAG, BUNDLE + '=====aboutToAppear=====ListItemView==创建了==' + this.item);
111 }111 }
112 112 
@@ -109,7 +109,7 @@ struct MyComponent {
109 .onAppear(() => {109 .onAppear(() => {
110 hilog.info(DOMAIN, TAG, BUNDLE + `ListItem ${index} onAppear`);110 hilog.info(DOMAIN, TAG, BUNDLE + `ListItem ${index} onAppear`);
111 })111 })
112- }, (item: number) => item.toString())112+ }, (item: string) => item)
113 }113 }
114 .width('100%')114 .width('100%')
115 .height('100%')115 .height('100%')
@@ -59,7 +59,7 @@ struct MyComponent {
59 // 使用可复用自定义组件。59 // 使用可复用自定义组件。
60 ReusableChildComponent({ item: item });60 ReusableChildComponent({ item: item });
61 }61 }
62- }, (item: string) => item)62+ }, (item: number) => item.toString())
63 }63 }
64 .cachedCount(2) // 设置GridItem的缓存数量。64 .cachedCount(2) // 设置GridItem的缓存数量。
65 .columnsTemplate('1fr 1fr 1fr')65 .columnsTemplate('1fr 1fr 1fr')
@@ -15,18 +15,18 @@
15 15 
16// [Start reusable_for_limited_variation]16// [Start reusable_for_limited_variation]
17class LimitedMyDataSource implements IDataSource {17class LimitedMyDataSource implements IDataSource {
18- private dataArray: string[] = [];18+ private dataArray: number[] = [];
19 private listener: DataChangeListener | undefined;19 private listener: DataChangeListener | undefined;
20 20 
21 public totalCount(): number {21 public totalCount(): number {
22 return this.dataArray.length;22 return this.dataArray.length;
23 }23 }
24 24 
25- public getData(index: number): string {25+ public getData(index: number): number {
26 return this.dataArray[index];26 return this.dataArray[index];
27 }27 }
28 28 
29- public pushData(data: string): void {29+ public pushData(data: number): void {
30 this.dataArray.push(data);30 this.dataArray.push(data);
31 }31 }
32 32 
@@ -50,7 +50,7 @@ struct LimitedIndex {
50 50 
51 aboutToAppear() {51 aboutToAppear() {
52 for (let i = 0; i < 1000; i++) { // 循环1000次52 for (let i = 0; i < 1000; i++) { // 循环1000次
53- this.data.pushData(i + '');53+ this.data.pushData(i);
54 }54 }
55 }55 }
56 56 
@@ -101,7 +101,6 @@ struct ReusableFlowItem {
101struct Index {101struct Index {
102 @State minSize: number = 50; // 最小值50102 @State minSize: number = 50; // 最小值50
103 @State maxSize: number = 80; // 最大值80103 @State maxSize: number = 80; // 最大值80
104- @State fontSize: number = 24; // 字体大小为24
105 @State colors: number[] = [0xFFC0CB, 0xDA70D6, 0x6B8E23, 0x6A5ACD, 0x00FFFF, 0x00FF7F];104 @State colors: number[] = [0xFFC0CB, 0xDA70D6, 0x6B8E23, 0x6A5ACD, 0x00FFFF, 0x00FF7F];
106 scroller: Scroller = new Scroller();105 scroller: Scroller = new Scroller();
107 dataSource: WaterFlowDataSource = new WaterFlowDataSource();106 dataSource: WaterFlowDataSource = new WaterFlowDataSource();