我在React Native中使用onpress方法调用一个函数。 OnPress在Android上无法正常运行,而在iOS上则可以正常运行。当我在其他地方尝试onPress时,它可以工作,但是当我单击图像时,onPress不起作用。
export default class HomeScreen extends Component {
onBildirim() {
this.props.navigation.navigate("notification", {
title: "notification"
});
}
<View style={styles.footerBody}>
<Image
source={require('../images/footer.png')}
style={{
width:screenWidth,
height:110,
bottom:0,
position: 'absolute'}}
/>
<TouchableHighlight onPress={() => this.onBildirim()}>
<Image
source={require('../images/haberlerbutton2.png')}
style={{
width:35,
height:35,
position: 'absolute',
top:30,
left:20 }}
/>
</TouchableHighlight>
<Text style={{
width:55,
height:35,
position: 'absolute',
top:65,
left:20,
fontSize: 11,
fontFamily: 'ProximaNova-Light' }} >Haberler</Text>
<TouchableHighlight onPress={() => this.onBildirim()}>
<Image
source={require('../images/canlıyayın.png')}
style={{
width:35,
height:35,
top:30,
position: 'absolute',
right:20 }}
/>
</TouchableHighlight>
}
答案 0 :(得分:0)
主要问题是位置:“绝对”,图片
从'react'导入React,{组件}; 导入{ 视图, 图片, TouchableOpacity,文字 }来自“ react-native”; 导出默认类HomeScreen扩展了组件{
onBildirim(){ this.props.navigation.navigate(“ notification”,{ 标题:“通知” }); } render(){ 返回( 黑客 this.onBildirim()}> this.onBildirim()}>
<Image
source={require('../Images/hacker.jpg')}
style={{
width: 100,
height: 100,
marginHorizontal:20
}}
/>
</TouchableOpacity>
</View>
</View>
);
} }