已合并
fix: Alert button order is not consistant #1038
zichenyang21创建于 2025年5月20日
fix: Alert button order is not consistant #1038
已合并
共 3 个文件变更+17-17
| @@ -42,9 +42,9 @@ class Alert { | |||
| 42 | 42 | ||
| 43 | // At most three buttons. Ignore rest. | 43 | // At most three buttons. Ignore rest. |
| 44 | const validButtons: Buttons = (buttons ?? [{text: "OK"}]).slice(0, 3) | 44 | const validButtons: Buttons = (buttons ?? [{text: "OK"}]).slice(0, 3) |
| 45 | - const primaryButton = validButtons.pop(); | 45 | + const tertiaryButton = validButtons.pop(); |
| 46 | const secondaryButton = validButtons.pop(); | 46 | const secondaryButton = validButtons.pop(); |
| 47 | - const thirdaryButton = validButtons.pop(); | 47 | + const primaryButton = validButtons.pop(); |
| 48 | 48 | ||
| 49 | if (primaryButton) { | 49 | if (primaryButton) { |
| 50 | alertOptions.primaryButton = primaryButton.text || ""; | 50 | alertOptions.primaryButton = primaryButton.text || ""; |
| @@ -52,8 +52,8 @@ class Alert { | |||
| 52 | if (secondaryButton) { | 52 | if (secondaryButton) { |
| 53 | alertOptions.secondaryButton = secondaryButton.text || ""; | 53 | alertOptions.secondaryButton = secondaryButton.text || ""; |
| 54 | } | 54 | } |
| 55 | - if (thirdaryButton) { | 55 | + if (tertiaryButton) { |
| 56 | - alertOptions.thirdaryButton = thirdaryButton.text || ""; | 56 | + alertOptions.tertiaryButton = tertiaryButton.text || ""; |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | const onAction = (action, buttonKey) => { | 59 | const onAction = (action, buttonKey) => { |
| @@ -62,8 +62,8 @@ class Alert { | |||
| 62 | primaryButton.onPress && primaryButton.onPress(); | 62 | primaryButton.onPress && primaryButton.onPress(); |
| 63 | } else if (buttonKey === constants.secondaryButton) { | 63 | } else if (buttonKey === constants.secondaryButton) { |
| 64 | secondaryButton.onPress && secondaryButton.onPress(); | 64 | secondaryButton.onPress && secondaryButton.onPress(); |
| 65 | - } else if (buttonKey === constants.thirdaryButton) { | 65 | + } else if (buttonKey === constants.tertiaryButton) { |
| 66 | - thirdaryButton.onPress && thirdaryButton.onPress(); | 66 | + tertiaryButton.onPress && tertiaryButton.onPress(); |
| 67 | } | 67 | } |
| 68 | } else if (action === constants.dismissed) { | 68 | } else if (action === constants.dismissed) { |
| 69 | options && options.onDismiss && options.onDismiss(); | 69 | options && options.onDismiss && options.onDismiss(); |
| @@ -7,7 +7,7 @@ type AlertAction = string; | |||
| 7 | /* | 7 | /* |
| 8 | primaryButton = 1, | 8 | primaryButton = 1, |
| 9 | secondaryButton = 2, | 9 | secondaryButton = 2, |
| 10 | - thirdaryButton = 3, | 10 | + tertiaryButton = 3, |
| 11 | */ | 11 | */ |
| 12 | type AlertButtonKey = number; | 12 | type AlertButtonKey = number; |
| 13 | export type AlertOptions = { | 13 | export type AlertOptions = { |
| @@ -15,7 +15,7 @@ export type AlertOptions = { | |||
| 15 | message?: string; | 15 | message?: string; |
| 16 | primaryButton?: string; | 16 | primaryButton?: string; |
| 17 | secondaryButton?: string; | 17 | secondaryButton?: string; |
| 18 | - thirdaryButton?: string; | 18 | + tertiaryButton?: string; |
| 19 | items?: Array<string>; | 19 | items?: Array<string>; |
| 20 | cancelable?: boolean; | 20 | cancelable?: boolean; |
| 21 | }; | 21 | }; |
| @@ -26,7 +26,7 @@ export interface Spec extends TurboModule { | |||
| 26 | dismissed: AlertAction; | 26 | dismissed: AlertAction; |
| 27 | primaryButton: AlertButtonKey; | 27 | primaryButton: AlertButtonKey; |
| 28 | secondaryButton: AlertButtonKey; | 28 | secondaryButton: AlertButtonKey; |
| 29 | - thirdaryButton: AlertButtonKey; | 29 | + tertiaryButton: AlertButtonKey; |
| 30 | }; | 30 | }; |
| 31 | alert: ( | 31 | alert: ( |
| 32 | options: AlertOptions, | 32 | options: AlertOptions, |
| @@ -14,7 +14,7 @@ type AlertOptions = { | |||
| 14 | message?: string | 14 | message?: string |
| 15 | primaryButton?: string | 15 | primaryButton?: string |
| 16 | secondaryButton?: string | 16 | secondaryButton?: string |
| 17 | - thirdaryButton?: string | 17 | + tertiaryButton?: string |
| 18 | cancelable: boolean | 18 | cancelable: boolean |
| 19 | } | 19 | } |
| 20 | 20 | ||
| @@ -31,7 +31,7 @@ export class AlertManagerTurboModule extends TurboModule { | |||
| 31 | dismissed: 'dismissed', | 31 | dismissed: 'dismissed', |
| 32 | primaryButton: 1, | 32 | primaryButton: 1, |
| 33 | secondaryButton: 2, | 33 | secondaryButton: 2, |
| 34 | - thirdaryButton: 3, | 34 | + tertiaryButton: 3, |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | getConstants() { | 37 | getConstants() { |
| @@ -59,21 +59,21 @@ export class AlertManagerTurboModule extends TurboModule { | |||
| 59 | onAction = undefined; | 59 | onAction = undefined; |
| 60 | } | 60 | } |
| 61 | } : undefined; | 61 | } : undefined; |
| 62 | - const thirdaryButton = | 62 | + const tertiaryButton = |
| 63 | - options.thirdaryButton? { | 63 | + options.tertiaryButton? { |
| 64 | - value: options.thirdaryButton, | 64 | + value: options.tertiaryButton, |
| 65 | action: () => { | 65 | action: () => { |
| 66 | - onAction?.(this.constants.buttonClicked, this.constants.thirdaryButton); | 66 | + onAction?.(this.constants.buttonClicked, this.constants.tertiaryButton); |
| 67 | onAction = undefined; | 67 | onAction = undefined; |
| 68 | } | 68 | } |
| 69 | } : undefined; | 69 | } : undefined; |
| 70 | - const buttons = [primaryButton, secondaryButton, thirdaryButton]; | 70 | + const buttons = [primaryButton, secondaryButton, tertiaryButton]; |
| 71 | 71 | ||
| 72 | const alertParams = { | 72 | const alertParams = { |
| 73 | title: options.title, | 73 | title: options.title, |
| 74 | message: options.message, | 74 | message: options.message, |
| 75 | autoCancel: options.cancelable, | 75 | autoCancel: options.cancelable, |
| 76 | - buttons: buttons, | 76 | + buttons: buttons.filter((button) => button !== undefined), |
| 77 | cancel: () => { | 77 | cancel: () => { |
| 78 | onAction?.(this.constants.dismissed); | 78 | onAction?.(this.constants.dismissed); |
| 79 | onAction = undefined; | 79 | onAction = undefined; |