mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-17 02:31:34 +08:00
fix(react): present and dismiss hooks return promises (#24299)
This commit is contained in:
@ -20,12 +20,12 @@ export function useIonActionSheet(): UseIonActionSheetResult {
|
|||||||
header?: string
|
header?: string
|
||||||
) => {
|
) => {
|
||||||
if (Array.isArray(buttonsOrOptions)) {
|
if (Array.isArray(buttonsOrOptions)) {
|
||||||
controller.present({
|
return controller.present({
|
||||||
buttons: buttonsOrOptions,
|
buttons: buttonsOrOptions,
|
||||||
header,
|
header,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
controller.present(buttonsOrOptions);
|
return controller.present(buttonsOrOptions);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[controller.present]
|
[controller.present]
|
||||||
@ -41,15 +41,15 @@ export type UseIonActionSheetResult = [
|
|||||||
* @param buttons An array of buttons for the action sheet
|
* @param buttons An array of buttons for the action sheet
|
||||||
* @param header Optional - Title for the action sheet
|
* @param header Optional - Title for the action sheet
|
||||||
*/
|
*/
|
||||||
(buttons: ActionSheetButton[], header?: string | undefined): void;
|
(buttons: ActionSheetButton[], header?: string | undefined): Promise<void>;
|
||||||
/**
|
/**
|
||||||
* Presents the action sheet
|
* Presents the action sheet
|
||||||
* @param options The options to pass to the IonActionSheet
|
* @param options The options to pass to the IonActionSheet
|
||||||
*/
|
*/
|
||||||
(options: ActionSheetOptions & HookOverlayOptions): void;
|
(options: ActionSheetOptions & HookOverlayOptions): Promise<void>;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Dismisses the action sheet
|
* Dismisses the action sheet
|
||||||
*/
|
*/
|
||||||
() => void
|
() => Promise<void>
|
||||||
];
|
];
|
||||||
|
@ -14,12 +14,12 @@ export function useIonAlert(): UseIonAlertResult {
|
|||||||
const present = useCallback(
|
const present = useCallback(
|
||||||
(messageOrOptions: string | (AlertOptions & HookOverlayOptions), buttons?: AlertButton[]) => {
|
(messageOrOptions: string | (AlertOptions & HookOverlayOptions), buttons?: AlertButton[]) => {
|
||||||
if (typeof messageOrOptions === 'string') {
|
if (typeof messageOrOptions === 'string') {
|
||||||
controller.present({
|
return controller.present({
|
||||||
message: messageOrOptions,
|
message: messageOrOptions,
|
||||||
buttons: buttons ?? [{ text: 'Ok' }],
|
buttons: buttons ?? [{ text: 'Ok' }],
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
controller.present(messageOrOptions);
|
return controller.present(messageOrOptions);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[controller.present]
|
[controller.present]
|
||||||
@ -35,15 +35,15 @@ export type UseIonAlertResult = [
|
|||||||
* @param message The main message to be displayed in the alert
|
* @param message The main message to be displayed in the alert
|
||||||
* @param buttons Optional - Array of buttons to be added to the alert
|
* @param buttons Optional - Array of buttons to be added to the alert
|
||||||
*/
|
*/
|
||||||
(message: string, buttons?: AlertButton[]): void;
|
(message: string, buttons?: AlertButton[]): Promise<void>;
|
||||||
/**
|
/**
|
||||||
* Presents the alert
|
* Presents the alert
|
||||||
* @param options The options to pass to the IonAlert
|
* @param options The options to pass to the IonAlert
|
||||||
*/
|
*/
|
||||||
(options: AlertOptions & HookOverlayOptions): void;
|
(options: AlertOptions & HookOverlayOptions): Promise<void>;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Dismisses the alert
|
* Dismisses the alert
|
||||||
*/
|
*/
|
||||||
() => void
|
() => Promise<void>
|
||||||
];
|
];
|
||||||
|
@ -21,13 +21,13 @@ export function useIonLoading(): UseIonLoadingResult {
|
|||||||
spinner?: SpinnerTypes
|
spinner?: SpinnerTypes
|
||||||
) => {
|
) => {
|
||||||
if (typeof messageOrOptions === 'string') {
|
if (typeof messageOrOptions === 'string') {
|
||||||
controller.present({
|
return controller.present({
|
||||||
message: messageOrOptions,
|
message: messageOrOptions,
|
||||||
duration,
|
duration,
|
||||||
spinner: spinner ?? 'lines',
|
spinner: spinner ?? 'lines',
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
controller.present(messageOrOptions);
|
return controller.present(messageOrOptions);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[controller.present]
|
[controller.present]
|
||||||
@ -44,15 +44,15 @@ export type UseIonLoadingResult = [
|
|||||||
* @param duration Optional - Number of milliseconds to wait before dismissing the loading indicator
|
* @param duration Optional - Number of milliseconds to wait before dismissing the loading indicator
|
||||||
* @param spinner Optional - The name of the spinner to display, defaults to "lines"
|
* @param spinner Optional - The name of the spinner to display, defaults to "lines"
|
||||||
*/
|
*/
|
||||||
(message?: string, duration?: number, spinner?: SpinnerTypes): void;
|
(message?: string, duration?: number, spinner?: SpinnerTypes): Promise<void>;
|
||||||
/**
|
/**
|
||||||
* Presents the loading indicator
|
* Presents the loading indicator
|
||||||
* @param options The options to pass to the IonLoading
|
* @param options The options to pass to the IonLoading
|
||||||
*/
|
*/
|
||||||
(options: LoadingOptions & HookOverlayOptions): void;
|
(options: LoadingOptions & HookOverlayOptions): Promise<void>;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Dismisses the loading indicator
|
* Dismisses the loading indicator
|
||||||
*/
|
*/
|
||||||
() => void
|
() => Promise<void>
|
||||||
];
|
];
|
||||||
|
@ -19,12 +19,12 @@ export function useIonPicker(): UseIonPickerResult {
|
|||||||
buttons?: PickerButton[]
|
buttons?: PickerButton[]
|
||||||
) => {
|
) => {
|
||||||
if (Array.isArray(columnsOrOptions)) {
|
if (Array.isArray(columnsOrOptions)) {
|
||||||
controller.present({
|
return controller.present({
|
||||||
columns: columnsOrOptions,
|
columns: columnsOrOptions,
|
||||||
buttons: buttons ?? [{ text: 'Ok' }],
|
buttons: buttons ?? [{ text: 'Ok' }],
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
controller.present(columnsOrOptions);
|
return controller.present(columnsOrOptions);
|
||||||
}
|
}
|
||||||
}, [controller.present]);
|
}, [controller.present]);
|
||||||
|
|
||||||
@ -38,15 +38,15 @@ export type UseIonPickerResult = [
|
|||||||
* @param columns Array of columns to be displayed in the picker.
|
* @param columns Array of columns to be displayed in the picker.
|
||||||
* @param buttons Optional - Array of buttons to be displayed at the top of the picker.
|
* @param buttons Optional - Array of buttons to be displayed at the top of the picker.
|
||||||
*/
|
*/
|
||||||
(columns: PickerColumn[], buttons?: PickerButton[]): void;
|
(columns: PickerColumn[], buttons?: PickerButton[]): Promise<void>;
|
||||||
/**
|
/**
|
||||||
* Presents the picker
|
* Presents the picker
|
||||||
* @param options The options to pass to the IonPicker
|
* @param options The options to pass to the IonPicker
|
||||||
*/
|
*/
|
||||||
(options: PickerOptions & HookOverlayOptions): void;
|
(options: PickerOptions & HookOverlayOptions): Promise<void>;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Dismisses the picker
|
* Dismisses the picker
|
||||||
*/
|
*/
|
||||||
() => void
|
() => Promise<void>
|
||||||
];
|
];
|
||||||
|
@ -16,12 +16,12 @@ export function useIonToast(): UseIonToastResult {
|
|||||||
|
|
||||||
const present = useCallback((messageOrOptions: string | ToastOptions & HookOverlayOptions, duration?: number) => {
|
const present = useCallback((messageOrOptions: string | ToastOptions & HookOverlayOptions, duration?: number) => {
|
||||||
if (typeof messageOrOptions === 'string') {
|
if (typeof messageOrOptions === 'string') {
|
||||||
controller.present({
|
return controller.present({
|
||||||
message: messageOrOptions,
|
message: messageOrOptions,
|
||||||
duration
|
duration
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
controller.present(messageOrOptions);
|
return controller.present(messageOrOptions);
|
||||||
}
|
}
|
||||||
}, [controller.present]);
|
}, [controller.present]);
|
||||||
|
|
||||||
@ -38,15 +38,15 @@ export type UseIonToastResult = [
|
|||||||
* @param message Message to be shown in the toast.
|
* @param message Message to be shown in the toast.
|
||||||
* @param duration Optional - How many milliseconds to wait before hiding the toast. By default, it will show until dismissToast() is called.
|
* @param duration Optional - How many milliseconds to wait before hiding the toast. By default, it will show until dismissToast() is called.
|
||||||
*/
|
*/
|
||||||
(message: string, duration?: number): void;
|
(message: string, duration?: number): Promise<void>;
|
||||||
/**
|
/**
|
||||||
* Presents the Toast
|
* Presents the Toast
|
||||||
* @param options The options to pass to the IonToast.
|
* @param options The options to pass to the IonToast.
|
||||||
*/
|
*/
|
||||||
(options: ToastOptions & HookOverlayOptions): void;
|
(options: ToastOptions & HookOverlayOptions): Promise<void>;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Dismisses the toast
|
* Dismisses the toast
|
||||||
*/
|
*/
|
||||||
() => void
|
() => Promise<void>
|
||||||
];
|
];
|
||||||
|
Reference in New Issue
Block a user