Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full text is not showing in alert dialog in react native

I am trying to show alert dialog to user on clicking on a button. I am trying like below

onPressButton() {
  Alert.alert(strings.tour_end);
}

strings.tour_end is "Great! Hope you like our product tour! Enjoy this app. We have some excited offers for you!"

This is how it is showing in alert. Is this bug in react-native ?enter image description here

like image 806
N Sharma Avatar asked May 01 '17 08:05

N Sharma


2 Answers

You have passed full message as Alert title, as per Alert API.

alert(title, message?, buttons?, options?, type?)

like below

alert("Great..!", strings.tour_end);

So title should be small message and you can show full message in message parameter.

if you want to develop customise Alert then use Modal API. Check it.

Or

You can use some third party npm modules to show customise alerts. which is also based on modal api.

npm install react-native-modalbox@latest --save

try this.

like image 50
Irfan Ali Avatar answered Sep 20 '22 00:09

Irfan Ali


If you pass only text it will consider as a Title

As per the documentation https://facebook.github.io/react-native/docs/alert.. you can pass values like this.

Alert.alert(
'Alert Title',
'My Alert Msg',
[
{text: 'Ask me later', onPress: () => console.log('Ask me later pressed')},
{text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
{text: 'OK', onPress: () => console.log('OK Pressed')},
], 
{ cancelable: false }
)
like image 36
Tarun Avatar answered Sep 21 '22 00:09

Tarun