我刚刚开始学习和练习 React Native,我遇到了第一个问题,我似乎可以自己解决。
\n我有以下代码,非常简单,但是当我在网络上运行它时,Alert.alert() 不起作用。如果我单击该按钮,则不会发生任何事情,但是,当我在 iOS 或 Android 模拟器上单击该按钮时,它工作正常。
\nimport { StatusBar } from 'expo-status-bar';\nimport React from 'react';\nimport { StyleSheet, Text, Button, View, Alert } from 'react-native';\n\nexport default function App() {\n return (\n <View style={styles.container}>\n <Text style={styles.headerStyle} >Practice App</Text>\n <Text style={{padding: 10}}>Open up App.js to start working on your app!</Text>\n <Button\n onPress={() => alert('Hello, Nice To Meet You :)')}\n title="Greet Me"\n />\n <StatusBar style="auto" />\n </View>\n );\n}\nRun Code Online (Sandbox Code Playgroud)\n我也知道alert()适用于所有三种设备,但是,我想了解为什么Alert.alert()仅适用于iOS和Android。
\n我的问题更多的是为了理解而不是寻找解决方案。是使用alert()的唯一解决方案,还是我以错误的方式实现Alert.alert()?
\n