Skip to content

Commit 3bbbaad

Browse files
committed
Add onTransitionEnd callback. Resolve #111
1 parent f6d06ef commit 3bbbaad

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ All attributes are optional.
2727
- `auto` {Boolean} `true` or `false` (`false` by default) toggle auto sliding.
2828
- `interval` {Number} (`4000`ms by default) interval for auto sliding.
2929
- `duration` {Number} (`300`ms by default) duration for animation.
30+
- `onTransitionEnd` {Function({ prev: HTMLElement, current: HTMLElement, next: HTMLElement})} on frames transition end callback.
3031
- `widgets` {Array of ReactClass} Indicator and switcher could be various,
3132
so it's not builtin. Here's some example custom widgets
3233
([dots indicator](src/indicator-dots.js),

src/carousel.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,16 @@ class Carousel extends React.Component {
247247
}, cb)
248248
}
249249

250-
prepareSiblingFrames () {
251-
const siblings = {
250+
getSiblingFrames () {
251+
return {
252252
current: this.refs['f' + this.getFrameId()],
253253
prev: this.refs['f' + this.getFrameId('prev')],
254254
next: this.refs['f' + this.getFrameId('next')]
255255
}
256+
}
257+
258+
prepareSiblingFrames () {
259+
const siblings = this.getSiblingFrames()
256260

257261
if (!this.props.loop) {
258262
this.state.current === 0 && (siblings.prev = undefined)
@@ -289,7 +293,7 @@ class Carousel extends React.Component {
289293

290294
transitFramesTowards (direction) {
291295
const { prev, current, next } = this.state.movingFrames
292-
const { duration, axis } = this.props
296+
const { duration, axis, onTransitionEnd } = this.props
293297

294298
let newCurrentId = this.state.current
295299
switch (direction) {
@@ -324,6 +328,8 @@ class Carousel extends React.Component {
324328
}
325329
}
326330

331+
onTransitionEnd && setTimeout(() => onTransitionEnd(this.getSiblingFrames()), duration)
332+
327333
this.setState({ current: newCurrentId })
328334
}
329335

@@ -382,7 +388,8 @@ Carousel.propTypes = {
382388
widgets: PropTypes.arrayOf(PropTypes.func),
383389
frames: PropTypes.arrayOf(PropTypes.element),
384390
style: PropTypes.object,
385-
minMove: PropTypes.number
391+
minMove: PropTypes.number,
392+
onTransitionEnd: PropTypes.func
386393
}
387394

388395
Carousel.defaultProps = {

0 commit comments

Comments
 (0)