2
2
* Created by zhouyunkui on 2017/6/9.
3
3
*/
4
4
/* eslint-disable */
5
- import React , { Component } from 'react' ;
5
+ import React , { Component } from 'react' ;
6
6
import PropTypes from 'prop-types' ;
7
7
import './Slide.less' ;
8
- import { preventDocMove , offPreventDefault , } from '../../pages/example/common/js/preventDocMove' ;
8
+ import { preventDocMove , offPreventDefault , } from '../../pages/example/common/js/preventDocMove' ;
9
9
const VERTICAL = 'vertical' ,
10
10
HORIZONTAL = 'horizontal' ;
11
11
export class Slide extends Component {
@@ -38,20 +38,20 @@ export class Slide extends Component {
38
38
}
39
39
constructor ( options ) {
40
40
super ( options ) ;
41
- const { children, defaultActiveIndex, activeIndex, width, height, } = this . props ;
41
+ const { children, defaultActiveIndex, activeIndex, width, height, } = this . props ;
42
42
const count = React . Children . count ( children ) ;
43
43
this . state = {
44
44
transform : - ( defaultActiveIndex * width ) ,
45
- transition : 'transition' ,
46
- region : this . progressRegion ( { width, count } ) ,
45
+ transition : false ,
46
+ region : this . progressRegion ( { width, count } ) ,
47
47
activeIndex : activeIndex ,
48
48
width : width ,
49
49
height : height ,
50
50
}
51
51
}
52
52
getSlidePane = ( ) => {
53
- const { children } = this . props ;
54
- const { width, height } = this . state ;
53
+ const { children } = this . props ;
54
+ const { width, height } = this . state ;
55
55
return React . Children . map ( children , ( child ) => {
56
56
if ( ! child ) return ;
57
57
const order = parseInt ( child . props . order , 10 ) ;
@@ -69,8 +69,8 @@ export class Slide extends Component {
69
69
* @returns {boolean }
70
70
*/
71
71
slideFeedbackSwitch = ( direction ) => {
72
- const { slideFeedback, children, } = this . props ;
73
- const { activeIndex } = this . state ;
72
+ const { slideFeedback, children, } = this . props ;
73
+ const { activeIndex } = this . state ;
74
74
const count = React . Children . count ( children ) ;
75
75
if ( ! slideFeedback ) {
76
76
if ( direction === - 1 ) {
@@ -88,8 +88,8 @@ export class Slide extends Component {
88
88
return true ;
89
89
}
90
90
whenSlideReachFeedbackTransformLimit = ( transformDistance ) => {
91
- const { region } = this . state ;
92
- const { slideFeedbackTransformLimit, slideFeedback, } = this . props ;
91
+ const { region } = this . state ;
92
+ const { slideFeedbackTransformLimit, slideFeedback, } = this . props ;
93
93
const first = region [ 0 ] ;
94
94
const last = region [ region . length - 1 ] ;
95
95
const howFarFromBeginToCurrent = transformDistance - first ,
@@ -112,17 +112,17 @@ export class Slide extends Component {
112
112
return finalTransformDistance ;
113
113
}
114
114
start = ( event ) => {
115
- const { preSlide } = this . props ;
116
- const { activeIndex } = this . state ;
117
- preSlide ? preSlide ( { activeIndex, } ) : '' ;
115
+ const { preSlide } = this . props ;
116
+ const { activeIndex } = this . state ;
117
+ preSlide ? preSlide ( { activeIndex, } ) : '' ;
118
118
this . startX = event . changedTouches [ 0 ] . clientX ;
119
119
this . startY = event . changedTouches [ 0 ] . clientY ;
120
120
this . switchRate = undefined ;
121
121
this . preventDocMove = false ;
122
122
this . cacheTransform = this . state . transform ;
123
123
}
124
124
move = ( event ) => {
125
- const { layout } = this . props ;
125
+ const { layout } = this . props ;
126
126
this . moveX = event . changedTouches [ 0 ] . clientX ;
127
127
this . moveY = event . changedTouches [ 0 ] . clientY ;
128
128
let currentMove ;
@@ -145,14 +145,14 @@ export class Slide extends Component {
145
145
let transformDistance = this . whenSlideReachFeedbackTransformLimit ( this . cacheTransform + currentMove ) ;
146
146
this . setState ( {
147
147
transform : transformDistance ,
148
- transition : ''
148
+ transition : false
149
149
} )
150
150
}
151
151
}
152
152
end = ( event ) => {
153
153
this . preventDocMove = false ;
154
- const { afterSlide, layout, } = this . props ;
155
- const { transform, } = this . state ;
154
+ const { afterSlide, layout, } = this . props ;
155
+ const { transform, } = this . state ;
156
156
this . endX = event . changedTouches [ 0 ] . clientX ;
157
157
this . endY = event . changedTouches [ 0 ] . clientY
158
158
let distance ;
@@ -162,16 +162,16 @@ export class Slide extends Component {
162
162
distance = this . endY - this . startY ;
163
163
}
164
164
const direction = distance > 0 ? 1 : ( distance < 0 ? - 1 : 0 ) ;
165
- const { transform : newTransform , index : activeIndex } = this . onlySlideInRegion ( direction ) ;
165
+ const { transform : newTransform , index : activeIndex } = this . onlySlideInRegion ( direction ) ;
166
166
this . setState ( {
167
167
transform : newTransform ,
168
- transition : 'transition' ,
168
+ transition : true ,
169
169
activeIndex : activeIndex
170
170
} , ( ) => {
171
- afterSlide ? afterSlide ( { activeIndex, } ) : '' ;
171
+ afterSlide ? afterSlide ( { activeIndex, } ) : '' ;
172
172
} )
173
173
}
174
- binaryChop = ( { region, target, direction } ) => {
174
+ binaryChop = ( { region, target, direction } ) => {
175
175
//此处region由大到小排列
176
176
let left = 0 ,
177
177
right = region . length - 1 ,
@@ -216,7 +216,7 @@ export class Slide extends Component {
216
216
//手指向右滑动
217
217
distance = target - region [ result [ 1 ] ] ;
218
218
}
219
- const { transformLimit } = this . props ;
219
+ const { transformLimit } = this . props ;
220
220
if ( distance >= transformLimit ) {
221
221
if ( direction === - 1 ) {
222
222
return {
@@ -258,8 +258,8 @@ export class Slide extends Component {
258
258
}
259
259
}
260
260
onlySlideInRegion = ( direction ) => {
261
- const { region, transform : target } = this . state ;
262
- return this . binaryChop ( { region, target, direction } ) ;
261
+ const { region, transform : target } = this . state ;
262
+ return this . binaryChop ( { region, target, direction } ) ;
263
263
}
264
264
progressRegion = ( { size, count} ) => {
265
265
const region = [ ] ;
@@ -277,39 +277,39 @@ export class Slide extends Component {
277
277
//获取元素宽度和高度,因为css中对Slide中的包裹元素设置了width和height都是100%。经历两次render
278
278
getLayout = ( instance ) => {
279
279
if ( ! instance ) return ;
280
- const { children, layout, defaultActiveIndex, } = this . props ;
280
+ const { children, layout, defaultActiveIndex, } = this . props ;
281
281
const count = React . Children . count ( children ) ;
282
282
const width = instance . offsetWidth ,
283
283
height = instance . offsetHeight ;
284
284
const size = ( layout === HORIZONTAL ) ? width : height ;
285
285
this . setState ( {
286
286
width,
287
287
height,
288
- region : this . progressRegion ( { size, count } ) ,
289
- transform : - ( defaultActiveIndex * size ) ,
288
+ region : this . progressRegion ( { size, count } ) ,
289
+ transform : - ( defaultActiveIndex * size )
290
290
} )
291
291
}
292
292
componentDidMount ( ) {
293
- preventDocMove . call ( this ) ;
293
+ preventDocMove . call ( this ) ;
294
294
}
295
295
componentWillUnmount ( ) {
296
- offPreventDefault . call ( this ) ;
296
+ offPreventDefault . call ( this ) ;
297
297
}
298
298
render ( ) {
299
299
console . log ( 'Slide' )
300
- const { children, style, className, layout, } = this . props ;
301
- const { width, height, transition, transform, } = this . state ;
300
+ const { children, style, className, layout, } = this . props ;
301
+ const { width, height, transition, transform, } = this . state ;
302
302
const count = React . Children . count ( children ) ;
303
303
const styleOfSlideCollection = {
304
- width : `${ layout === HORIZONTAL ? width * count : width } px` ,
305
- height : `${ layout === HORIZONTAL ? height : height * count } px` ,
306
- transform : `translate${ layout === HORIZONTAL ? 'X' : 'Y' } (${ transform } px)` ,
307
- WebkitTransform : `translate${ layout === HORIZONTAL ? 'X' :'Y' } (${ transform } px)` ,
308
- transition : `${ transition ? 'transform .6s cubic-bezier(.53,.54,.02,.99)' : '' } ` ,
309
- WebkitTransition : `${ transition ? '-webkit-transform .6s cubic-bezier(.53,.54,.02,.99)' : '' } `
304
+ width : `${ layout === HORIZONTAL ? width * count : width } px` ,
305
+ height : `${ layout === HORIZONTAL ? height : height * count } px` ,
306
+ transform : `translate${ layout === HORIZONTAL ? 'X' : 'Y' } (${ transform } px)` ,
307
+ WebkitTransform : `translate${ layout === HORIZONTAL ? 'X' :'Y' } (${ transform } px)` ,
308
+ transition : `${ transition ? 'transform .6s cubic-bezier(.53,.54,.02,.99)' : '' } ` ,
309
+ WebkitTransition : `${ transition ? '-webkit-transform .6s cubic-bezier(.53,.54,.02,.99)' : '' } `
310
310
} ;
311
311
const wrapClassName = `slide-wrap ${ className } ` ;
312
- return < div ref = { this . getLayout } className = { wrapClassName } style = { style } >
312
+ return < div ref = { this . getLayout } className = { wrapClassName } style = { style } >
313
313
< div
314
314
className = { `slide-collection` }
315
315
style = { styleOfSlideCollection }
@@ -340,14 +340,14 @@ export class SlideItem extends Component {
340
340
}
341
341
render ( ) {
342
342
console . log ( 'SlideItem' )
343
- const { width, height, style, className, children, } = this . props ;
343
+ const { width, height, style, className, children, } = this . props ;
344
344
const styleOfSlidePane = Object . assign ( { } , style , {
345
345
width : `${ width } px` ,
346
346
height : `${ height } px` ,
347
347
} )
348
348
const sectionClassName = `slide-item ${ className } ` ;
349
349
return < section className = { sectionClassName } style = { styleOfSlidePane } >
350
- { children }
350
+ { children }
351
351
</ section >
352
352
}
353
353
}
0 commit comments