Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I style an Alert element in react-native?

Tags:

I'm working with react-native and I have created an Alert element.

Alert.alert(     'Warning',     'bla bla bla',     [            {text: 'OK', onPress: () => console.log('OK Pressed')},     ] ) 

Now I'd like to apply some style to it. Let's say I want to apply to it a red background color and white color for the text.

How can I achieve this? Is it possible?

like image 703
splunk Avatar asked Jan 15 '17 20:01

splunk


People also ask

Can I style alert in react native?

In IOS you can use more than three buttons with the style which is one of default, destructive or cancel. React Native Alert does not support custom styling and animations.


1 Answers

There actually is a way to customize the text on the buttons but you're limited to what is provided... Below is the type definition from react native. Then a simple example showing a red button. Basically the "default" is blue, "cancel" is bold but still blue and "destructive" is red.

**  * An Alert button style */ export type AlertButtonStyle = $Enum<{ /** * Default button style */ 'default': string, /** * Cancel button style */ 'cancel': string, /** * Destructive button style */ 'destructive': string, }>;   Alert.alert("Look out!",         "Hitting reset will wipe all the app's data on your phone. This cannot be undone!",         [         {text: 'Reset', onPress: this._doSomethingSerious, style: 'destructive'},         {text: 'Cancel'},         ],         {cancelable: false}     ) 
like image 141
Sean O'Leary Avatar answered Sep 22 '22 10:09

Sean O'Leary