mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Use default OK on buttonPositive to prevent showing an alert without any buttons (#25033)
Summary: Solve #25016 Use `OK` as default text for the affirmative button if no text is specified. When setting an alert on android with button configuration, and no `text` field specified no button is shown on the alert. This makes it impossible to dismiss. An example of how this can happen is creating a simple button where a `onPress` callback is used but no text is specified: ``` Alert.alert( 'title', 'message', [ { onPress: () => console.log('onPress') } ], ) ``` Does not change the current behavior of no text button configurations on iOS. On iOS at least one button is always shown, and buttons with no text can be displayed. Behavior on setting multiple buttons is a little wonky, but this PR does not aim to solve it. I did test these cases and included some examples below. ## Changelog [Android] [Fixed] - Use OK as default text on Android Alert if button configuration specified without text Pull Request resolved: https://github.com/facebook/react-native/pull/25033 Differential Revision: D15502780 Pulled By: cpojer fbshipit-source-id: 505a9940f4588f4c10e25b67bfed8b8a1e610c69
This commit is contained in:
committed by
Facebook Github Bot
parent
7d1c827cb2
commit
fa97b2383c
@@ -73,9 +73,10 @@ class Alert {
|
||||
}
|
||||
// At most three buttons (neutral, negative, positive). Ignore rest.
|
||||
// The text 'OK' should be probably localized. iOS Alert does that in native.
|
||||
const defaultPositiveText = 'OK';
|
||||
const validButtons: Buttons = buttons
|
||||
? buttons.slice(0, 3)
|
||||
: [{text: 'OK'}];
|
||||
: [{text: defaultPositiveText}];
|
||||
const buttonPositive = validButtons.pop();
|
||||
const buttonNegative = validButtons.pop();
|
||||
const buttonNeutral = validButtons.pop();
|
||||
@@ -87,7 +88,7 @@ class Alert {
|
||||
config.buttonNegative = buttonNegative.text || '';
|
||||
}
|
||||
if (buttonPositive) {
|
||||
config.buttonPositive = buttonPositive.text || '';
|
||||
config.buttonPositive = buttonPositive.text || defaultPositiveText;
|
||||
}
|
||||
|
||||
const onAction = (action, buttonKey) => {
|
||||
|
||||
Reference in New Issue
Block a user