标签: touchableopacity

react-native TouchableNativeFeedback onPress 不起作用

我创建了一个组合组件来将 TouchableNativeFeedback 组合到 wrapperComponent。

export default function withFeedback2(
    WrappedComponent
) {
    return class extends BaseComponent {
        constructor(props) {
            super(props);
        }

        render() {
            return (
                <View>
                    <TouchableNativeFeedback
                        onPress={() => this.props.onContainerViewPress()}

                    >
                        <WrappedComponent {...this.props} />
                    </TouchableNativeFeedback>
                    {/* <TouchableOpacity
                        onPress={this.props.onContainerViewPress ? () => this.props.onContainerViewPress() : null}

 >
                        <WrappedComponent {...this.props} />
                    </TouchableOpacity> */}
                </View>
            );
        }
    };
}
Run Code Online (Sandbox Code Playgroud)

但是TochableNativeFeedback 的 OnPress事件没有触发。而 OnPress 事件被正确触发,并且如果 wrappercomponent 包装在 TouchableOpacity 下,则调用 wrappercomponent 的onContainerViewPress道具。

我正在 Android 平台上对此进行测试。

react-native react-native-android touchableopacity react-navigation touchablewithoutfeedback

1
推荐指数
2
解决办法
3825
查看次数

如何在 react native (expo) 中获取点击事件(单、双、长)?

我正在使用 React Native 中的几个点击事件(单、双、长)制作按钮。我已经使用了 Touchable 组件,并且使用时间延迟获得了这些事件。但这不是一个好的解决方案,并且存在一些问题。就是当我双击时,单个事件同时发生。在这种情况下,我必须删除单击事件并获得唯一的双击事件。有没有其他好的解决办法?

react-native touchableopacity expo

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

在react-native-modal中打开键盘时第一次无法单击“保存”按钮

在我的react-native应用程序中..它有一个从react-native-modal导入的模态。Modal 内部有一个 TextInput 字段。当我专注于 textInput 时,默认情况下会打开键盘,但是在 TextInput 中输入文本后,当我尝试单击“保存”按钮时,无法单击“保存”按钮。首先它关闭键盘,然后我可以单击“保存”按钮。请问有人可以帮忙解决这个问题吗?在此输入图像描述

button react-native touchableopacity react-native-modal

0
推荐指数
1
解决办法
1477
查看次数

选择一个组件时选择和取消选择组件

我必须显示三个组件(卡),用户可以从中选择一个。我将这三个组件放置在 a 中ScrollView

...
            <ScrollView horizontal={true} showsHorizontalScrollIndicator={false}>
                <LocationAndPriceCard
                    price={'100'}
                    title={'Choice 3'} />
                <LocationAndPriceCard
                    price={'200'}
                    title={'Choice 2'} />
                <LocationAndPriceCard
                    price={'300'}
                    title={'Choice 1'}} />
            </ScrollView>
...
Run Code Online (Sandbox Code Playgroud)

以下是LocationAndPriceCard编码方式:

...
function LocationAndPriceCard({ price, title }) {

    const [selectedLocation, setSelectedLocation] = useState("red")

    const styles = getStyles(selectedLocation);

    const selected = () => {
        if (selectedLocation == "red") {
            setSelectedLocation("green")
        } else {
            setSelectedLocation("red")
        }
    }

    return (
        <TouchableOpacity style={styles.frame} onPress={selected}>

            <Text style={styles.priceTxt}>RM {price}</Text>
            <Text style={styles.title} numberOfLines={2}>{title}</Text>
        </TouchableOpacity>
    );
}

const getStyles = …
Run Code Online (Sandbox Code Playgroud)

react-native touchableopacity use-state

0
推荐指数
1
解决办法
3807
查看次数