@momo-kits/carousel 0.0.1-beta → 0.0.1
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/Carousel.js +17 -6
- package/package.json +15 -16
- package/publish.sh +1 -1
- package/utils/animation.js +5 -3
package/Carousel.js
CHANGED
|
@@ -78,6 +78,7 @@ export default class Carousel extends PureComponent {
|
|
|
78
78
|
// This bool aims at fixing an iOS bug due to scrollTo that triggers onMomentumScrollEnd.
|
|
79
79
|
// onMomentumScrollEnd fires this._snapScroll, thus creating an infinite loop.
|
|
80
80
|
this._ignoreNextMomentum = false;
|
|
81
|
+
this._animated = false;
|
|
81
82
|
|
|
82
83
|
// Warnings
|
|
83
84
|
if (!ViewPropTypes) {
|
|
@@ -424,6 +425,12 @@ export default class Carousel extends PureComponent {
|
|
|
424
425
|
}
|
|
425
426
|
|
|
426
427
|
_getWrappedRef() {
|
|
428
|
+
if (this._carouselRef && (
|
|
429
|
+
(this._needsScrollView() && this._carouselRef.scrollTo)
|
|
430
|
+
|| (!this._needsScrollView() && this._carouselRef.scrollToOffset)
|
|
431
|
+
)) {
|
|
432
|
+
return this._carouselRef;
|
|
433
|
+
}
|
|
427
434
|
// https://github.com/facebook/react-native/issues/10635
|
|
428
435
|
// https://stackoverflow.com/a/48786374/8412141
|
|
429
436
|
return this._carouselRef && this._carouselRef.getNode && this._carouselRef.getNode();
|
|
@@ -547,7 +554,7 @@ export default class Carousel extends PureComponent {
|
|
|
547
554
|
interpolator = tinderScrollInterpolator(_index, props);
|
|
548
555
|
}
|
|
549
556
|
|
|
550
|
-
if (!interpolator || !interpolator
|
|
557
|
+
if (!interpolator || !interpolator?.inputRange || !interpolator?.outputRange) {
|
|
551
558
|
interpolator = defaultScrollInterpolator(_index, props);
|
|
552
559
|
}
|
|
553
560
|
|
|
@@ -697,11 +704,15 @@ export default class Carousel extends PureComponent {
|
|
|
697
704
|
animated
|
|
698
705
|
};
|
|
699
706
|
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
707
|
+
setTimeout(() => {
|
|
708
|
+
if (this._needsScrollView()) {
|
|
709
|
+
wrappedRef.scrollTo(options);
|
|
710
|
+
} else {
|
|
711
|
+
wrappedRef.scrollToOffset(options);
|
|
712
|
+
}
|
|
713
|
+
}, (!animated && this._animated) ? 200 : 0);
|
|
714
|
+
|
|
715
|
+
this._animated = animated;
|
|
705
716
|
}
|
|
706
717
|
|
|
707
718
|
_onScroll(event) {
|
package/package.json
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
"name": "@momo-kits/carousel",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"prop-types": "^15.7.2",
|
|
8
|
+
"react": "16.9.0"
|
|
9
|
+
},
|
|
10
|
+
"peerDependencies": {
|
|
11
|
+
"react": "16.9.0",
|
|
12
|
+
"react-native": ">=0.55"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {},
|
|
15
|
+
"license": "MoMo"
|
|
16
|
+
}
|
package/publish.sh
CHANGED
|
@@ -12,7 +12,7 @@ echo VERSION: $VERSION
|
|
|
12
12
|
rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type.js' --exclude 'prop-types.js' ./* dist
|
|
13
13
|
|
|
14
14
|
# #babel component to dist
|
|
15
|
-
babel ./dist -d dist --copy-files
|
|
15
|
+
#babel ./dist -d dist --copy-files
|
|
16
16
|
|
|
17
17
|
#copy option
|
|
18
18
|
#cp -r ./src/ dist
|
package/utils/animation.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */
|
|
2
|
-
import { Platform } from 'react-native';
|
|
2
|
+
import { Platform, Dimensions } from 'react-native';
|
|
3
3
|
|
|
4
4
|
const IS_ANDROID = Platform.OS === 'android';
|
|
5
|
+
const { width: viewportWidth = 0, height: viewportHeight = 0 } = Dimensions.get('window') || {};
|
|
5
6
|
|
|
6
7
|
// Get scroll interpolator's input range from an array of slide indexes
|
|
7
8
|
// Indexes are relative to the current active slide (index 0)
|
|
@@ -14,9 +15,10 @@ const IS_ANDROID = Platform.OS === 'android';
|
|
|
14
15
|
// (index + 1) * sizeRef // active - 1
|
|
15
16
|
// ]
|
|
16
17
|
export function getInputRangeFromIndexes(range, index, carouselProps) {
|
|
17
|
-
const sizeRef = carouselProps.vertical ? carouselProps.itemHeight : carouselProps.
|
|
18
|
+
const sizeRef = carouselProps.vertical ? carouselProps.itemHeight <= 0 ? (viewportHeight || 680) : carouselProps.itemHeight:
|
|
19
|
+
carouselProps.itemWidth <= 0 ? (viewportWidth || 375) : carouselProps.itemWidth;
|
|
18
20
|
const inputRange = [];
|
|
19
|
-
|
|
21
|
+
|
|
20
22
|
for (let i = 0; i < range.length; i += 1) {
|
|
21
23
|
inputRange.push((index - range[i]) * sizeRef);
|
|
22
24
|
}
|