@@ -18,13 +18,21 @@ If this button doesn't look right for your app, you can build your own button us
1818
1919## Example
2020
21- ``` SnackPlayer name=Button%20Example
21+ ``` SnackPlayer name=Button%20Example&ext=js
2222import React from 'react';
23- import {StyleSheet, Button, View, Text, Alert} from 'react-native';
23+ import {StyleSheet, Button, View, Text, Alert, Platform } from 'react-native';
2424import {SafeAreaView, SafeAreaProvider} from 'react-native-safe-area-context';
2525
2626const Separator = () => <View style={styles.separator} />;
2727
28+ function showAlert(message) {
29+ if (Platform.OS === 'web') {
30+ window.alert(message);
31+ } else {
32+ Alert.alert(message);
33+ }
34+ }
35+
2836const App = () => (
2937 <SafeAreaProvider>
3038 <SafeAreaView style={styles.container}>
@@ -35,7 +43,7 @@ const App = () => (
3543 </Text>
3644 <Button
3745 title="Press me"
38- onPress={() => Alert.alert ('Simple Button pressed')}
46+ onPress={() => showAlert ('Simple Button pressed')}
3947 />
4048 </View>
4149 <Separator />
@@ -48,7 +56,7 @@ const App = () => (
4856 <Button
4957 title="Press me"
5058 color="#f194ff"
51- onPress={() => Alert.alert ('Button with adjusted color pressed')}
59+ onPress={() => showAlert ('Button with adjusted color pressed')}
5260 />
5361 </View>
5462 <Separator />
@@ -59,7 +67,7 @@ const App = () => (
5967 <Button
6068 title="Press me"
6169 disabled
62- onPress={() => Alert.alert ('Cannot press this one')}
70+ onPress={() => showAlert ('Cannot press this one')}
6371 />
6472 </View>
6573 <Separator />
@@ -70,11 +78,11 @@ const App = () => (
7078 <View style={styles.fixToText}>
7179 <Button
7280 title="Left button"
73- onPress={() => Alert.alert ('Left button pressed')}
81+ onPress={() => showAlert ('Left button pressed')}
7482 />
7583 <Button
7684 title="Right button"
77- onPress={() => Alert.alert ('Right button pressed')}
85+ onPress={() => showAlert ('Right button pressed')}
7886 />
7987 </View>
8088 </View>
0 commit comments