参考地址:https://www.jianshu.com/p/935e5c6a5064

官方文档地址:https://facebook.github.io/react-native/docs/panresponder.html

官方翻译地址:https://reactnative.cn/docs/0.50/panresponder.html

首先,通过react native引入PanResponder
import {PanResponder} from 'react-native';   //这里是当移动了超过20,才会进行隐藏或是显示
_panResponder = PanResponder.create({
        onStartShouldSetPanResponder: () => true,
onMoveShouldSetPanResponder: () => true,
onPanResponderGrant: () => {
console.log('开始移动:');
this.setState({ moveBG: '#eeeeee' })
},
onPanResponderMove: (evt, gs) => {
console.log('正在移动:X轴:' + gs.dx + ',Y轴:' + gs.dy);
},
onPanResponderRelease: (evt, gs) => {
console.log('结束移动:X轴:' + gs.dx + ',Y轴:' + gs.dy);
this.setState({
moveBG: '#FFF'
});
if (gs.dy > 20) {
this.setState({
IsShowOrderInfoFlag: true
})
} else if (gs.dy < -20) {
this.setState({
IsShowOrderInfoFlag: false
})
}
}
});

以上为声明手势响应,将手势响应方法放入至某一个View中

Render方法中
<View style={styles.container}>
{
this.state.IsShowOrderInfoFlag ?
<View style={[styles.headerView, { backgroundColor: '#e0e0e0' }]}>
<Text style={styles.orderInfoLabel}>{I18n.t('Component.HandmadeCheck.ComponentValue.Order.zdCode_Text')}{this.props.bundleEntity.bundleInfo.zdCode}</Text>
<Text style={styles.orderInfoLabel}>{I18n.t('Component.HandmadeCheck.ComponentValue.Order.Customer_Text')}{this.props.bundleEntity.bundleInfo.custName}|{this.props.bundleEntity.bundleInfo.custCode}</Text>
<Text style={styles.orderInfoLabel}>{I18n.t('Component.HandmadeCheck.ComponentValue.Bundle.Bundle_Text')}{this.props.bundleEntity.bundleInfo.bundle.groupNo}</Text>
</View>
:
null
}
<View style={[styles.headerView, { backgroundColor: this.state.moveBG }]} {...this._panResponder.panHandlers}>
<Text style={styles.headerLabel}>{I18n.t('Component.HandmadeCheck.ComponentValue.QAComment_Text')}</Text>
<TextInput style={styles.qaCommentText}
placeholder={I18n.t('Component.HandmadeCheck.ComponentValue.QAComment_Placeholder')}
maxLength={10000}
multiline={true}
returnKeyType='done'
onChangeText={(text) => {
let oldHandmadeCheckData = this.state.HandmadeCheckData;
oldHandmadeCheckData.QAComment = text;
this.setState({ HandmadeCheckData: oldHandmadeCheckData })
}}
value={this.state.HandmadeCheckData.QAComment}
/>
<Button onPress={() => {
this._removeQAComment();
}}>
<Icon style={styles.removeQACommentIcon} name="remove" size={32} />
</Button>
<Button onPress={() => {
this.refs.qaCommentModal.showQACommentModal(this.props.handmadeCheckEntity.AllQACommentList, this);
}}>
<Icon style={styles.qaCommentIcon} name="comment" size={32} />
</Button> <Text style={styles.headerLabel}>{I18n.t('Component.HandmadeCheck.ComponentValue.Pass_Product_Count_Text')}</Text>
<TextInput style={styles.EditText}
placeholder={I18n.t('Component.HandmadeCheck.ComponentValue.Pass_Product_Count_Placeholder')}
editable={true}
keyboardType='numeric'
returnKeyType='done'
value={this.state.PassProductCount}
onBlur={() => {
this.props.onSetPassProduct(this.state.PassProductCount)
}}
onChangeText={(text) => {
this.setState({ PassProductCount: text })
}}
/>
<Text style={styles.headerLabel}>{I18n.t('Component.HandmadeCheck.ComponentValue.Can_Not_Rework_Product_Count_Text')}</Text>
<TextInput style={styles.EditText}
placeholder={I18n.t('Component.HandmadeCheck.ComponentValue.Can_Not_Rework_Product_Count_Placeholder')}
editable={true}
keyboardType='numeric'
returnKeyType='done'
value={this.state.CanNotReworkProductCount}
onBlur={() => {
this.props.onSetCannotReworkProduct(this.state.CanNotReworkProductCount)
}}
onChangeText={(text) => {
this.setState({ CanNotReworkProductCount: text })
}}
/>
</View>
{
this.state.IsShowOrderInfoFlag ?
<View style={styles.headerView}>
<Text style={styles.headerLabel}>{I18n.t('Component.HandmadeCheck.ComponentValue.CheckTime_Text')}</Text>
<TextInput style={styles.checkTimeText}
placeholder={I18n.t('Component.HandmadeCheck.ComponentValue.CheckTime_Placeholder')}
editable={false}
keyboardType='numeric'
returnKeyType='done'
value={this.state.HandmadeCheckData.CheckTime}
/>
<Text style={styles.headerLabel}>{I18n.t('Component.HandmadeCheck.ComponentValue.Request_Check_Count_Text')}</Text>
<TextInput style={styles.checkTimeText}
placeholder={I18n.t('Component.HandmadeCheck.ComponentValue.Request_Check_Count_Placeholder')}
editable={false}
keyboardType='numeric'
returnKeyType='done'
value={this.state.RequestCheckCount}
/>
<Text style={styles.headerLabel}>{I18n.t('Component.HandmadeCheck.ComponentValue.Issue_Product_Count_Text')}</Text>
<TextInput style={styles.checkTimeText}
placeholder={I18n.t('Component.HandmadeCheck.ComponentValue.Issue_Product_Count_Placeholder')}
editable={false}
keyboardType='numeric'
returnKeyType='done'
value={this.state.IssueProductCount}
/>
<Text style={styles.headerLabel}>{I18n.t('Component.HandmadeCheck.ComponentValue.Handmade_Issue_Product_Count_Text')}</Text>
<TextInput style={styles.checkTimeText}
placeholder={I18n.t('Component.HandmadeCheck.ComponentValue.Handmade_Issue_Product_Count_Placeholder')}
editable={false}
keyboardType='numeric'
returnKeyType='done'
value={this.state.HandmadeIssueProductCount}
/>
<Text style={styles.headerLabel}>{I18n.t('Component.HandmadeCheck.ComponentValue.Non_Handmade_Issue_Product_Count_Text')}</Text>
<TextInput style={styles.checkTimeText}
placeholder={I18n.t('Component.HandmadeCheck.ComponentValue.Non_Handmade_Issue_Product_Count_Placeholder')}
editable={false}
keyboardType='numeric'
returnKeyType='done'
value={this.state.NonHandmadeIssueProductCount}
/>
</View>
: null
}

