【问题标题】:OnPress doesn't work React Native - AndroidOnPress 不起作用 React Native - Android
【发布时间】:2020-03-11 14:35:21
【问题描述】:

我使用 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>
}

【问题讨论】:

  • 试试 touchableOpacity for Android 吧。
  • 不工作 touchableOpacity
  • 您是否尝试为可触摸的不透明度样式添加更高的 z 索引?试试这个并添加背景颜色,看看它是否被覆盖

标签: react-native


【解决方案1】:

主要问题是位置:'absolute', Image

从'react'导入反应,{组件}; 进口 { 看法, 图片, 可触摸不透明度,文本 } 来自 'react-native'; 导出默认类 HomeScreen 扩展组件 {

onBildirim() { this.props.navigation.navigate("通知", { 标题:“通知” }); } 使成为() { 返回 ( 黑客 this.onBildirim()}> this.onBildirim()}>

        <Image
          source={require('../Images/hacker.jpg')}
          style={{
            width: 100,
            height: 100,
            marginHorizontal:20
          }}
        />
      </TouchableOpacity>

    </View>
  </View>
);

} }

【讨论】:

    猜你喜欢
    • 2018-09-19
    • 2018-11-06
    • 1970-01-01
    • 1970-01-01
    • 2019-02-18
    • 1970-01-01
    • 1970-01-01
    • 2022-12-12
    • 2020-09-19
    相关资源
    最近更新 更多