Skip to content

Commit 23c704e

Browse files
committed
ok
1 parent 06f81f2 commit 23c704e

File tree

3 files changed

+15
-314
lines changed

3 files changed

+15
-314
lines changed

react-swipeable/src/App.js

Lines changed: 10 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,8 @@
11
import React, {Component} from "react";
2-
import SwipeableViews from "react-swipeable-views";
3-
import virtualize from "react-swipeable-views/lib/virtualize";
4-
import mod from "react-swipeable-views/lib/utils/mod";
5-
6-
const EnhancedSwipeableViews = virtualize(SwipeableViews);
7-
8-
const CONFIG = {
9-
loop: true
10-
}
2+
import CustomAutoPlay from "./CustomAutoPlay";
113

124
class App extends Component {
13-
14-
constructor(props) {
15-
super(props);
16-
this.state = {index: 0};
17-
}
18-
19-
componentWillUnmount() {
20-
clearInterval(this.timer);
21-
}
22-
23-
timer = null;
24-
25-
slideRenderer = (params, children)=> {
26-
let childrenLength = children.length;
27-
const {index, key} = params;
28-
if (mod(index, childrenLength) < childrenLength) {
29-
return this.dealChild(children[mod(index, childrenLength)], key)
30-
}
31-
return null
32-
}
33-
34-
middle = (params)=> {
5+
render() {
356
let children = [
367
<div id="test">
378
{'slide n°0'}
@@ -42,79 +13,16 @@ class App extends Component {
4213
<div id="test">
4314
{'slide n°2'}
4415
</div>,
16+
<div id="test">
17+
{'slide n°3'}
18+
</div>,
4519
];
4620

47-
return this.slideRenderer(params, children);
48-
}
49-
50-
51-
dealChild = (div, key)=> {
52-
return <div key={key}>
53-
{div}
54-
</div>
55-
}
56-
57-
componentDidMount() {
58-
this.startInterval();
59-
}
60-
61-
62-
startInterval(interval = 2000) {
63-
if (CONFIG.loop != true) {
64-
return
65-
}
66-
clearInterval(this.timer);
67-
this.timer = setInterval(this.handleInterval, interval);
68-
}
69-
70-
handleInterval = () => {
71-
const indexLatest = this.state.index;
72-
//Todo use props.children.length
73-
let indexNew = mod((indexLatest + 1), 3);
74-
console.info('setTimer:indexNew' + indexNew)
75-
this.setState({
76-
index: indexNew,
77-
});
78-
};
79-
80-
81-
onChangeIndex = (index, indexLatest)=> {
82-
console.info('onChangeIndexindex:[' + index + "]===indexLatest[" + indexLatest + "]---this.state.index=[" + (this.state.index) + "]")
83-
let stateIndex = this.state.index;
84-
if ((index - indexLatest) > 0) {
85-
stateIndex = (stateIndex + 1);
86-
} else if ((index - indexLatest) < 0) {
87-
stateIndex = (stateIndex - 1);
88-
}
89-
console.info('result===' + stateIndex + "mod=" + (mod(stateIndex, 3)));
90-
this.setState({
91-
index: stateIndex
92-
})
93-
}
94-
95-
handleSwitching = (index, type) => {
96-
if (this.timer) {
97-
console.error('clear timer');
98-
clearInterval(this.timer);
99-
this.timer = null;
100-
} else if (type === 'end') {
101-
console.error('start timer');
102-
this.startInterval();
103-
}
104-
105-
console.log('invoke handleSwitching');
106-
};
107-
108-
109-
render() {
110-
let {index}=this.state;
111-
return (
112-
<EnhancedSwipeableViews
113-
index={index}
114-
onSwitching={this.handleSwitching}
115-
onChangeIndex={this.onChangeIndex}
116-
slideRenderer={this.middle}/>
117-
);
21+
return <CustomAutoPlay
22+
children={children}
23+
autoplay={true}
24+
interval={3500}
25+
/>;
11826
}
11927
}
12028

react-swipeable/src/autoplay.js renamed to react-swipeable/src/CustomAutoPlay.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import mod from "react-swipeable-views/lib/utils/mod";
1111
const EnhancedSwipeableViews = virtualize(SwipeableViews);
1212

1313

14-
class App extends Component {
14+
class CustomAutoPlay extends Component {
1515

1616
constructor(props) {
1717
super(props);
@@ -21,7 +21,7 @@ class App extends Component {
2121
static defaultProps = {
2222
autoplay: true,
2323
index: 0,
24-
interval: 3000,
24+
interval: 1000,
2525
};
2626

2727
componentWillUnmount() {
@@ -78,9 +78,9 @@ class App extends Component {
7878
onChangeIndex = (index, indexLatest)=> {
7979
let stateIndex = this.state.index;
8080
if ((index - indexLatest) > 0) {
81-
stateIndex = (stateIndex + 1);
81+
stateIndex += 1;
8282
} else if ((index - indexLatest) < 0) {
83-
stateIndex = (stateIndex - 1);
83+
stateIndex -= 1;
8484
}
8585
this.setState({
8686
index: stateIndex
@@ -100,7 +100,6 @@ class App extends Component {
100100

101101
render() {
102102
let {index}=this.state;
103-
let {children, autoplay, interval}=this.props;
104103
return (
105104
<EnhancedSwipeableViews
106105
index={index}
@@ -112,4 +111,4 @@ class App extends Component {
112111
}
113112

114113

115-
export default Autoplay;
114+
export default CustomAutoPlay;

react-swipeable/src/autoPlay.js

Lines changed: 0 additions & 206 deletions
This file was deleted.

0 commit comments

Comments
 (0)