Skip to content

Commit fb9fb5a

Browse files
ajkshfjkajmaikai (A)
andauthored
feat: 添加select方法适配 (#10)
Co-authored-by: maikai (A) <mWX1352063@china.huawei.com>
1 parent b1fc4cc commit fb9fb5a

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

harmony/picker/src/main/ets/Magic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface FontStyle {
3232
}
3333

3434
export interface GlobalDialogParam {
35-
content: string;
35+
selected: string | string[];
3636
}
3737

3838
export interface ResultItem {

harmony/picker/src/main/ets/PickerBaseOperate.ets

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import Logger from './Logger';
2525
export const TAG = "Picker";
2626

2727
@Builder
28-
function buildGlobalDialogComponent() {
28+
function buildGlobalDialogComponent(params: Params) {
2929
Column() {
3030
Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
3131
Text(content.pickerCancelBtnText)
@@ -54,7 +54,7 @@ function buildGlobalDialogComponent() {
5454
.height(FIVE_PERCENT)
5555
.width(HUNDRED_PERCENT)
5656

57-
TextPicker({ range: content.pickerData, value: content.selectedValue })
57+
TextPicker({ range: content.pickerData, value: params.selected })
5858
.onChange((value: string | string[]) => {
5959
changeSelect(value);
6060
})
@@ -107,6 +107,14 @@ let pickerCtx: TurboModuleContext;
107107
let uiContext: UIContext;
108108
let showPicker: boolean = false;
109109

110+
class Params {
111+
selected: string | string[] = '';
112+
113+
constructor(selected: string | string[]) {
114+
this.selected = selected;
115+
}
116+
}
117+
110118
export class GlobalDialog {
111119
static contentNode: ComponentContent<GlobalDialogParam>;
112120
protected ctx: TurboModuleContext;
@@ -122,7 +130,8 @@ export class GlobalDialog {
122130

123131
static show() {
124132
try {
125-
GlobalDialog.contentNode = new ComponentContent(uiContext, wrapBuilder(buildGlobalDialogComponent));
133+
GlobalDialog.contentNode =
134+
new ComponentContent(uiContext, wrapBuilder(buildGlobalDialogComponent), new Params(content.selectedValue));
126135
const promptAction = uiContext.getPromptAction();
127136
promptAction.openCustomDialog(GlobalDialog.contentNode, {
128137
alignment: DialogAlignment.Bottom,
@@ -159,6 +168,11 @@ export class GlobalDialog {
159168
return content;
160169
}
161170

171+
update(array: Array<string>) {
172+
content.selectedValue = array;
173+
GlobalDialog.contentNode.update(new Params(content.selectedValue));
174+
}
175+
162176
processData(data: object[]): ResultItem[] {
163177
try {
164178
const result = data.map((item: object) => {

harmony/picker/src/main/ets/PickerTurboModule.ets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class RNCPickerTurboModule extends TurboModule {
2121
}
2222

2323
select(array: Array<string>) {
24+
this.pickerBaseOperate?.update(array);
2425
}
2526

2627
hide() {

0 commit comments

Comments
 (0)