Skip to content

feat: 添加select方法适配 #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion harmony/picker/src/main/ets/Magic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface FontStyle {
}

export interface GlobalDialogParam {
content: string;
selected: string | string[];
}

export interface ResultItem {
Expand Down
20 changes: 17 additions & 3 deletions harmony/picker/src/main/ets/PickerBaseOperate.ets
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Logger from './Logger';
export const TAG = "Picker";

@Builder
function buildGlobalDialogComponent() {
function buildGlobalDialogComponent(params: Params) {
Column() {
Flex({ direction: FlexDirection.Row, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
Text(content.pickerCancelBtnText)
Expand Down Expand Up @@ -54,7 +54,7 @@ function buildGlobalDialogComponent() {
.height(FIVE_PERCENT)
.width(HUNDRED_PERCENT)

TextPicker({ range: content.pickerData, value: content.selectedValue })
TextPicker({ range: content.pickerData, value: params.selected })
.onChange((value: string | string[]) => {
changeSelect(value);
})
Expand Down Expand Up @@ -107,6 +107,14 @@ let pickerCtx: TurboModuleContext;
let uiContext: UIContext;
let showPicker: boolean = false;

class Params {
selected: string | string[] = '';

constructor(selected: string | string[]) {
this.selected = selected;
}
}

export class GlobalDialog {
static contentNode: ComponentContent<GlobalDialogParam>;
protected ctx: TurboModuleContext;
Expand All @@ -122,7 +130,8 @@ export class GlobalDialog {

static show() {
try {
GlobalDialog.contentNode = new ComponentContent(uiContext, wrapBuilder(buildGlobalDialogComponent));
GlobalDialog.contentNode =
new ComponentContent(uiContext, wrapBuilder(buildGlobalDialogComponent), new Params(content.selectedValue));
const promptAction = uiContext.getPromptAction();
promptAction.openCustomDialog(GlobalDialog.contentNode, {
alignment: DialogAlignment.Bottom,
Expand Down Expand Up @@ -159,6 +168,11 @@ export class GlobalDialog {
return content;
}

update(array: Array<string>) {
content.selectedValue = array;
GlobalDialog.contentNode.update(new Params(content.selectedValue));
}

processData(data: object[]): ResultItem[] {
try {
const result = data.map((item: object) => {
Expand Down
1 change: 1 addition & 0 deletions harmony/picker/src/main/ets/PickerTurboModule.ets
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class RNCPickerTurboModule extends TurboModule {
}

select(array: Array<string>) {
this.pickerBaseOperate?.update(array);
}

hide() {
Expand Down