File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -315,6 +315,10 @@ export default class Carousel extends Component {
315
315
} ) ;
316
316
}
317
317
318
+ get currentIndex ( ) {
319
+ return this . state . activeItem ;
320
+ }
321
+
318
322
startAutoplay ( instantly = false ) {
319
323
const { autoplayInterval, autoplayDelay } = this . props ;
320
324
@@ -354,7 +358,26 @@ export default class Carousel extends Component {
354
358
this . refs . scrollview . scrollTo ( { x : snapX , y : 0 , animated} ) ;
355
359
this . props . onSnapToItem && fireCallback && this . props . onSnapToItem ( index , this . props . items [ index ] ) ;
356
360
}
361
+ }
357
362
363
+ snapToNext ( animated = true ) {
364
+ const itemsLength = this . _positions . length ;
365
+
366
+ let newIndex = this . currentIndex + 1 ;
367
+ if ( newIndex > itemsLength - 1 ) {
368
+ newIndex = 0 ;
369
+ }
370
+ this . snapToItem ( newIndex , animated ) ;
371
+ }
372
+
373
+ snapToPrev ( animated = true ) {
374
+ const itemsLength = this . _positions . length ;
375
+
376
+ let newIndex = this . currentIndex - 1 ;
377
+ if ( newIndex < 0 ) {
378
+ newIndex = itemsLength - 1 ;
379
+ }
380
+ this . snapToItem ( newIndex , animated ) ;
358
381
}
359
382
360
383
render ( ) {
You can’t perform that action at this time.
0 commit comments