Skip to content

Commit a646743

Browse files
Wes Johnsonfacebook-github-bot
authored andcommitted
Alert - allow for hiding alert title on iOS
Summary: Wanted a "message-only" alert on iOS that doesn't lead to the message being large & bolded via the title field (current state). Before: ![screen shot 2017-08-28 at 9 22 04 pm](https://user-images.githubusercontent.com/1047502/29801514-fc3629d2-8c3d-11e7-86d5-f0a866301814.png) After: ![screen shot 2017-08-28 at 9 26 56 pm](https://user-images.githubusercontent.com/1047502/29801521-071aa1ca-8c3e-11e7-9bd0-0a4682d81979.png) It also aligns iOS with Android's current behaviour. The above screenhots were generated from the `RNTester` example added herein. Allowed for passing an empty string through to `UIAlertController.alertControllerWithTitle` so that the message could be rendered in its expected place on iOS (not as the title). * Ran RNTester & compared example alerts before & after (below default with titles, for example) * Ran end-to-end manual test suite (it's the only one I could get through without unrelated failures) Before ![screen shot 2017-08-28 at 9 21 53 pm](https://user-images.githubusercontent.com/1047502/29801775-6e249ff0-8c3f-11e7-888b-2c4d5177a7d7.png) After ![screen shot 2017-08-28 at 9 26 40 pm](https://user-images.githubusercontent.com/1047502/29801781-7270c4a8-8c3f-11e7-8b9b-59b2649646f2.png) Closes #15685 Differential Revision: D5729420 Pulled By: hramos fbshipit-source-id: 4866b0b24473ae35e9ebae09f2cee13a49d7717e
1 parent 9f38d45 commit a646743

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Libraries/Alert/AlertIOS.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ class AlertIOS {
110110
* @static
111111
* @method alert
112112
* @param title The dialog's title.
113+
*
114+
* An empty string hides the title.
113115
* @param message An optional message that appears below
114116
* the dialog's title.
115117
* @param callbackOrButtons This optional argument should
@@ -209,7 +211,7 @@ class AlertIOS {
209211
var callback = type;
210212
var defaultValue = message;
211213
RCTAlertManager.alertWithArgs({
212-
title: title || undefined,
214+
title: title,
213215
type: 'plain-text',
214216
defaultValue,
215217
}, (id, value) => {
@@ -242,7 +244,7 @@ class AlertIOS {
242244
}
243245

244246
RCTAlertManager.alertWithArgs({
245-
title: title || undefined,
247+
title: title,
246248
message: message || undefined,
247249
buttons,
248250
type: type || undefined,

RNTester/js/AlertExample.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ class SimpleAlertExampleBlock extends React.Component {
110110
<Text>Alert that cannot be dismissed</Text>
111111
</View>
112112
</TouchableHighlight>
113+
<TouchableHighlight style={styles.wrapper}
114+
onPress={() => Alert.alert(
115+
'',
116+
alertMessage,
117+
[
118+
{text: 'OK', onPress: () => console.log('OK Pressed!')},
119+
]
120+
)}>
121+
<View style={styles.button}>
122+
<Text>Alert without title</Text>
123+
</View>
124+
</TouchableHighlight>
113125
</View>
114126
);
115127
}

0 commit comments

Comments
 (0)