@momo-kits/carousel 0.151.1-test.4 → 0.151.2-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.tsx +16 -9
  2. package/package.json +1 -1
package/index.tsx CHANGED
@@ -398,18 +398,25 @@ class Carousel extends React.PureComponent<CarouselProps, CarouselState> {
398
398
  return 0;
399
399
  }
400
400
 
401
- let minDistance = Infinity;
401
+ if (
402
+ this._positions[lastIndex] &&
403
+ offset >= this._positions[lastIndex].start
404
+ ) {
405
+ return lastIndex;
406
+ }
407
+
402
408
  for (let i = 0; i < this._positions.length; i++) {
403
409
  const { start, end } = this._positions[i];
404
- const itemCenter = (start + end) / 2;
405
- const distance = Math.abs(itemCenter - center);
406
- if (distance < minDistance) {
407
- minDistance = distance;
410
+ if (
411
+ center + activeSlideOffset >= start &&
412
+ center - activeSlideOffset <= end
413
+ ) {
408
414
  itemIndex = i;
415
+ break;
409
416
  }
410
417
  }
411
418
 
412
- return itemIndex !== undefined ? itemIndex : 0;
419
+ return itemIndex || 0;
413
420
  }
414
421
 
415
422
  _initPositionsAndInterpolators(props = this.props) {
@@ -508,10 +515,10 @@ class Carousel extends React.PureComponent<CarouselProps, CarouselState> {
508
515
 
509
516
  if (nextActiveItem !== this._onScrollActiveItem) {
510
517
  this._onScrollActiveItem = nextActiveItem;
511
- const dataIndex = this._getDataIndex(nextActiveItem);
518
+ onScrollIndexChanged &&
519
+ onScrollIndexChanged(this._getDataIndex(nextActiveItem));
512
520
 
513
- onScrollIndexChanged && onScrollIndexChanged(dataIndex);
514
- onSnapToItem && onSnapToItem(dataIndex);
521
+ onSnapToItem && onSnapToItem(this._getDataIndex(nextActiveItem));
515
522
  }
516
523
 
517
524
  if (
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/carousel",
3
- "version": "0.151.1-test.4",
3
+ "version": "0.151.2-beta.2",
4
4
  "private": false,
5
5
  "main": "index.tsx",
6
6
  "peerDependencies": {