@@ -26,6 +26,7 @@ class Carousel extends React.Component {
2626 swipedSliderPosition : 0 ,
2727 isSwiping : false ,
2828 transitioning : false ,
29+ transitionMs : this . props . transitionMs ,
2930 activeIndex : this . props . initialActiveIndex || this . props . initialFirstItem , // support deprecated initialFirstItem
3031 pages : [ ] ,
3132 activePage : 0 ,
@@ -168,7 +169,8 @@ class Carousel extends React.Component {
168169 const {
169170 children,
170171 verticalMode,
171- itemsToShow
172+ itemsToShow,
173+ transitionMs
172174 } = this . getDerivedPropsFromBreakPoint ( ) ;
173175 const { childWidth, childHeight, activeIndex } = state ;
174176 const totalItems = children . length ;
@@ -181,6 +183,10 @@ class Carousel extends React.Component {
181183 let sliderPosition = ( verticalMode ? childHeight : childWidth ) * moveBy ;
182184 const newActiveIndex =
183185 emptySlots > 0 ? activeIndex - emptySlots : activeIndex ;
186+ // go back from 0ms to whatever set by the user
187+ // We were at 0ms because we wanted to disable animation on resize
188+ // see https://github.com/sag1v/react-elastic-carousel/issues/94
189+ window . requestAnimationFrame ( ( ) => this . setState ( { transitionMs } ) ) ;
184190 return {
185191 sliderPosition,
186192 activeIndex : newActiveIndex < 0 ? 0 : newActiveIndex
@@ -209,7 +215,8 @@ class Carousel extends React.Component {
209215 onContainerResize = sliderContainerNode => {
210216 const { width } = sliderContainerNode . contentRect ;
211217 // update slider container width
212- this . setState ( { sliderContainerWidth : width } , ( ) => {
218+ // disable animation on resize see https://github.com/sag1v/react-elastic-carousel/issues/94
219+ this . setState ( { sliderContainerWidth : width , transitionMs : 0 } , ( ) => {
213220 // we must get these props inside setState (get future props because its async)
214221 const {
215222 onResize,
@@ -334,23 +341,28 @@ class Carousel extends React.Component {
334341 divider = largeDivider ;
335342 }
336343
337- let distanceSwipe = verticalMode
344+ const distanceSwipe = verticalMode
338345 ? rootHeight / divider
339346 : sliderContainerWidth / divider ;
340347
341- const isHorizontalSwipe = dir === "Left" || dir === "Right" ;
348+ const horizontalSwipe = dir === "Left" || dir === "Right" ;
349+ const verticalSwipe = dir === "Up" || dir === "Down" ;
350+ const horizontalMode = ! verticalMode ;
342351
343352 const shouldHorizontalSkipUpdate =
344- isHorizontalSwipe && ( ! verticalMode && absX > distanceSwipe ) ;
353+ ( horizontalMode && verticalSwipe ) ||
354+ ( horizontalMode && horizontalSwipe && absX > distanceSwipe ) ;
355+
345356 const shouldVerticalSkipUpdate =
346- ! isHorizontalSwipe && ( verticalMode && absY > distanceSwipe ) ;
357+ ( verticalMode && horizontalSwipe ) ||
358+ ( verticalMode && verticalSwipe && absY > distanceSwipe ) ;
347359
348360 if ( shouldHorizontalSkipUpdate || shouldVerticalSkipUpdate ) {
349361 // bail out of state update
350362 return ;
351363 }
352364 return {
353- swipedSliderPosition : isHorizontalSwipe
365+ swipedSliderPosition : horizontalSwipe
354366 ? sliderPosition - deltaX
355367 : sliderPosition - deltaY ,
356368 isSwiping : true ,
@@ -366,19 +378,24 @@ class Carousel extends React.Component {
366378 // 3. vertical mode - swipe up or down
367379
368380 const { absX, absY, dir } = data ;
369- const { childWidth } = this . state ;
381+ const { childWidth, childHeight } = this . state ;
370382 const { verticalMode, isRTL } = this . props ;
371383 let func = this . resetSwipe ;
372- const minSwipeDistance = childWidth / 3 ;
384+ const minSwipeDistanceHorizontal = childWidth / 3 ;
385+ const minSwipeDistanceVertical = childHeight / 3 ;
373386 const swipedLeft = dir === "Left" ;
374387 const swipedRight = dir === "Right" ;
375388 const swipedUp = dir === "Up" ;
376389 const swipedDown = dir === "Down" ;
377390 const verticalGoSwipe =
378- verticalMode && ( swipedUp || swipedDown ) && absY > minSwipeDistance ;
391+ verticalMode &&
392+ ( swipedUp || swipedDown ) &&
393+ absY > minSwipeDistanceVertical ;
379394
380395 const horizontalGoSwipe =
381- ! verticalMode && ( swipedRight || swipedLeft ) && absX > minSwipeDistance ;
396+ ! verticalMode &&
397+ ( swipedRight || swipedLeft ) &&
398+ absX > minSwipeDistanceHorizontal ;
382399
383400 let goodToGo = false ;
384401 if ( verticalGoSwipe || horizontalGoSwipe ) {
@@ -585,7 +602,8 @@ class Carousel extends React.Component {
585602 swipedSliderPosition,
586603 rootHeight,
587604 pages,
588- activeIndex
605+ activeIndex,
606+ transitionMs
589607 } = this . state ;
590608 const {
591609 className,
@@ -595,7 +613,6 @@ class Carousel extends React.Component {
595613 isRTL,
596614 easing,
597615 tiltEasing,
598- transitionMs,
599616 children,
600617 focusOnSelect,
601618 autoTabIndexVisibleItems,
@@ -663,6 +680,7 @@ class Carousel extends React.Component {
663680 ref = { this . setRef ( "slider" ) }
664681 >
665682 < Track
683+ verticalMode = { verticalMode }
666684 children = { children }
667685 childWidth = { childWidth }
668686 currentItem = { activeIndex }
@@ -742,6 +760,7 @@ Carousel.defaultProps = {
742760 autoPlaySpeed : 2000 ,
743761
744762 // callbacks
763+ onChange : noop ,
745764 onNextEnd : noop ,
746765 onPrevEnd : noop ,
747766 onNextStart : noop ,
0 commit comments