!4546 【Sample】【Radio】Radio单选按钮添加热区后,点击所在行没有选中

Merge pull request !4546 from YangXin/ComponentCollections0626
This commit is contained in:
openharmony_ci 2024-06-27 05:44:08 +00:00 committed by Gitee
commit b800f22851
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -32,6 +32,8 @@ struct RadioSample {
@State noResponseRegionIndex: number = 0;
private context: Context = getContext(this);
private cityNames: Resource[] = [$r('app.string.radio_beijing'), $r('app.string.radio_shanghai'), $r('app.string.radio_guangzhou'), $r('app.string.radio_shenzhen')];
private widthValue: number = 20;
private heightValue: number = 48;
build() {
Column() {
@ -63,10 +65,12 @@ struct RadioSample {
ForEach(this.cityNames, (item: Resource, index: number) => {
Row() {
Radio({ value: this.context.resourceManager.getStringSync(item), group: 'responseRegion' })
.size({ width: 20, height: 20 })
.size({ width: this.widthValue, height: this.heightValue })
.checked(this.responseRegionIndex === index)
.responseRegion({
width: this.radioItemWidth, // Get response region with equals radio item width
x: 0,
y: 0,
width: this.radioItemWidth * (100 / this.widthValue) + '%',
height: '100%'
})
.onChange((isChecked: boolean) => {
@ -77,9 +81,7 @@ struct RadioSample {
})
.id('cityHot' + String(index))
Text(item)
.width(this.radioItemWidth)
.height(48)
.responseRegion({ width: 0, height: 0 }) // Make this text has no response region
.height(this.heightValue)
}
.width('100%')
.margin({ bottom: 6 })