小编Pra*_*93a的帖子

onPress 事件不适用于本机反应中的视图、图像、touchableopacity

我是 React Native 的新手,我在 View 组件上实现了 onPress 函数(我尝试过 touchableOpacity 和 NativeFeedBack),但它对它们中的任何一个都不起作用。我不明白为什么。

我想使用图像来实现按钮,这样当有人单击该按钮时,代码就会运行。但事情并不如预期。

import React, { Component } from 'react';
import {
    StatusBar,
    Image,
    View,
    Text,
    Dimensions,
    TouchableNativeFeedback
} from 'react-native';

import Constants from 'expo-constants';
class LandingScreen extends Component {

    render() {
        const resizeMode = 'cover';
        const text = '';
        const { width, height } = Dimensions.get('screen');
        return (
            <View
                  style={{
                    flex: 1,
                    backgroundColor: '#eee',
                    paddingStart:Constants.statusBarHeight
                  }}
                >
                      <StatusBar hidden />
                  <View
                    style={{
                      position: 'absolute',
                      top: 0,
                      left: 0,
                      width: width, …
Run Code Online (Sandbox Code Playgroud)

javascript react-native react-native-navigation

5
推荐指数
1
解决办法
8298
查看次数