按下时不会触发onPress功能

时间:2018-08-07 21:04:35

标签: reactjs react-native react-native-android react-native-ios

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

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

<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();
  }

1 个答案:

答案 0 :(得分:0)

尝试以下语法:

onPress = {() => {
    this.openList()
}}
相关问题