@momo-kits/carousel 0.80.8-beta.9 → 0.81.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 (3) hide show
  1. package/index.tsx +28 -20
  2. package/package.json +1 -1
  3. package/types.ts +1 -0
package/index.tsx CHANGED
@@ -8,8 +8,9 @@ import {
8
8
  NativeSyntheticEvent,
9
9
  Platform,
10
10
  View,
11
+ ViewStyle,
11
12
  } from 'react-native';
12
- import {defaultAnimatedStyles, defaultScrollInterpolator} from './animation';
13
+ import {defaultScrollInterpolator} from './animation';
13
14
  import {CarouselProps, CarouselRef, CarouselState, Position} from './types';
14
15
  import {scaleSize, Spacing} from '@momo-kits/foundation';
15
16
 
@@ -44,6 +45,7 @@ export default class Carousel extends React.PureComponent<
44
45
  disableIntervalMomentum: IS_ANDROID,
45
46
  useExperimentalSnap: IS_ANDROID,
46
47
  visibleItem: 1,
48
+ full: false,
47
49
  };
48
50
 
49
51
  _activeItem;
@@ -346,7 +348,8 @@ export default class Carousel extends React.PureComponent<
346
348
 
347
349
  _getItemMainDimension() {
348
350
  const {itemWidth} = this.state;
349
- return itemWidth + Spacing.S;
351
+ const {full} = this.props;
352
+ return full ? itemWidth : itemWidth + Spacing.S;
350
353
  }
351
354
 
352
355
  _getItemScrollOffset(index: number) {
@@ -569,15 +572,20 @@ export default class Carousel extends React.PureComponent<
569
572
  this._onLayoutInitDone = true;
570
573
  }
571
574
  const containerWidth = event.nativeEvent.layout.width;
572
- const itemWidth =
573
- this.props.itemWidth ||
574
- (this.props.visibleItem === 1
575
+ let itemWidth =
576
+ this.props.visibleItem === 1
575
577
  ? screenWidth - Spacing.M * 2
576
578
  : Math.ceil(
577
579
  scaleSize(
578
580
  (containerWidth * 0.9 - visibleItem * Spacing.S) / visibleItem,
579
581
  ),
580
- ));
582
+ );
583
+ if (this.props.itemWidth) {
584
+ itemWidth = this.props.itemWidth;
585
+ }
586
+ if (this.props.full) {
587
+ itemWidth = containerWidth;
588
+ }
581
589
 
582
590
  this.setState({containerWidth, itemWidth});
583
591
 
@@ -640,7 +648,7 @@ export default class Carousel extends React.PureComponent<
640
648
  _renderItem(info: {item: any; index: number}) {
641
649
  const {item, index} = info;
642
650
  const {interpolators, itemWidth} = this.state;
643
- const {slideStyle} = this.props;
651
+ const {slideStyle, full} = this.props;
644
652
  const animatedValue = interpolators && interpolators[index];
645
653
 
646
654
  if (typeof animatedValue === 'undefined') {
@@ -649,12 +657,20 @@ export default class Carousel extends React.PureComponent<
649
657
 
650
658
  const animate = this._shouldAnimateSlides();
651
659
  const Component = animate ? Animated.View : View;
652
- // const animatedStyle = animate
653
- // ? this._getSlideInterpolatedStyle(index, animatedValue)
654
- // : {};
655
-
656
660
  const mainDimension = {width: itemWidth};
657
661
 
662
+ let spacingStyle: ViewStyle = this.props.loop
663
+ ? {marginLeft: Spacing.S}
664
+ : {
665
+ marginLeft: index === 0 ? Spacing.M : 0,
666
+ marginRight:
667
+ index === this._getCustomDataLength() - 1 ? Spacing.M : Spacing.S,
668
+ };
669
+
670
+ if (full) {
671
+ spacingStyle = {};
672
+ }
673
+
658
674
  return (
659
675
  <Component
660
676
  style={[
@@ -662,15 +678,7 @@ export default class Carousel extends React.PureComponent<
662
678
  slideStyle,
663
679
  // animatedStyle,
664
680
  {overflow: 'hidden'},
665
- this.props.loop
666
- ? {marginLeft: Spacing.S}
667
- : {
668
- marginLeft: index === 0 ? Spacing.M : 0,
669
- marginRight:
670
- index === this._getCustomDataLength() - 1
671
- ? Spacing.M
672
- : Spacing.S,
673
- },
681
+ spacingStyle,
674
682
  ]}
675
683
  pointerEvents="box-none">
676
684
  {this.props.renderItem({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/carousel",
3
- "version": "0.80.8-beta.9",
3
+ "version": "0.81.2",
4
4
  "private": false,
5
5
  "main": "index.tsx",
6
6
  "peerDependencies": {
package/types.ts CHANGED
@@ -34,6 +34,7 @@ export type CarouselProps = {
34
34
  ) => {length: number; offset: number; index: number};
35
35
  style?: ViewStyle;
36
36
  visibleItem?: number;
37
+ full?: boolean;
37
38
  };
38
39
 
39
40
  export type CarouselRef = {