@momo-kits/carousel 0.150.2-beta.4 → 0.150.2-beta.40
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.
- package/index.tsx +9 -16
- package/package.json +20 -20
package/index.tsx
CHANGED
|
@@ -398,25 +398,18 @@ class Carousel extends React.PureComponent<CarouselProps, CarouselState> {
|
|
|
398
398
|
return 0;
|
|
399
399
|
}
|
|
400
400
|
|
|
401
|
-
|
|
402
|
-
this._positions[lastIndex] &&
|
|
403
|
-
offset >= this._positions[lastIndex].start
|
|
404
|
-
) {
|
|
405
|
-
return lastIndex;
|
|
406
|
-
}
|
|
407
|
-
|
|
401
|
+
let minDistance = Infinity;
|
|
408
402
|
for (let i = 0; i < this._positions.length; i++) {
|
|
409
403
|
const { start, end } = this._positions[i];
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
404
|
+
const itemCenter = (start + end) / 2;
|
|
405
|
+
const distance = Math.abs(itemCenter - center);
|
|
406
|
+
if (distance < minDistance) {
|
|
407
|
+
minDistance = distance;
|
|
414
408
|
itemIndex = i;
|
|
415
|
-
break;
|
|
416
409
|
}
|
|
417
410
|
}
|
|
418
411
|
|
|
419
|
-
return itemIndex
|
|
412
|
+
return itemIndex !== undefined ? itemIndex : 0;
|
|
420
413
|
}
|
|
421
414
|
|
|
422
415
|
_initPositionsAndInterpolators(props = this.props) {
|
|
@@ -515,10 +508,10 @@ class Carousel extends React.PureComponent<CarouselProps, CarouselState> {
|
|
|
515
508
|
|
|
516
509
|
if (nextActiveItem !== this._onScrollActiveItem) {
|
|
517
510
|
this._onScrollActiveItem = nextActiveItem;
|
|
518
|
-
|
|
519
|
-
onScrollIndexChanged(this._getDataIndex(nextActiveItem));
|
|
511
|
+
const dataIndex = this._getDataIndex(nextActiveItem);
|
|
520
512
|
|
|
521
|
-
|
|
513
|
+
onScrollIndexChanged && onScrollIndexChanged(dataIndex);
|
|
514
|
+
onSnapToItem && onSnapToItem(dataIndex);
|
|
522
515
|
}
|
|
523
516
|
|
|
524
517
|
if (
|
package/package.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
2
|
+
"name": "@momo-kits/carousel",
|
|
3
|
+
"version": "0.150.2-beta.40",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "index.tsx",
|
|
6
|
+
"peerDependencies": {
|
|
7
|
+
"@momo-kits/foundation": "latest",
|
|
8
|
+
"react": "*",
|
|
9
|
+
"react-native": "*"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@momo-platform/versions": "4.1.11"
|
|
13
|
+
},
|
|
14
|
+
"license": "MoMo",
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"registry": "https://registry.npmjs.org/"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"moment": "^2.24.0"
|
|
20
|
+
}
|
|
21
|
+
}
|