Skip to content

Commit 1bd8ce3

Browse files
committed
feat: add Method isDragging
1 parent 5639225 commit 1bd8ce3

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Needs react-native >= 0.14.2
1616
- <b>paginationWrapStyle</b> style object, style of paginationWrap
1717
- <b>activePaginationStyle</b> style object, style of activePaginationStyle
1818

19+
####Method
20+
- <b>isDragging</b> return dragging or not
21+
1922
###Usage
2023

2124
####Step 1 - install

index.js

+21-28
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default class Slide extends React.Component{
3232

3333
constructor(props, context){
3434
super(props, context);
35+
this.dragging = false;
3536
}
3637

3738
componentWillMount(){
@@ -49,10 +50,6 @@ export default class Slide extends React.Component{
4950
componentWillReceiveProps(newProps){
5051
let newState = this._getStateFromProps(newProps);
5152
this.setState(newState);
52-
}
53-
54-
componentDidMount(){
55-
//this.state.autoPlay && this._autoPlay();
5653
React.Children.count(this.state.children) && this.state.autoPlay && this._autoPlay();
5754
}
5855

@@ -61,24 +58,9 @@ export default class Slide extends React.Component{
6158
}
6259

6360
_getStateFromProps(props){
64-
let height = props.height;
65-
let autoPlay = props.autoPlay;
66-
let loop = props.loop;
67-
let showPagination = props.showPagination;
68-
let paginationStyle = props.paginationStyle;
69-
let paginationWrapStyle = props.paginationWrapStyle;
70-
let activePaginationStyle = props.activePaginationStyle;
71-
let children = props.children;
7261
return {
73-
height,
74-
autoPlay,
75-
loop,
76-
showPagination,
77-
paginationStyle,
78-
paginationWrapStyle,
79-
activePaginationStyle,
80-
children
81-
}
62+
...props
63+
};
8264
}
8365

8466
_createPagination(){
@@ -110,6 +92,7 @@ export default class Slide extends React.Component{
11092

11193
_autoPlay(){
11294
var interval = this.state.autoPlay;
95+
clearTimeout(this.timer);
11396
this.timer = setTimeout(() => {
11497
if(Platform.OS === 'ios'){
11598
this.setState({
@@ -195,6 +178,10 @@ export default class Slide extends React.Component{
195178
}
196179
}
197180

181+
isDragging(){
182+
return this.dragging;
183+
}
184+
198185
render(){
199186
//first come may have no child, such as async get child
200187
if(!React.Children.count(this.state.children)){//this.state.children.length?
@@ -250,22 +237,28 @@ export default class Slide extends React.Component{
250237
ref={scrollView => this.scrollView = scrollView}
251238
style={styles.scrollView}
252239
initialPage={0}
240+
onPageScrollStateChanged={status => {
241+
//idle means not dragging
242+
if(status === 'idle'){
243+
this.dragging = false;
244+
}
245+
else if(status === 'dragging'){
246+
this.dragging = true;
247+
}
248+
else{
249+
this.dragging = false;
250+
}
251+
}}
253252
onPageScroll={e => {
254253
//this will trigger all the time when the view is sliding, but stops at e.nativeEvent.offset=0
255254
let {offset, position} = e.nativeEvent;
256255
if(offset === 0){
257256
this._moveEnd(position);
258257
}
259-
}}
260-
//user action
261-
onPageSelected={e => {
262-
263258
}}>
264259
{this._getChildren()}
265260
</ViewPagerAndroid>);
266-
// React.Children.map(this.props.children, child=>{
267-
// console.log(child);
268-
// });
261+
269262
return (
270263
<View style={[styles.container, {
271264
height: this.state.height

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-slide",
3-
"version": "0.1.6",
3+
"version": "0.2.0",
44
"description": "react-native-slide",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)