1# ArkUI子系统ChangeLog 2## cl.arkui.1 Navigation、NavDestination的title和menus接口支持Resource类型资源 3**访问级别** 4 5公开接口 6 7**变更原因** 8 9基础能力增强,Navigation、navdestination的title和menus接口支持Resource类型 10 11**变更影响** 12 13该变更为不兼容变更。 14 15由于NavigationMenuItem变量类型变更为 string | Resource,不再与单一变量类型string相匹配,因此将NavigationMenuItem赋值给一个string类型变量,程序会编译报错。 16 17``` 18@State myString: string = ''; 19@State myIcon: NavigationMenuItem["value"] = $r("app.string.MyTestMenuValue1") 20 21this.myString = this.myIcon 22``` 23 24**起始API Level** 25 269 27 28**变更发生版本** 29 30从OpenHarmony SDK 5.0.0.42 版本开始。 31 32**变更的接口/组件** 33 34Navigation/NavDestination 35 36**适配指导** 37 38``` 39// navigation.ets 40// 使用resource类型资源赋值给Navigation/NavDestination的title及menu接口 41Navigation() { 42 // xxx 43} 44.title($r('app.string.MyTestNavigationTitle')) // 可直接将resource类型资源传递给title接口 45// menus内的item设置可直接支持resource类型资源 46.menus([ 47 { 48 value: $r("app.string.MyTestMenuValue1"), 49 icon: $r("app.media.1") 50 }, 51 { 52 value: $r("app.string.MyTestMenuValue2"), 53 icon: $r("app.media.2") 54 }, 55 { 56 value: $r("app.string.MyTestMenuValue3"), 57 icon: $r("app.media.3") 58 } 59]) 60``` 61 62 63``` 64// navDestination.ets 65// Navigation及NavDestination的CommonTitle类型,支持设置resource资源 66@State commonTitle: NavDestinationCommonTitle = { main: $r('app.string.MyTestNavigationTitle'), sub: $r('app.string.MyTestNavigationTitle')} 67NavDestination() { 68 // xxx 69} 70.menus([ 71 { 72 value: $r("app.string.MyTestMenuValue1"), 73 icon: $r("app.media.4") 74 }, 75 { 76 value: $r("app.string.MyTestMenuValue2"), 77 icon: $r("app.media.5") 78 }, 79 { 80 value: $r("app.string.MyTestMenuValue3"), 81 icon: $r("app.media.6") 82 } 83]) 84.title(this.commonTitle) 85``` 86 87## cl.arkui.2 优化状态变量场景下ForEach的冗余刷新行为 88 89**访问级别** 90 91公开接口 92 93**变更原因** 94 95开发者使用ForEach,在旧节点下树的时候会被刷新一次,属于规格外的行为,当刷新调用方法中存在对全局变量的修改时会发生异常。 96 97**变更影响** 98 99该变更为不兼容变更。 100 101变更前:开发者在使用ForEach时,节点下树的时候会被刷新一次。 102 103变更后:开发者在使用ForEach时,节点下树的时候不会被刷新。 104 105**起始API Level** 106 1079 108 109**变更发生版本** 110 111从OpenHarmony SDK 5.0.0.42开始。 112 113**变更的接口/组件** 114 115ForEach 116 117**适配指导** 118 119之前使用ForEach涉及节点刷新时调用的方法存在对全局变量值修改的,需要根据具体情况对代码进行相应的修改,使当前修改等效于原来的两次修改叠加,以保证效果不变。 120 121示例: 122 123变更前: 124```ts 125let g_data = 0; 126 127@Entry 128@Component 129struct MyComponent { 130 @State simpleList: number[] = [0, 1, 2] 131 132 fn(item: number, index: number) { 133 g_data++; 134 return 80; 135 } 136 137 build() { 138 Row() { 139 Column() { 140 Button('click button []') 141 .onClick(() => { 142 this.simpleList = [4, 5, 6] 143 }) 144 ForEach(this.simpleList, (item: number, index: number) => { 145 Text(item.toString()) 146 .fontSize(this.fn(item, index)) 147 .onAppear(()=>{ 148 console.log('g_data: ' + g_data); 149 }) 150 }, (item: string) => item) 151 } 152 .width('100%') 153 .height('100%') 154 } 155 } 156} 157``` 158 159变更后: 160```ts 161let g_data = 0; 162 163@Entry 164@Component 165struct MyComponent { 166 @State simpleList: number[] = [0, 1, 2] 167 168 fn(item: number, index: number) { 169 // 变更前总会调用两次,变更后只会调用一次,保证变更前后效果一致 170 g_data+=2; 171 return 80; 172 } 173 174 build() { 175 Row() { 176 Column() { 177 Button('click button []') 178 .onClick(() => { 179 this.simpleList = [4, 5, 6] 180 }) 181 ForEach(this.simpleList, (item: number, index: number) => { 182 Text(item.toString()) 183 .fontSize(this.fn(item, index)) 184 .onAppear(()=>{ 185 console.log('g_data: ' + g_data); 186 }) 187 }, (item: string) => item) 188 } 189 .width('100%') 190 .height('100%') 191 } 192 } 193} 194```