react-native - 以编程方式触发 TouchableOpacity.onPress
问题描述
我有一个用例,文件上传后我想打开包裹在里面的灯箱<TouchableOpacity>
这是我的代码。
<TouchableOpacity style={{marginRight: ms(10), borderRadius: ms(10), overflow: 'hidden'}}>
<Lightbox>
<FastImage
style={{width: ms(75), height: ms(75), borderRadius: ms(10)}}
source={{uri: this.props.image.path}}
/>
</Lightbox>
</TouchableOpacity>
灯箱没有任何以编程方式触发打开的事件,这是我正在使用的灯箱https://github.com/oblador/react-native-lightbox
我唯一的选择似乎是TouchableOpacity.onPress
在文件上传完成后以编程方式触发,尝试使用 ref 以下方式。
TouchableOpacity ref={component => this.touchable = component}
这给了this.touchable.props.onPress();
我一个错误,说未定义不是一个对象,当console.log(this.touchable)
我注意到它不是空的,但是当我这样做时console.log(this.touchable.props)
它说未定义,也许语法发生了变化,这似乎没有记录在案。
有没有办法以编程方式触发 onPress?
谢谢。
解决方案
Maybe try :
ref={(touchable) => this._touchable = touchable}
this._touchable.touchableHandlePress() //this?
推荐阅读
- c# - 如何为任何类型的通用类型窗口/页面实现 xaml 页面?
- azure - 更改 Azure ADDS 下仅 Azure AD 云帐户的最小密码长度
- android-databinding - DataBindingUtil.setContentView 偶尔返回 null 的可能原因是什么?
- javascript - 通过 ajax 数据设置的本地存储随机获取未定义
- azure-data-factory-2 - 数据工厂子项修改或创建日期
- ios - 什么会导致分段选取器控件“弹出”而不是滑动到新选择,仅在实际设备上?
- flutter - 颤振:输入'列表
' 不是 'Widget' 类型的子类型 - ios - 保存 UIDocument 失败并出现权限错误 - `NSCocoaErrorDomain` 代码 `513`
- php - 迁移到新服务器 Laravel 5.8 后页面丢失
- php - PHP XPath 确定是否选中了一个复选框?