[英]React Native component onPress navigation Button Native-Base
[英]Onpress() of native-base Button is not working on Android
我正在使用基于本机的按钮并尝试通过按下按钮来下载图像。 它在 IOS 中运行良好,但在 Android 中运行良好。 这是我的代码
<View
style={{
marginVertical: hp("2%"),
marginHorizontal: wp("15%"),
textAlign: "center",
width: "100%",
}}
>
<Button
onPress={() => downloadFile()}
style={{
backgroundColor: "#fff",
width: "60%",
borderRadius: 0,
}}
block
>
<Text
style={{
color: "black",
fontSize: RFPercentage(2.1),
fontFamily: "BalsamiqSansBold",
}}
>
ADD TO PHOTOS
</Text>
</Button>
</View>
当按钮被按下时,downloadFile() function 在 IOS 中被调用,但在 Android 的情况下它不起作用。
我也试过控制台登录这样的新闻
<Button
onPress={() => console.log("Button Clicked")}
style={{
backgroundColor: "#fff",
width: "60%",
borderRadius: 0,
}}
block
>
它适用于 IOS 但不适用于 Android。
此外,如果我在 Android 中像这样在 onPress 上直接调用 function ,它会自动记录按钮单击而不被按下。 我试图找出解决它的所有可能方法,但我没有得到这个问题的确切原因。
<Button
onPress={console.log("Button Clicked")}
style={{
backgroundColor: "#fff",
width: "60%",
borderRadius: 0,
}}
block
>
也许您在 android 中遇到有关 TouchableOpacity 的问题。
您可以从“react-native-gesture-handler”导入 ToucahableOpacity,希望这会有所帮助。
你可以像这样导入
import {TouchableOpacity} from 'react-native-gesture-handler'
import {TouchableOpacity } from 'react-native'
<TouchableOpacity
style={styles.button}
onPress={handleSaveLimitValue}
>
<Text
color={colors.white}
weight={TextWeight.DEMI_BOLD}
size={16}
style={styles.buttonText}
>
Save
</Text>
</TouchableOpacity>
使用原生模块的 TouchableOpacity 对我有用,而不是使用import {BaseButton} from react-native-gesture-handler
希望我的回答可以帮到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.