1# ArkUI子系统Changelog 2 3## cl.arkui.1 DatePicker、DatePickerDialog、TextPicker、TextPickerDialog支持设置触控反馈(声音和振动)效果 4 5**访问级别** 6 7公开接口 8 9**变更原因** 10 11UX规范变更。 12 13**变更影响** 14 15此变更不涉及应用适配,建议保持系统默认效果。 16 17- 变更前:在滑动选项时,DatePicker、DatePickerDialog、TextPicker、TextPickerDialog组件无触控反馈(声音和振动)效果。 18 19- 变更后:在快速滑动选项时,DatePicker、DatePickerDialog、TextPicker、TextPickerDialog组件均匀触发声音和振动效果。在滑动选项居中时,DatePicker、DatePickerDialog、TextPicker、TextPickerDialog组件触发一次声音和振动效果。 20 21**起始API Level** 22 238 24 25**变更发生版本** 26 27从OpenHarmony SDK 5.1.0.51开始。 28 29**适配指导** 30 31DatePicker、DatePickerDialog、TextPicker、TextPickerDialog默认支持触控反馈(声音和振动)效果,开发者可以通过如下代码关闭组件的触控反馈效果。如果开发者有自实现触控反馈,建议只保留一种,推荐使用组件的触控反馈。 32```ts 33@Entry 34@Component 35struct PickerHapticFeedbackExample { 36 private fruits: string[] = ['apple1', 'orange2', 'peach3', 'grape4'] 37 build() { 38 Row() { 39 Column() { 40 DatePicker() 41 .enableHapticFeedback(false) //DatePicker设置关闭反馈效果 42 43 Button("DatePickerDialog") 44 .onClick(() => { 45 DatePickerDialog.show({ 46 enableHapticFeedback: false, //DatePickerDialog设置关闭反馈效果 47 }) 48 }) 49 50 TextPicker({ range: this.fruits }) 51 .enableHapticFeedback(false) //TextPicker设置关闭反馈效果 52 53 Button("TextPickerDialog") 54 .onClick(() => { 55 TextPickerDialog.show({ 56 range: this.fruits, 57 enableHapticFeedback: false, //TextPickerDialog设置关闭反馈效果 58 }) 59 }) 60 }.width('100%') 61 }.height('100%') 62 } 63} 64``` 65 66## cl.arkui.2 TextController的SetStyledString接口支持保存设置的属性字符串信息到调用的TextController中 67 68**访问级别** 69 70公开接口 71 72**变更原因** 73 74优化属性字符串与Text组件的绑定时机。 75 76**变更影响** 77 78此变更涉及应用适配。 79 80- 变更前:开发者调用TextController的setStyledString接口设置属性字符串时,如果调用时TextController还未绑定对应的Text,则此次设置无效。 81 82- 变更后:开发者调用TextController的setStyledString接口时,调用的TextController会保存设置的属性字符串。当TextController和Text绑定时,如果TextController中已经存储之前调用setStyledString接口保存的属性字符串,则Text会自动设置保存的属性字符串,显示出对应的属性字符串。 83 84**起始API Level** 85 8612 87 88**变更发生版本** 89 90从OpenHarmony SDK 5.1.0.51开始,API version 15及以上生效。 91 92**适配指导** 93 94变更后对setStyledString的接口的调用可以更加灵活,Text能够正确地显示出属性字符串。 95```ts 96@Entry 97@Component 98struct StyledStringExample { 99 controller: TextController = new TextController() 100 101 aboutToAppear(): void { 102 this.controller.setStyledString(new StyledString("123456")) // 变更前,由于此时controller还未和Text绑定,此次设置不生效。变更后,属性字符串可以正确的显示 103 } 104 105 build() { 106 Row() { 107 Column() { 108 Text(undefined, {controller: this.controller}) 109 }.width('100%') 110 }.height('100%') 111 } 112} 113``` 114 115## cl.arkui.3 Image、Text和ListItem组件onDragStart接口默认行为变更 116 117**访问级别** 118 119公开接口 120 121**变更原因** 122 123Image、Text和ListItem组件存在设置onDragStart接口DragItemInfo返回值中的builder属性后,返回值中pixelMap和extraInfo属性不生效的问题。 124 125**变更影响** 126 127此变更涉及应用适配,只涉及Image、Text和ListItem组件。 128 129- 变更前:onDragStart接口设置返回值中的builder属性后,无法解析pixelMap和extraInfo属性。 130 131- 变更后:onDragStart接口设置返回值中的builder属性后,能够解析pixelMap和extraInfo属性。 132 133**起始API Level** 134 13511 136 137**变更发生版本** 138 139从OpenHarmony SDK 5.1.0.51开始, API15及以上生效。 140 141**变更的接口/组件** 142 143涉及组件: Image, Text, ListItem组件。 144 145涉及接口: onDragStart(event: (event: DragEvent, extraParams?: string) => CustomBuilder | DragItemInfo) 146 147**适配指导** 148 149onDragStart接口的返回值用于指定拖拽过程中显示的图片(pixelMap,builder)以及拖拽过程中组件携带的额外信息(extraInfo)。变更后,pixelMap的显示优先级高于builder。如果开发者同时设置了pixelMap和builder,应移除返回值中的pixelMap属性。同样,若不打算传递extraInfo,也应删除该属性。具体实现代码如下: 150```ts 151@Entry 152@Component 153struct SlideExample { 154 build() { 155 Row() { 156 Image() 157 .onDragStart((event) => { 158 return { 159 builder: () => { this.pixelMapBuilder }, 160 // 若需要拖拽显示builder,需要移除掉pixelMap属性的赋值。 161 // pixelMap:this.pixelMap, 162 // 若设置了builder并且不需要传递extraInfo,需要移除掉extraInfo属性的赋值。 163 // extraInfo: "test" 164 } 165 }) 166 }.height('100%') 167 } 168} 169``` 170 171## cl.arkui.4 NavDestination新增对OnActive/OnInactive生命周期监听 172 173**访问级别** 174 175公开接口 176 177**变更原因** 178 179新增[NavDestination](../../../application-dev/reference/apis-arkui/arkui-ts/ts-basic-components-navdestination.md)的onActive、onInactive生命周期回调,增加[observer](../../../application-dev/reference/apis-arkui/js-apis-arkui-observer.md)中navDestination中对该状态的监听。 180 181**变更影响** 182 183此变更涉及应用适配。 184 185|生命周期回调|变更前|变更后| 186|---|---|---| 187|ON_WILL_APPEAR| 支持 | 支持 | 188|ON_APPEAR|支持|支持| 支持 | 189|ON_WILL_SHOW|支持|支持| 190|ON_SHOWN|支持|支持| 191|ON_ACTIVE|不支持|支持| 192|ON_WILL_HIDE|支持|支持| 193|ON_INACTIVE|不支持|支持| 194|ON_HIDDEN|支持|支持| 195|ON_WILL_DISAPPEAR|支持|支持| 196|ON_DISAPPEAR|支持|支持| 197 198变更前: 199运行如下示例代码: 200```ts 201// observer 202import {uiObserver} from '@kit.ArkUI' 203@Entry 204@Component 205struct ObserverExample { 206 aboutToAppear() { 207 uiObserver.on('navDestinationUpdate', (info: NavDestinationInfo) => { 208 const states: Array<uiObserver.NavDestinationState> = [ 209 uiObserver.NavDestinationState.ON_WILL_APPEAR, 210 uiObserver.NavDestinationState.ON_APPEAR, 211 uiObserver.NavDestinationState.ON_WILL_SHOW, 212 uiObserver.NavDestinationState.ON_SHOWN, 213 uiObserver.NavDestinationState.ON_WILL_HIDE, 214 uiObserver.NavDestinationState.ON_HIDDEN, 215 uiObserver.NavDestinationState.ON_WILL_DISAPPEAR, 216 uiObserver.NavDestinationState.ON_DISAPPEAR 217 ] 218 if (states.indexOf(info.state) === -1){ 219 console.log("state is invalid") 220 } 221 }) 222 } 223 224 build() {} 225} 226``` 227observer.on('navDestinationUpdate', (info: NavDestinationState) => {})中不会触发NavDestinationState.ON_ACTIVE以及NavDestinationState.ON_INACTIVE的回调。 228 229变更后: 在observer.on中添加对新增的生命周期函数onActive和onInactive的通知,可能会导致开发者在处理生命周期之外的枚举值时出现异常。 230 231**起始API Level** 232 233API Version 12 234 235**变更发生版本** 236 237从OpenHarmony SDK 5.1.0.51开始。 238 239**变更的接口/组件** 240 241observer 242 243**适配指导** 244 245对于observer监听状态的处理,如果需要拦截NavDestination生命周期之外的值,应将新增的生命周期添加到拦截值之外,但是该方式可能会导致后续NavDestination新增生命周期再次适配,推荐采用处理传入生命周期中的合法状态值处理的方式。 246 247```ts 248// observer 249import {uiObserver} from '@kit.ArkUI' 250@Entry 251@Component 252struct ObserverExample { 253 aboutToAppear() { 254 uiObserver.on('navDestinationUpdate', (info: NavDestinationInfo) => { 255 if (info.state === uiObserver.NavDestinationState.ON_WILL_APPEAR) { 256 // 处理onWillAppear事件 257 } 258 if (info.state === uiObserver.NavDestinationState.ON_APPEAR) { 259 // 处理onAppear事件 260 } 261 if (info.state === uiObserver.NavDestinationState.ON_WILL_SHOW) { 262 // 处理onWillShow事件 263 } 264 if (info.state === uiObserver.NavDestinationState.ON_ACTIVE) { 265 // 处理onActive事件 266 } 267 if (info.state === uiObserver.NavDestinationState.ON_SHOWN) { 268 // 处理onShown事件 269 } 270 if (info.state === uiObserver.NavDestinationState.ON_WILL_HIDE) { 271 // 处理onWillHide事件 272 } 273 if (info.state == uiObserver.NavDestinationState.ON_INACTIVE) { 274 // 处理onInactive事件 275 } 276 if (info.state == uiObserver.NavDestinationState.ON_HIDDEN) { 277 // 处理onHidden事件 278 } 279 if (info.state == uiObserver.NavDestinationState.ON_WILL_DISAPPEAR) { 280 // 处理onWillDisappear事件 281 } 282 if (info.state == uiObserver.NavDestinationState.ON_DISAPPEAR) { 283 // 处理onDisappear事件 284 } 285 }) 286 } 287 build() {} 288} 289```