1# arkui子系统ChangeLog 2 3## cl.arkui.1 状态变量数据类型声明使用限制。 4 5所有的状态装饰器变量需要显式声明变量类型,不允许声明any。 6 7**示例:** 8 9```ts 10// xxx.ets 11@Entry 12@Component 13struct DatePickerExample { 14 // 错误写法: @State isLunar: any = false 15 @State isLunar: boolean = false 16 17 build() { 18 ... 19 } 20} 21``` 22 23**变更影响** 24 25如果状态装饰器变量没有显式声明变量类型,声明any,编译拦截等级由WARN变成ERROR。 26 27```ts 28// ArkTS:ERROR Please define an explicit type, not any. 29@State isLunar: any = false 30``` 31 32**关键的接口/组件变更** 33 34不涉及。 35 36**适配指导** 37 38状态装饰器变量声明具体的变量类型替代any。 39 40## cl.arkui.2 自定义组件成员变量初始化的规则与约束。 41 42不允许从父组件初始化`@LocalStorageLink`, `@LocalStorageProp`修饰的变量。 43 44**示例:** 45 46```ts 47let NextID: number = 0; 48 49@Observed 50class ClassA { 51 public id: number; 52 public c: number; 53 54 constructor(c: number) { 55 this.id = NextID++; 56 this.c = c; 57 } 58} 59 60@Entry 61@Component 62struct LocalStorageComponent { 63 build() { 64 Column() { 65 Child({ 66 /* ArkTS:ERROR Property 'simpleVarName' in the custom component 'Child' cannot 67 initialize here (forbidden to specify). */ 68 simpleVarName: 1, 69 /* ArkTS:ERROR Property 'objectName' in the custom component 'Child' cannot 70 initialize here (forbidden to specify). */ 71 objectName: new ClassA(1) 72 }) 73 } 74 } 75} 76 77@Component 78struct Child { 79 @LocalStorageLink("storageSimpleProp") simpleVarName: number = 0; 80 @LocalStorageProp("storageObjectProp") objectName: ClassA = new ClassA(1); 81 82 build() { 83 } 84} 85``` 86 87**变更影响** 88 89如果父组件初始化`@LocalStorageLink`, `@LocalStorageProp`修饰的变量,编译拦截等级由WARN变成ERROR。 90 91**关键的接口/组件变更** 92 93不涉及。 94 95**适配指导** 96 97构造子组件时,不对子组件的`@LocalStorageLink`, `@LocalStorageProp`修饰的变量进行赋值。 98 99如果需要在父组件中修改子组件的`@LocalStorageLink`, `@LocalStorageProp`修饰的变量,则使用LocalStorage提供的API接口方法(比如set方法)赋值。 100 101## cl.arkui.3 PromptAction模块中,文本提示框toast的bottom属性含义变更。 102 103文本提示框toast的bottom属性值的含义,从文本提示框上边沿到屏幕下边沿,变更为文本提示框下边沿到屏幕下边沿。 104 105**示例:** 106 107```ts 108import promptAction from '@ohos.promptAction'; 109@Entry 110@Component 111struct Index { 112 build() { 113 Row() { 114 Button() 115 .onClick(() => { 116 try { 117 promptAction.showToast({ 118 message: 'Message Info', 119 duration: 2000 120 }); 121 } catch (error) { 122 console.error(`showToast args error code is ${error.code}, message is ${error.message}`); 123 }; 124 }) 125 } 126 } 127} 128``` 129 130**变更影响** 131 132PromptAction模块中,文本提示框toast的bottom属性设置同样的数值,会由于编译器所使用的API版本是否为API version 10+而有所差异。 133 134**关键的接口/组件变更** 135 136不涉及。 137 138**适配指导** 139 140编译器采用API version 9或以往版本以保持之前的样式,或者采用API version 10及以上版本以采用新样式。 141 142## cl.arkui.4 AlertDialog控件内容布局变更。 143 144AlertDialog的内容属性部分会根据:1)有无标题title,2)是否为单行文本,条件不同而布局有所不同。 145 146目前规格:仅无标题title的单行文本情况下为居中,其余情况文本左对齐。 147 148**示例:** 149 150```ts 151// xxx.ets 152@Entry 153@Component 154struct AlertDialogExample { 155 build() { 156 Column({ space: 5 }) { 157 Button('one button dialog') 158 .onClick(() => { 159 AlertDialog.show( 160 { 161 title: 'title', 162 message: 'text'.repeat(20), 163 autoCancel: true, 164 alignment: DialogAlignment.Bottom, 165 offset: { dx: 0, dy: -20 }, 166 gridCount: 3, 167 confirm: { 168 value: 'button', 169 action: () => { 170 console.info('Button-clicking callback') 171 } 172 }, 173 cancel: () => { 174 console.info('Closed callbacks') 175 } 176 } 177 ) 178 }) 179 .backgroundColor(0x317aff) 180 }.width('100%').margin({ top: 5 }) 181 } 182} 183``` 184 185**变更影响** 186 187AlertDialog控件message属性对应的文本内容,布局效果变更。 188 189**关键的接口/组件变更** 190 191不涉及。 192 193**适配指导** 194 195无需主动适配,或者可以使用customDialog做相关实现。 196 197## cl.arkui.5 popup避让行为优化。 198 199变更前,popup发生避让优先在下方空间找位置,导致在上方空间充足也无法设置在上方显示。 200 201目前规格:根据开发者设置,若设置在上方,优先在上方空间找位置;若设置在下方,优先在上下方空间找位置。 202 203**变更影响** 204 205使用bindpopup属性,气泡避让行为优化。 206 207**关键的接口/组件变更** 208 209不涉及。 210 211**适配指导** 212 213若发现使用场景中,使用bindpopup属性,气泡出现位置与之前发生上下位置变化,可通过调整placement恢复。