!47865 fix segmentbutton focus bug

Merge pull request !47865 from zhaoyong/segmentbutton
This commit is contained in:
openharmony_ci 2024-11-10 00:59:13 +00:00 committed by Gitee
commit d747b6ceee
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 27 additions and 14 deletions

View File

@ -261,7 +261,7 @@ let SegmentButtonOptions = o = class SegmentButtonOptions {
this.buttons = new SegmentButtonItemOptionsArray(options.buttons);
if (this.type === 'capsule') {
this.multiply = options.multiply ?? false;
this.n2();
this.w3();
this.selectedFontColor = options.selectedFontColor ?? e1.t1;
this.selectedBackgroundColor = options.selectedBackgroundColor ??
e1.z1;
@ -270,7 +270,8 @@ let SegmentButtonOptions = o = class SegmentButtonOptions {
}
this.m2 = this.multiply ? 0 : 2;
}
n2() {
w3() {
this.buttons?.forEach(button => {
this.i2 ||= button.text !== void 0;
this.showIcon ||= button.icon !== void 0 || button.selectedIcon !== void 0;
@ -1104,6 +1105,7 @@ class m1 extends ViewPU {
this.t3 = new ObservedPropertyObjectPU(Array.from({ length: a1 }, (i3, index) => 0), this, "buttonHeight");
this.buttonItemsRealHeight = Array.from({ length: a1 }, (h3, index) => 0);
this.groupId = util.generateRandomUUID(true);
this.onItemClicked = undefined;
this.setInitiallyProvidedValue(params);
this.declareWatch("optionsArray", this.onOptionsArrayChange);
this.declareWatch("options", this.onOptionsChange);
@ -1126,6 +1128,9 @@ class m1 extends ViewPU {
if (params.groupId !== undefined) {
this.groupId = params.groupId;
}
if (params.onItemClicked !== undefined) {
this.onItemClicked = params.onItemClicked;
}
}
updateStateVars(params) {
@ -1562,6 +1567,9 @@ class m1 extends ViewPU {
Gesture.create(GesturePriority.Low);
TapGesture.create();
TapGesture.onAction(() => {
if (this.onItemClicked) {
this.onItemClicked(index);
}
if (this.options.type === 'capsule' &&
(this.options.multiply ?? false)) {
if (this.selectedIndexes.indexOf(index) === -1) {
@ -1658,7 +1666,7 @@ class m1 extends ViewPU {
}, undefined, elmtId, () => {
}, {
page: "segmentbutton/src/main/ets/components/MainPage.ets",
line: 817,
line: 818,
u3: 15
});
ViewPU.create(componentCall);
@ -2025,7 +2033,7 @@ export class SegmentButton extends ViewPU {
return;
}
if (this.options.type === 'capsule') {
this.options.n2();
this.options.w3();
}
if (this.doSelectedChangeAnimate) {
this.updateAnimatedProperty(this.getSelectedChangeCurve());
@ -2166,7 +2174,6 @@ export class SegmentButton extends ViewPU {
GestureGroup.create(GestureMode.Parallel);
TapGesture.create();
TapGesture.onAction((event) => {
this.focusIndex = -1;
let a2 = event.fingerList.find(Boolean);
if (a2 === void 0) {
return;
@ -2352,7 +2359,7 @@ export class SegmentButton extends ViewPU {
}, undefined, elmtId, () => {
}, {
page: "segmentbutton/src/main/ets/components/MainPage.ets",
line: 1121,
line: 1124,
u3: 11
});
ViewPU.create(componentCall);
@ -2424,7 +2431,7 @@ export class SegmentButton extends ViewPU {
}, undefined, elmtId, () => {
}, {
page: "segmentbutton/src/main/ets/components/MainPage.ets",
line: 1132,
line: 1135,
u3: 23
});
ViewPU.create(componentCall);
@ -2501,7 +2508,7 @@ export class SegmentButton extends ViewPU {
}, undefined, elmtId, () => {
}, {
page: "segmentbutton/src/main/ets/components/MainPage.ets",
line: 1158,
line: 1161,
u3: 13
});
ViewPU.create(componentCall);
@ -2534,7 +2541,7 @@ export class SegmentButton extends ViewPU {
}, undefined, elmtId, () => {
}, {
page: "segmentbutton/src/main/ets/components/MainPage.ets",
line: 1164,
line: 1167,
u3: 13
});
ViewPU.create(componentCall);
@ -2569,9 +2576,10 @@ export class SegmentButton extends ViewPU {
optionsArray: this.options.buttons,
options: this.options,
selectedIndexes: this.t2,
maxFontScale: this.getMaxFontSize()
maxFontScale: this.getMaxFontSize(),
onItemClicked: this.onItemClicked
}, undefined, elmtId, () => {
}, { page: "segmentbutton/src/main/ets/components/MainPage.ets", line: 1179, u3: 9 });
}, { page: "segmentbutton/src/main/ets/components/MainPage.ets", line: 1182, u3: 9 });
ViewPU.create(componentCall);
let paramsLambda = () => {
return {
@ -2581,7 +2589,8 @@ export class SegmentButton extends ViewPU {
optionsArray: this.options.buttons,
options: this.options,
selectedIndexes: this.selectedIndexes,
maxFontScale: this.getMaxFontSize()
maxFontScale: this.getMaxFontSize(),
onItemClicked: this.onItemClicked
};
};
componentCall.paramsGenerator_ = paramsLambda;

View File

@ -627,6 +627,7 @@ struct SegmentButtonItemArrayComponent {
@State buttonHeight: number[] = Array.from({ length: MAX_ITEM_COUNT }, (_: Object, index) => 0)
private buttonItemsRealHeight: number[] = Array.from({ length: MAX_ITEM_COUNT }, (_: Object, index) => 0)
private groupId: string = util.generateRandomUUID(true)
public onItemClicked?: Callback<number>
onButtonItemsSizeChange() {
this.buttonItemsSize.forEach((value, index) => {
@ -877,6 +878,9 @@ struct SegmentButtonItemArrayComponent {
this.focusIndex = index
})
.gesture(TapGesture().onAction(() => {
if (this.onItemClicked) {
this.onItemClicked(index)
}
if (this.options.type === 'capsule' && (this.options.multiply ?? false)) {
if (this.selectedIndexes.indexOf(index) === -1) {
this.selectedIndexes.push(index)
@ -1182,7 +1186,8 @@ export struct SegmentButton {
optionsArray: this.options.buttons,
options: this.options,
selectedIndexes: $selectedIndexes,
maxFontScale: this.getMaxFontSize()
maxFontScale: this.getMaxFontSize(),
onItemClicked: this.onItemClicked
})
}
}
@ -1217,7 +1222,6 @@ export struct SegmentButton {
GestureGroup(GestureMode.Parallel,
TapGesture()
.onAction((event: GestureEvent) => {
this.focusIndex = -1
let fingerInfo = event.fingerList.find(Boolean)
if (fingerInfo === void 0) {
return