@@ -20,11 +20,20 @@ If this button doesn't look right for your app, you can build your own button us
2020
2121``` SnackPlayer name=Button%20Example
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: string){
29+ if(Platform.OS === "web"){
30+ window.alert(message);
31+ }
32+ else{
33+ Alert.alert(message)
34+ }
35+ }
36+
2837const App = () => (
2938 <SafeAreaProvider>
3039 <SafeAreaView style={styles.container}>
@@ -35,7 +44,7 @@ const App = () => (
3544 </Text>
3645 <Button
3746 title="Press me"
38- onPress={() => Alert.alert ('Simple Button pressed')}
47+ onPress={() => showAlert ('Simple Button pressed')}
3948 />
4049 </View>
4150 <Separator />
@@ -48,7 +57,7 @@ const App = () => (
4857 <Button
4958 title="Press me"
5059 color="#f194ff"
51- onPress={() => Alert.alert ('Button with adjusted color pressed')}
60+ onPress={() => showAlert ('Button with adjusted color pressed')}
5261 />
5362 </View>
5463 <Separator />
@@ -59,7 +68,7 @@ const App = () => (
5968 <Button
6069 title="Press me"
6170 disabled
62- onPress={() => Alert.alert ('Cannot press this one')}
71+ onPress={() => showAlert ('Cannot press this one')}
6372 />
6473 </View>
6574 <Separator />
@@ -70,11 +79,11 @@ const App = () => (
7079 <View style={styles.fixToText}>
7180 <Button
7281 title="Left button"
73- onPress={() => Alert.alert ('Left button pressed')}
82+ onPress={() => showAlert ('Left button pressed')}
7483 />
7584 <Button
7685 title="Right button"
77- onPress={() => Alert.alert ('Right button pressed')}
86+ onPress={() => showAlert ('Right button pressed')}
7887 />
7988 </View>
8089 </View>
0 commit comments