Skip to content

Commit

Permalink
added dontAnimate argument to slickGoTo method
Browse files Browse the repository at this point in the history
fixes: akiran#488
  • Loading branch information
laveesingh committed Apr 2, 2018
1 parent d8d7668 commit 8362527
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Name | Arguments | Description
------------------|-----------------|-------------------------
`slickPrev` | None | go to previous slide
`slickNext` | None | go to next slide
`slickGoTo` | index:number | go to the given slide index
`slickGoTo` | index, dontAnimate| go to the given slide index
`slickPause` | None | pause the autoplay
`slickPlay` | None | start the autoplay

Expand Down
24 changes: 17 additions & 7 deletions src/inner-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,17 @@ export class InnerSlider extends React.Component {
}
}
}
slideHandler = (index) => {
slideHandler = (index, dontAnimate=false) => {
const {
asNavFor, currentSlide, beforeChange, onLazyLoad, speed, afterChange
} = this.props
let {state, nextState} = slideHandler(
{index, ...this.props, ...this.state, trackRef: this.track})
let {state, nextState} = slideHandler({
index,
...this.props,
...this.state,
trackRef: this.track,
useCSS: !dontAnimate,
})
if (!state) return
beforeChange && beforeChange(currentSlide, state.currentSlide)
let slidesToLoad = state.lazyLoadedList.filter(value =>
Expand All @@ -293,6 +298,7 @@ export class InnerSlider extends React.Component {
this.setState(state, () => {
asNavFor && asNavFor.innerSlider.state.currentSlide !== currentSlide
&& asNavFor.innerSlider.slideHandler(index)
if (!nextState) return
this.animationEndCallback = setTimeout(() => {
const{animating, ...firstBatch} = nextState
this.setState(firstBatch, () => {
Expand All @@ -305,11 +311,15 @@ export class InnerSlider extends React.Component {
})

}
changeSlide = (options) => {
changeSlide = (options, dontAnimate=false) => {
const spec = {...this.props, ...this.state}
let targetSlide = changeSlide(spec, options)
if (targetSlide !== 0 && !targetSlide) return
this.slideHandler(targetSlide)
if (dontAnimate === true) {
this.slideHandler(targetSlide, dontAnimate)
} else {
this.slideHandler(targetSlide)
}
}
clickHandler = e => {
if (this.clickable === false) {
Expand Down Expand Up @@ -382,15 +392,15 @@ export class InnerSlider extends React.Component {
this.callbackTimers.push(
setTimeout(() => this.changeSlide({ message: 'next' }), 0))
}
slickGoTo = (slide) => {
slickGoTo = (slide, dontAnimate=false) => {
slide = Number(slide)
if (isNaN(slide)) return ''
this.callbackTimers.push(
setTimeout( () => this.changeSlide({
message: 'index',
index: slide,
currentSlide: this.state.currentSlide
}), 0)
}, dontAnimate), 0)
)
}
play = ()=> {
Expand Down
2 changes: 1 addition & 1 deletion src/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default class Slider extends React.Component {

slickNext = () => this.innerSlider.slickNext()

slickGoTo = slide => this.innerSlider.slickGoTo(slide)
slickGoTo = (slide, dontAnimate=false) => this.innerSlider.slickGoTo(slide, dontAnimate)

slickPause = () => this.innerSlider.pause('paused')

Expand Down

0 comments on commit 8362527

Please sign in to comment.