react-native-lib-cus-com
Version:
react-native 自定义辅助组件库,完美的网路请求,带加载条,可上传、下载文件,等等多种ui,可自定义删除;可节省应用级软件的开发时间
64 lines (52 loc) • 1.55 kB
JavaScript
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {
View,
} from 'react-native';
/**
* View的升级版 增加左右滑动事件
* **/
export class ViewCtrl extends Component {
//属性注释及类型,所有的属性对象都是句柄模式(类型时number),类似C语言中的指针
static propTypes = {
onSwipeLeft:PropTypes.func,//左滑事件
onSwipeRight:PropTypes.func,//右边滑事件
}
/**
* 设置默认属性
* **/
static defaultProps = {
isShowPillar:true,
isShowIconLeft:true,
isShowIconRight:true,
isShowIconCenter:true,
isDateUse:true,
dateFormat:'YYYY年MM月',
isDateToCur:true,
}
constructor(props) {
super(props);
this.viewLayoutStart = {};
}
_onResponderRelease = (e)=>{
const {onSwipeLeft,onSwipeRight} = this.props;
if((e.nativeEvent.pageX - this.viewLayoutStart.pageX) > 0){
onSwipeRight&&onSwipeRight(e);
}
else if((e.nativeEvent.pageX - this.viewLayoutStart.pageX) < 0){
onSwipeLeft&&onSwipeLeft(e);
}
}
render() {
return(
<View {...this.props}
onMoveShouldSetResponder={(e)=>{
this.viewLayoutStart = e.nativeEvent;
return true;
}}
onResponderRelease={this._onResponderRelease}>
{this.props.children}
</View>
);
}
}