@momo-kits/carousel 0.80.4-beta.2 → 0.80.8-beta.6
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/animation.ts +5 -4
- package/index.tsx +15 -19
- package/package.json +2 -2
package/animation.ts
CHANGED
|
@@ -31,23 +31,24 @@ export function defaultAnimatedStyles(
|
|
|
31
31
|
) {
|
|
32
32
|
let animatedOpacity = {};
|
|
33
33
|
let animatedScale = {};
|
|
34
|
+
const {inactiveSlideOpacity = 1, inactiveSlideScale = 1} = carouselProps;
|
|
34
35
|
|
|
35
|
-
if (
|
|
36
|
+
if (inactiveSlideOpacity < 1) {
|
|
36
37
|
animatedOpacity = {
|
|
37
38
|
opacity: animatedValue.interpolate({
|
|
38
39
|
inputRange: [0, 1],
|
|
39
|
-
outputRange: [
|
|
40
|
+
outputRange: [inactiveSlideOpacity, 1],
|
|
40
41
|
}),
|
|
41
42
|
};
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
if (
|
|
45
|
+
if (inactiveSlideScale < 1) {
|
|
45
46
|
animatedScale = {
|
|
46
47
|
transform: [
|
|
47
48
|
{
|
|
48
49
|
scaleY: animatedValue.interpolate({
|
|
49
50
|
inputRange: [0, 1],
|
|
50
|
-
outputRange: [
|
|
51
|
+
outputRange: [inactiveSlideScale, 1],
|
|
51
52
|
}),
|
|
52
53
|
},
|
|
53
54
|
],
|
package/index.tsx
CHANGED
|
@@ -77,7 +77,7 @@ export default class Carousel extends React.PureComponent<
|
|
|
77
77
|
itemWidth: screenWidth - Spacing.L * 2,
|
|
78
78
|
};
|
|
79
79
|
|
|
80
|
-
const initialActiveItem = this._getFirstItem(props.firstItem);
|
|
80
|
+
const initialActiveItem = this._getFirstItem(props.firstItem || 0);
|
|
81
81
|
this._activeItem = initialActiveItem;
|
|
82
82
|
this._onScrollActiveItem = initialActiveItem;
|
|
83
83
|
this._previousFirstItem = initialActiveItem;
|
|
@@ -132,7 +132,7 @@ export default class Carousel extends React.PureComponent<
|
|
|
132
132
|
|
|
133
133
|
componentDidUpdate(prevProps: CarouselProps) {
|
|
134
134
|
const {interpolators} = this.state;
|
|
135
|
-
const {firstItem, scrollEnabled} = this.props;
|
|
135
|
+
const {firstItem = 0, scrollEnabled} = this.props;
|
|
136
136
|
const itemsLength = this._getCustomDataLength(this.props);
|
|
137
137
|
|
|
138
138
|
if (!itemsLength) {
|
|
@@ -211,12 +211,12 @@ export default class Carousel extends React.PureComponent<
|
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
_shouldAnimateSlides(props = this.props) {
|
|
214
|
-
const {inactiveSlideOpacity, inactiveSlideScale} = props;
|
|
214
|
+
const {inactiveSlideOpacity = 1, inactiveSlideScale = 1} = props;
|
|
215
215
|
return inactiveSlideOpacity < 1 || inactiveSlideScale < 1;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
_shouldRepositionScroll(index: number) {
|
|
219
|
-
const {data, enableSnap, loopClonesPerSide} = this.props;
|
|
219
|
+
const {data, enableSnap, loopClonesPerSide = 3} = this.props;
|
|
220
220
|
const dataLength = data && data.length;
|
|
221
221
|
return !(
|
|
222
222
|
!enableSnap ||
|
|
@@ -231,7 +231,7 @@ export default class Carousel extends React.PureComponent<
|
|
|
231
231
|
}
|
|
232
232
|
|
|
233
233
|
_getCustomData(props = this.props) {
|
|
234
|
-
const {data, loopClonesPerSide} = props;
|
|
234
|
+
const {data, loopClonesPerSide = 3} = props;
|
|
235
235
|
const dataLength = data && data.length;
|
|
236
236
|
|
|
237
237
|
if (!dataLength) {
|
|
@@ -265,7 +265,7 @@ export default class Carousel extends React.PureComponent<
|
|
|
265
265
|
}
|
|
266
266
|
|
|
267
267
|
_getCustomDataLength(props = this.props) {
|
|
268
|
-
const {data, loopClonesPerSide} = props;
|
|
268
|
+
const {data, loopClonesPerSide = 3} = props;
|
|
269
269
|
const dataLength = data && data.length;
|
|
270
270
|
|
|
271
271
|
if (!dataLength) {
|
|
@@ -286,7 +286,7 @@ export default class Carousel extends React.PureComponent<
|
|
|
286
286
|
}
|
|
287
287
|
|
|
288
288
|
_getDataIndex(index: number) {
|
|
289
|
-
const {data, loopClonesPerSide} = this.props;
|
|
289
|
+
const {data, loopClonesPerSide = 3} = this.props;
|
|
290
290
|
const dataLength = data && data.length;
|
|
291
291
|
if (!this._enableLoop() || !dataLength) {
|
|
292
292
|
return index;
|
|
@@ -322,7 +322,7 @@ export default class Carousel extends React.PureComponent<
|
|
|
322
322
|
}
|
|
323
323
|
|
|
324
324
|
_getFirstItem(index: number, props = this.props) {
|
|
325
|
-
const {loopClonesPerSide} = props;
|
|
325
|
+
const {loopClonesPerSide = 3} = props;
|
|
326
326
|
const itemsLength = this._getCustomDataLength(props);
|
|
327
327
|
|
|
328
328
|
if (!itemsLength || index > itemsLength - 1 || index < 0) {
|
|
@@ -373,7 +373,7 @@ export default class Carousel extends React.PureComponent<
|
|
|
373
373
|
}
|
|
374
374
|
|
|
375
375
|
_getActiveSlideOffset() {
|
|
376
|
-
const {activeSlideOffset} = this.props;
|
|
376
|
+
const {activeSlideOffset = 0} = this.props;
|
|
377
377
|
const itemMainDimension = this._getItemMainDimension();
|
|
378
378
|
const minOffset = 10;
|
|
379
379
|
return itemMainDimension / 2 - activeSlideOffset >= minOffset
|
|
@@ -413,10 +413,6 @@ export default class Carousel extends React.PureComponent<
|
|
|
413
413
|
return itemIndex || 0;
|
|
414
414
|
}
|
|
415
415
|
|
|
416
|
-
_getSlideInterpolatedStyle(index: number, animatedValue: Animated.Value) {
|
|
417
|
-
return defaultAnimatedStyles(animatedValue, this.props);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
416
|
_initPositionsAndInterpolators(props = this.props) {
|
|
421
417
|
const {data} = props;
|
|
422
418
|
const itemMainDimension = this._getItemMainDimension();
|
|
@@ -458,7 +454,7 @@ export default class Carousel extends React.PureComponent<
|
|
|
458
454
|
}
|
|
459
455
|
|
|
460
456
|
_repositionScroll(index: number, animated = false) {
|
|
461
|
-
const {data, loopClonesPerSide} = this.props;
|
|
457
|
+
const {data, loopClonesPerSide = 3} = this.props;
|
|
462
458
|
const dataLength = data && data.length;
|
|
463
459
|
|
|
464
460
|
if (typeof index === 'undefined' || !this._shouldRepositionScroll(index)) {
|
|
@@ -564,7 +560,7 @@ export default class Carousel extends React.PureComponent<
|
|
|
564
560
|
}
|
|
565
561
|
|
|
566
562
|
_onLayout(event: LayoutChangeEvent) {
|
|
567
|
-
const {onLayout, visibleItem} = this.props;
|
|
563
|
+
const {onLayout, visibleItem = 1} = this.props;
|
|
568
564
|
|
|
569
565
|
if (this._onLayoutInitDone) {
|
|
570
566
|
this._initPositionsAndInterpolators();
|
|
@@ -587,7 +583,7 @@ export default class Carousel extends React.PureComponent<
|
|
|
587
583
|
}
|
|
588
584
|
|
|
589
585
|
_getPositionIndex(index: number) {
|
|
590
|
-
const {loop, loopClonesPerSide} = this.props;
|
|
586
|
+
const {loop, loopClonesPerSide = 3} = this.props;
|
|
591
587
|
return loop ? index + loopClonesPerSide : index;
|
|
592
588
|
}
|
|
593
589
|
|
|
@@ -750,9 +746,9 @@ export default class Carousel extends React.PureComponent<
|
|
|
750
746
|
|
|
751
747
|
render() {
|
|
752
748
|
const {
|
|
753
|
-
loopClonesPerSide,
|
|
754
|
-
visibleItem,
|
|
755
|
-
firstItem,
|
|
749
|
+
loopClonesPerSide = 3,
|
|
750
|
+
visibleItem = 1,
|
|
751
|
+
firstItem = 0,
|
|
756
752
|
getItemLayout,
|
|
757
753
|
keyExtractor,
|
|
758
754
|
style,
|
package/package.json
CHANGED