首页 > 解决方案 > 按下时 onPress 函数不会触发

问题描述

按下按钮时不会触发以下功能。一切似乎都被正确地绑定了。

我没有看到使用类属性绑定来解决这些问题的任何更新答案,这是我定义函数的方式。我在另一个页面上有这个确切的设置,唯一的区别是这个函数不带参数。这是组件

<Animated.View style={[styles.listTitle, {bottom: this.state.titlePos}]}>
          <TouchableWithoutFeedback style={fill} onPress={this.openList}>
            <ClearBtn
              type='text'
              align='center'
              textSize={18}
              textContent='Current Deals'
            />
          </TouchableWithoutFeedback>
        </Animated.View>

这是函数定义

openList = () => {
    console.log('HERE');
    Animated.parallel([
      Animated.timing(
        this.state.titlePos,
        {
          toValue: 500,
          duration: 20
        }
      ),
      Animated.timing(
        this.state.listHeight,
        {
          toValue: 500,
          duration: 20
        }
      )
    ]).start();
  }

标签: reactjsreact-nativereact-native-androidreact-native-ios

解决方案


试试这个语法:

onPress = {() => {
    this.openList()
}}

推荐阅读