• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ArkUI子系统ChangeLog
2## cl.arkui.1 Navigationd的menus接口、NavDestination的title和menus接口支持Resource类型资源
3**访问级别**
4
5公开接口
6
7**变更原因**
8
9基础能力增强,Navigationd的menus接口、NavDestination的title和menus接口支持Resource类型资源。
10
11**变更影响**
12
13该变更为不兼容变更。
14
15由于NavigationMenuItem变量类型变更为 string | Resource,不再与单一变量类型string相匹配,因此将NavigationMenuItem赋值给一个string类型变量,程序会编译报错。
16
17```
18const myIcon: NavigationMenuItem = { value: "图标", icon: "https://example.png"}
19const myString: string = myIcon.value
20```
21
22**起始API Level**
23
249
25
26**变更发生版本**
27
28从OpenHarmony SDK 5.0.0.42 版本开始。
29
30**变更的接口/组件**
31
32Navigation的menus接口
33
34NavDestination的menus和title接口
35
36**适配指导**
37
38```
39// navigation.ets
40// 使用resource类型资源赋值给Navigation/NavDestination的title及menu接口
41Navigation() {
42    // xxx
43}
44// $r('app.string.MyTestNavigationTitle')需要替换为开发者所需的资源文件
45.title($r('app.string.MyTestNavigationTitle'))  // 可直接将resource类型资源传递给title接口
46// menus内的item设置可直接支持resource类型资源
47.menus([
48  {
49    // $r("app.string.MyTestMenuValue1")和$r("app.media.1")需要替换为开发者所需的资源文件
50    value: $r("app.string.MyTestMenuValue1"),
51    icon: $r("app.media.1")
52  },
53  {
54    // $r("app.string.MyTestMenuValue2")和$r("app.media.2")需要替换为开发者所需的资源文件
55    value: $r("app.string.MyTestMenuValue2"),
56    icon: $r("app.media.2")
57  },
58  {
59    // $r("app.string.MyTestMenuValue3")和$r("app.media.3")需要替换为开发者所需的资源文件
60    value: $r("app.string.MyTestMenuValue3"),
61    icon: $r("app.media.3")
62  }
63])
64```
65
66
67```
68// navDestination.ets
69// Navigation及NavDestination的CommonTitle类型,支持设置resource资源
70// 需要替换为开发者所需的资源文件
71@State commonTitle: NavDestinationCommonTitle = { main: $r('app.string.MyTestNavigationTitle'), sub: $r('app.string.MyTestNavigationTitle')}
72NavDestination() {
73    // xxx
74}
75.menus([
76  {
77    // $r("app.string.MyTestMenuValue1")和$r("app.media.4")需要替换为开发者所需的资源文件
78    value: $r("app.string.MyTestMenuValue1"),
79    icon: $r("app.media.4")
80  },
81  {
82    // $r("app.string.MyTestMenuValue2")和$r("app.media.5")需要替换为开发者所需的资源文件
83    value: $r("app.string.MyTestMenuValue2"),
84    icon: $r("app.media.5")
85  },
86  {
87    // $r("app.string.MyTestMenuValue3")和$r("app.media.6")需要替换为开发者所需的资源文件
88    value: $r("app.string.MyTestMenuValue3"),
89    icon: $r("app.media.6")
90  }
91])
92.title(this.commonTitle)
93```
94
95## cl.arkui.2 优化状态变量场景下ForEach的冗余刷新行为
96
97**访问级别**
98
99公开接口
100
101**变更原因**
102
103开发者使用ForEach,在旧节点下树的时候会被刷新一次,属于规格外的行为,当刷新调用方法中存在对全局变量的修改时会发生异常。
104
105**变更影响**
106
107该变更为不兼容变更。
108
109变更前:开发者在使用ForEach时,节点下树的时候会被刷新一次。
110
111变更后:开发者在使用ForEach时,节点下树的时候不会被刷新。
112
113**起始API Level**
114
1159
116
117**变更发生版本**
118
119从OpenHarmony SDK 5.0.0.42开始。
120
121**变更的接口/组件**
122
123ForEach
124
125**适配指导**
126
127之前使用ForEach涉及节点刷新时调用的方法存在对全局变量值修改的,需要根据具体情况对代码进行相应的修改,使当前修改等效于原来的两次修改叠加,以保证效果不变。
128
129示例:
130
131变更前:
132```ts
133let g_data = 0;
134
135@Entry
136@Component
137struct MyComponent {
138  @State simpleList: number[] = [0, 1, 2]
139
140  fn(item: number, index: number) {
141    g_data++;
142    return 80;
143  }
144
145  build() {
146    Row() {
147      Column() {
148        Button('click button []')
149          .onClick(() => {
150            this.simpleList = [4, 5, 6]
151          })
152        ForEach(this.simpleList, (item: number, index: number) => {
153          Text(item.toString())
154            .fontSize(this.fn(item, index))
155            .onAppear(()=>{
156              console.log('g_data: ' + g_data);
157            })
158        }, (item: string) => item)
159      }
160      .width('100%')
161      .height('100%')
162    }
163  }
164}
165```
166
167变更后:
168```ts
169let g_data = 0;
170
171@Entry
172@Component
173struct MyComponent {
174  @State simpleList: number[] = [0, 1, 2]
175
176  fn(item: number, index: number) {
177    // 变更前总会调用两次,变更后只会调用一次,保证变更前后效果一致
178    g_data+=2;
179    return 80;
180  }
181
182  build() {
183    Row() {
184      Column() {
185        Button('click button []')
186          .onClick(() => {
187            this.simpleList = [4, 5, 6]
188          })
189        ForEach(this.simpleList, (item: number, index: number) => {
190          Text(item.toString())
191            .fontSize(this.fn(item, index))
192            .onAppear(()=>{
193              console.log('g_data: ' + g_data);
194            })
195        }, (item: string) => item)
196      }
197      .width('100%')
198      .height('100%')
199    }
200  }
201}
202```
203
204## cl.arkui.3 NavDestination的Dialog模式默认支持系统动画
205
206**访问级别**
207
208公开接口
209
210**变更原因**
211
212NavDestination的Dialog模式支持系统动画。
213
214**变更影响**
215该变更为不兼容变更。
216
217变更前:NavDestination的Dialog模式,无系统默认动画。
218
219变更后:NavDestination的Dialog模式,默认带有系统转场动画。
220
221| 变更前 | 变更后 |
222|---------|---------|
223| ![](figures/dialog_before.gif) | ![](figures/dialog_after.gif) |
224
225**起始API Level**
226
2279
228
229**变更发生版本**
230
231从OpenHarmony SDK 5.0.0.42开始。
232
233**变更的接口/组件**
234
235NavDestination
236
237**适配指导**
238
239开发者可以通过在pop与push接口中设置false关闭NavDestination的系统默认动画。
240
241示例:
242
243```ts
244@Entry
245@Component
246
247struct NavigationDemo {
248	@State pageInfos: NavPathStack = new NavPathStack();
249
250	@Builder
251	pageOneTmp() {
252		NavDestination() {
253          Text("This is a sample")
254            .fontSize(50)
255		}
256		.title("PageOne")
257		.mode(NavDestinationMode.DIALOG)
258    .backgroundColor(Color.Blue)
259	}
260
261	@Builder
262	PageMap(name: string, param: object) {
263		if (name === 'pageOne') {
264			this.pageOneTmp()
265		}
266	}
267
268	build() {
269		Column({ space: 10 }) {
270			Button('Pop Dialog')
271			.onClick(() => {
272				// Set true to enable system animations, or set false to disable system animations.
273				this.pageInfos.pop(true)
274			})
275			Button('Push Dialog')
276			.onClick(() => {
277				// Set true to enable system animations, or set false to disable system animations.
278				this.pageInfos.pushPath({ name: 'pageOne' }, true)
279			})
280			Navigation(this.pageInfos) {
281				Column({ space: 10 }) {
282					Text("This is navigation").fontSize(60).align(Alignment.Center)
283				}
284			}
285			.height(500)
286			.backgroundColor(Color.Grey)
287			.navDestination(this.PageMap)
288		}.height(50)
289	}
290}
291```