reactjs - 按下时 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();
}
解决方案
试试这个语法:
onPress = {() => {
this.openList()
}}
推荐阅读
- oracle - Oracle SQL 开发人员数据建模器 - 复合键
- c# - 如何使 IActionFilter 可用于剃须刀页面?
- python - Python 无法长时间调度
- graphql - 如何过滤分配给 GraphQL 中别名的值?
- algorithm - 当除数尾数全为零时的浮点算法 - 比如在 2.0 in 的情况下 - IEEE -754
- r - 如何创建基于同一行中另一列的值命名的新列?
- konvajs - 通过从 Konvajs 的空白区域拖动来拖动变压器的最佳方法是什么?
- c# - .Net Core 3.1 身份中具有角色的用户列表
- fatal-error - 当我在 django 3 中使用“git push heroku master”时出现致命错误,“heroku open”出现“应用程序错误”
- flutter - 显示返回的 JSON