效果

react native 手势响应的更多相关文章

  1. 混合开发的大趋势之一React Native手势行为那些事

    转载请注明出处:王亟亟的大牛之路 最近项目部分模块重构,事情有点多,学习进度有所延缓,外加一直在吸毒(wow你懂的),导致好多天没发问了,其实这部分知识月头就想写了,一直没补. 话不多说先安利:htt ...

  2. [转] 「指尖上的魔法」 - 谈谈 React Native 中的手势

    http://gold.xitu.io/entry/55fa202960b28497519db23f React-Native是一款由Facebook开发并开源的框架,主要卖点是使用JavaScrip ...

  3. 【React Native】进阶指南之二(手势响应系统)

    移动设备上的手势识别要比在 web 上复杂得多.用户的一次触摸操作的真实意图是什么,App 要经过好几个阶段才能判断.比如 App 需要判断用户的触摸到底是在滚动页面,还是滑动一个 widget,或者 ...

  4. [技术博客]react native事件监听、与原生通信——实现对通知消息的响应

    在react native中会涉及到很多页面之间的参数传递问题.静态的参数传递通常利用组件的Props属性,在初始化组件时即可从父组件中将参数传递到子组件中.对于非父子关系的组件来说,无法直接传递参数 ...

  5. 如何让你的 React Native 应用在键盘弹出时优雅地响应

    原文地址:How to make your React Native app respond gracefully when the keyboard pops up 原文作者:Spencer Car ...

  6. React Native之 Navigator与NavigatorIOS使用

    前言 学习本系列内容需要具备一定 HTML 开发基础,没有基础的朋友可以先转至 HTML快速入门(一) 学习 本人接触 React Native 时间并不是特别长,所以对其中的内容和性质了解可能会有所 ...

  7. React Native之 ScrollView介绍和使用

    前言 学习本系列内容需要具备一定 HTML 开发基础,没有基础的朋友可以先转至 HTML快速入门(一) 学习 本人接触 React Native 时间并不是特别长,所以对其中的内容和性质了解可能会有所 ...

  8. React Native 之 Touchable 介绍与使用

    前言 学习本系列内容需要具备一定 HTML 开发基础,没有基础的朋友可以先转至 HTML快速入门(一) 学习 本人接触 React Native 时间并不是特别长,所以对其中的内容和性质了解可能会有所 ...

  9. React Native APP结构探索

    APP结构探索 我在Github上找到了一个有登陆界面,能从网上获取新闻信息的开源APP,想来研究一下APP的结构. 附上原网址:我的第一个React Native App 具体来讲,就是研究一个复杂 ...

