reactjs – 禁用TouchableHighlight onPress?
发布时间:2020-12-15 09:34:05 所属栏目:百科 来源:网络整理
导读:如果其中一个被按下,如何禁用TouchableHighlight组?可能吗 ?例如,我有listview,每行有两个TouchableHighlights.如果其中一个按下,我想禁用这两个触摸的onPress功能. 解决方法 我解决了这个问题方法如下: 首先,感谢James Ide用于0700道具的超赞button组件.
如果其中一个被按下,如何禁用TouchableHighlight组?可能吗 ?例如,我有listview,每行有两个TouchableHighlights.如果其中一个按下,我想禁用这两个触摸的onPress功能.
解决方法
我解决了这个问题方法如下:
首先,感谢James Ide用于0700道具的超赞button组件. 我为按钮组编写了自定义组件–main.js–.并使用禁用道具禁用按钮组. index.ios.js: class PNTest extends React.Component{ constructor(props){ super(props) this.state ={ clicked: [] } } render(){ return( <View style={styles.container}> <Main handleClick={this._handleClick.bind(this)} left={1} right={2} name={'group1'}/> <Main handleClick={this._handleClick.bind(this)} left={3} right={4} name={'group2'}/> <Text style={styles.welcome}> {this.state.clicked} </Text> </View> ); } _handleClick(id,group){ this.state.clicked.push(id); console.log(group + ' now inactive and clicked button id: ' + id); console.log('clicked button ids: ' + this.state.clicked); } } main.js: class Main extends React.Component{ constructor(props){ super(props) this.state = { disabled: false,left: {},right: {} } } render(){ return( <View style={styles.container}> <Button disabled={this.state.disabled} style={[styles.buttonContainer,this.state.left]} onPress={() => this._onPress(this.props.left)}> Left </Button> <Button disabled={this.state.disabled} style={[styles.buttonContainer,this.state.right]} onPress={() => this._onPress(this.props.right)}> Right </Button> </View> ); } _onPress(id){ var left = {}; var right = {}; if(id === this.props.left){ left = styles.buttonSelected; right = styles.buttonNotSelected; }else if(id === this.props.right){ right = styles.buttonSelected; left = styles.buttonNotSelected; } this.setState({ disabled: true,left: left,right: right }); this.props.handleClick(id,this.props.name); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 反应本机 – 列表视图顶部的覆盖视图?
- dart – Flutter ListView,SliverList等内的当前滚动偏移量
- DWR3.0推送技术实现QQ即时通信功能(1)
- 借鉴的正则-验证数值长度15,包含3位小数
- vb6 – 如何从命令行更改EXE或DLL版本号?
- c# – 使用iTextSharp创建图像水印到Pdf
- react-native – React Native中的Superscript Text
- 详谈Ajax请求中的async:false/true的作用(ajax 在外部调用问
- xcode – 使用swift为Mac应用程序获得管理权限
- 正则匹配密码只能是数字和字母组合字符串功能【php与js实现