mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 07:01:24 +00:00
!47865 fix segmentbutton focus bug
Merge pull request !47865 from zhaoyong/segmentbutton
This commit is contained in:
commit
d747b6ceee
@ -261,7 +261,7 @@ let SegmentButtonOptions = o = class SegmentButtonOptions {
|
|||||||
this.buttons = new SegmentButtonItemOptionsArray(options.buttons);
|
this.buttons = new SegmentButtonItemOptionsArray(options.buttons);
|
||||||
if (this.type === 'capsule') {
|
if (this.type === 'capsule') {
|
||||||
this.multiply = options.multiply ?? false;
|
this.multiply = options.multiply ?? false;
|
||||||
this.n2();
|
this.w3();
|
||||||
this.selectedFontColor = options.selectedFontColor ?? e1.t1;
|
this.selectedFontColor = options.selectedFontColor ?? e1.t1;
|
||||||
this.selectedBackgroundColor = options.selectedBackgroundColor ??
|
this.selectedBackgroundColor = options.selectedBackgroundColor ??
|
||||||
e1.z1;
|
e1.z1;
|
||||||
@ -270,7 +270,8 @@ let SegmentButtonOptions = o = class SegmentButtonOptions {
|
|||||||
}
|
}
|
||||||
this.m2 = this.multiply ? 0 : 2;
|
this.m2 = this.multiply ? 0 : 2;
|
||||||
}
|
}
|
||||||
n2() {
|
|
||||||
|
w3() {
|
||||||
this.buttons?.forEach(button => {
|
this.buttons?.forEach(button => {
|
||||||
this.i2 ||= button.text !== void 0;
|
this.i2 ||= button.text !== void 0;
|
||||||
this.showIcon ||= button.icon !== void 0 || button.selectedIcon !== 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.t3 = new ObservedPropertyObjectPU(Array.from({ length: a1 }, (i3, index) => 0), this, "buttonHeight");
|
||||||
this.buttonItemsRealHeight = Array.from({ length: a1 }, (h3, index) => 0);
|
this.buttonItemsRealHeight = Array.from({ length: a1 }, (h3, index) => 0);
|
||||||
this.groupId = util.generateRandomUUID(true);
|
this.groupId = util.generateRandomUUID(true);
|
||||||
|
this.onItemClicked = undefined;
|
||||||
this.setInitiallyProvidedValue(params);
|
this.setInitiallyProvidedValue(params);
|
||||||
this.declareWatch("optionsArray", this.onOptionsArrayChange);
|
this.declareWatch("optionsArray", this.onOptionsArrayChange);
|
||||||
this.declareWatch("options", this.onOptionsChange);
|
this.declareWatch("options", this.onOptionsChange);
|
||||||
@ -1126,6 +1128,9 @@ class m1 extends ViewPU {
|
|||||||
if (params.groupId !== undefined) {
|
if (params.groupId !== undefined) {
|
||||||
this.groupId = params.groupId;
|
this.groupId = params.groupId;
|
||||||
}
|
}
|
||||||
|
if (params.onItemClicked !== undefined) {
|
||||||
|
this.onItemClicked = params.onItemClicked;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateStateVars(params) {
|
updateStateVars(params) {
|
||||||
@ -1562,6 +1567,9 @@ class m1 extends ViewPU {
|
|||||||
Gesture.create(GesturePriority.Low);
|
Gesture.create(GesturePriority.Low);
|
||||||
TapGesture.create();
|
TapGesture.create();
|
||||||
TapGesture.onAction(() => {
|
TapGesture.onAction(() => {
|
||||||
|
if (this.onItemClicked) {
|
||||||
|
this.onItemClicked(index);
|
||||||
|
}
|
||||||
if (this.options.type === 'capsule' &&
|
if (this.options.type === 'capsule' &&
|
||||||
(this.options.multiply ?? false)) {
|
(this.options.multiply ?? false)) {
|
||||||
if (this.selectedIndexes.indexOf(index) === -1) {
|
if (this.selectedIndexes.indexOf(index) === -1) {
|
||||||
@ -1658,7 +1666,7 @@ class m1 extends ViewPU {
|
|||||||
}, undefined, elmtId, () => {
|
}, undefined, elmtId, () => {
|
||||||
}, {
|
}, {
|
||||||
page: "segmentbutton/src/main/ets/components/MainPage.ets",
|
page: "segmentbutton/src/main/ets/components/MainPage.ets",
|
||||||
line: 817,
|
line: 818,
|
||||||
u3: 15
|
u3: 15
|
||||||
});
|
});
|
||||||
ViewPU.create(componentCall);
|
ViewPU.create(componentCall);
|
||||||
@ -2025,7 +2033,7 @@ export class SegmentButton extends ViewPU {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.options.type === 'capsule') {
|
if (this.options.type === 'capsule') {
|
||||||
this.options.n2();
|
this.options.w3();
|
||||||
}
|
}
|
||||||
if (this.doSelectedChangeAnimate) {
|
if (this.doSelectedChangeAnimate) {
|
||||||
this.updateAnimatedProperty(this.getSelectedChangeCurve());
|
this.updateAnimatedProperty(this.getSelectedChangeCurve());
|
||||||
@ -2166,7 +2174,6 @@ export class SegmentButton extends ViewPU {
|
|||||||
GestureGroup.create(GestureMode.Parallel);
|
GestureGroup.create(GestureMode.Parallel);
|
||||||
TapGesture.create();
|
TapGesture.create();
|
||||||
TapGesture.onAction((event) => {
|
TapGesture.onAction((event) => {
|
||||||
this.focusIndex = -1;
|
|
||||||
let a2 = event.fingerList.find(Boolean);
|
let a2 = event.fingerList.find(Boolean);
|
||||||
if (a2 === void 0) {
|
if (a2 === void 0) {
|
||||||
return;
|
return;
|
||||||
@ -2352,7 +2359,7 @@ export class SegmentButton extends ViewPU {
|
|||||||
}, undefined, elmtId, () => {
|
}, undefined, elmtId, () => {
|
||||||
}, {
|
}, {
|
||||||
page: "segmentbutton/src/main/ets/components/MainPage.ets",
|
page: "segmentbutton/src/main/ets/components/MainPage.ets",
|
||||||
line: 1121,
|
line: 1124,
|
||||||
u3: 11
|
u3: 11
|
||||||
});
|
});
|
||||||
ViewPU.create(componentCall);
|
ViewPU.create(componentCall);
|
||||||
@ -2424,7 +2431,7 @@ export class SegmentButton extends ViewPU {
|
|||||||
}, undefined, elmtId, () => {
|
}, undefined, elmtId, () => {
|
||||||
}, {
|
}, {
|
||||||
page: "segmentbutton/src/main/ets/components/MainPage.ets",
|
page: "segmentbutton/src/main/ets/components/MainPage.ets",
|
||||||
line: 1132,
|
line: 1135,
|
||||||
u3: 23
|
u3: 23
|
||||||
});
|
});
|
||||||
ViewPU.create(componentCall);
|
ViewPU.create(componentCall);
|
||||||
@ -2501,7 +2508,7 @@ export class SegmentButton extends ViewPU {
|
|||||||
}, undefined, elmtId, () => {
|
}, undefined, elmtId, () => {
|
||||||
}, {
|
}, {
|
||||||
page: "segmentbutton/src/main/ets/components/MainPage.ets",
|
page: "segmentbutton/src/main/ets/components/MainPage.ets",
|
||||||
line: 1158,
|
line: 1161,
|
||||||
u3: 13
|
u3: 13
|
||||||
});
|
});
|
||||||
ViewPU.create(componentCall);
|
ViewPU.create(componentCall);
|
||||||
@ -2534,7 +2541,7 @@ export class SegmentButton extends ViewPU {
|
|||||||
}, undefined, elmtId, () => {
|
}, undefined, elmtId, () => {
|
||||||
}, {
|
}, {
|
||||||
page: "segmentbutton/src/main/ets/components/MainPage.ets",
|
page: "segmentbutton/src/main/ets/components/MainPage.ets",
|
||||||
line: 1164,
|
line: 1167,
|
||||||
u3: 13
|
u3: 13
|
||||||
});
|
});
|
||||||
ViewPU.create(componentCall);
|
ViewPU.create(componentCall);
|
||||||
@ -2569,9 +2576,10 @@ export class SegmentButton extends ViewPU {
|
|||||||
optionsArray: this.options.buttons,
|
optionsArray: this.options.buttons,
|
||||||
options: this.options,
|
options: this.options,
|
||||||
selectedIndexes: this.t2,
|
selectedIndexes: this.t2,
|
||||||
maxFontScale: this.getMaxFontSize()
|
maxFontScale: this.getMaxFontSize(),
|
||||||
|
onItemClicked: this.onItemClicked
|
||||||
}, undefined, elmtId, () => {
|
}, 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);
|
ViewPU.create(componentCall);
|
||||||
let paramsLambda = () => {
|
let paramsLambda = () => {
|
||||||
return {
|
return {
|
||||||
@ -2581,7 +2589,8 @@ export class SegmentButton extends ViewPU {
|
|||||||
optionsArray: this.options.buttons,
|
optionsArray: this.options.buttons,
|
||||||
options: this.options,
|
options: this.options,
|
||||||
selectedIndexes: this.selectedIndexes,
|
selectedIndexes: this.selectedIndexes,
|
||||||
maxFontScale: this.getMaxFontSize()
|
maxFontScale: this.getMaxFontSize(),
|
||||||
|
onItemClicked: this.onItemClicked
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
componentCall.paramsGenerator_ = paramsLambda;
|
componentCall.paramsGenerator_ = paramsLambda;
|
||||||
|
@ -627,6 +627,7 @@ struct SegmentButtonItemArrayComponent {
|
|||||||
@State buttonHeight: number[] = Array.from({ length: MAX_ITEM_COUNT }, (_: Object, index) => 0)
|
@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 buttonItemsRealHeight: number[] = Array.from({ length: MAX_ITEM_COUNT }, (_: Object, index) => 0)
|
||||||
private groupId: string = util.generateRandomUUID(true)
|
private groupId: string = util.generateRandomUUID(true)
|
||||||
|
public onItemClicked?: Callback<number>
|
||||||
|
|
||||||
onButtonItemsSizeChange() {
|
onButtonItemsSizeChange() {
|
||||||
this.buttonItemsSize.forEach((value, index) => {
|
this.buttonItemsSize.forEach((value, index) => {
|
||||||
@ -877,6 +878,9 @@ struct SegmentButtonItemArrayComponent {
|
|||||||
this.focusIndex = index
|
this.focusIndex = index
|
||||||
})
|
})
|
||||||
.gesture(TapGesture().onAction(() => {
|
.gesture(TapGesture().onAction(() => {
|
||||||
|
if (this.onItemClicked) {
|
||||||
|
this.onItemClicked(index)
|
||||||
|
}
|
||||||
if (this.options.type === 'capsule' && (this.options.multiply ?? false)) {
|
if (this.options.type === 'capsule' && (this.options.multiply ?? false)) {
|
||||||
if (this.selectedIndexes.indexOf(index) === -1) {
|
if (this.selectedIndexes.indexOf(index) === -1) {
|
||||||
this.selectedIndexes.push(index)
|
this.selectedIndexes.push(index)
|
||||||
@ -1182,7 +1186,8 @@ export struct SegmentButton {
|
|||||||
optionsArray: this.options.buttons,
|
optionsArray: this.options.buttons,
|
||||||
options: this.options,
|
options: this.options,
|
||||||
selectedIndexes: $selectedIndexes,
|
selectedIndexes: $selectedIndexes,
|
||||||
maxFontScale: this.getMaxFontSize()
|
maxFontScale: this.getMaxFontSize(),
|
||||||
|
onItemClicked: this.onItemClicked
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1217,7 +1222,6 @@ export struct SegmentButton {
|
|||||||
GestureGroup(GestureMode.Parallel,
|
GestureGroup(GestureMode.Parallel,
|
||||||
TapGesture()
|
TapGesture()
|
||||||
.onAction((event: GestureEvent) => {
|
.onAction((event: GestureEvent) => {
|
||||||
this.focusIndex = -1
|
|
||||||
let fingerInfo = event.fingerList.find(Boolean)
|
let fingerInfo = event.fingerList.find(Boolean)
|
||||||
if (fingerInfo === void 0) {
|
if (fingerInfo === void 0) {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user