随机推荐

  1. 轮廓问题/Outline Problem

    --------------------------------------------------- //已发布改进后的轮廓问题算法:http://www.cnblogs.com/andyzeng/ ...

  2. ES6 利用集合Set解决数组 交集 并集 差集的问题

    根据阮一峰老师的ES6教程自己体会而写的,希望能给一些朋友有帮助到 let a = new Set([1,2,3,4]) let b = new Set([2,3,4,5,]) 并集 let unio ...

  3. [LeetCode] 16. 3Sum Closest ☆☆☆

    Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...

  4. Item27--优先考虑泛型方法

    类型推导:发生在以下三个地方.1.Java编译器根据泛型方法传入的参数,推导出具体的类型.2.Java编译器,根据泛型构造器传入的类型来推导出实际要构造的实例类型.3.Java编译器根据表达式的目标类 ...

  5. 【poj1901-求区间第k大值(带修改)】树状数组套主席树

    901: Zju2112 Dynamic Rankings Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 7025  Solved: 2925[Sub ...

  6. Spring注解概览(数漫江湖)

    从Java5.0开始,Java开始支持注解.Spring做为Java生态中的领军框架,从2.5版本后也开始支持注解.相比起之前使用xml来配置Spring框架,使用注解提供了更多的控制Spring框架 ...

  7. 某labs上传writeup-上传漏洞总结

    github:https://github.com/d0ef/upload-labs 第一题:通过JS判断的直接抓包改了就ok. 第二题:只要Content-Type信息为图片的就可以 第三题:通过上 ...

  8. github删除文件夹

    git rm -rf dirgit add .git commit -m 'remove dir'git push origin master //dir是要删除的文件夹路径

  9. 【Python学习】程序运行完发送邮件提醒

    有时候我们运行一个需要跑很长时间的程序,不管是在云主机还是本地主机上运行,我们都不可能一直守在电脑面前等.所以想到使用邮件来通知提醒. 示例代码如下 # -*- coding: utf-8 -*- # ...

  10. Reactor与Proactor区别

    如网络编程中accept之后等待数据到达,并且读取数据为例: Reactor: 基于同步IO 1. 线程等待读取socket数据,将socketfd添加到事件分派器中,如添加到epoll: 2. 事件 ...