@wlloyalty/wll-react-sdk 1.0.101 → 1.0.102

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/dist/index.d.ts CHANGED
@@ -526,8 +526,9 @@ type TSection = {
526
526
 
527
527
  type CarouselProps = {
528
528
  section?: TSection;
529
+ autoRotateInterval?: number;
529
530
  };
530
- declare const Carousel: ({ section }: CarouselProps) => JSX.Element | null;
531
+ declare const Carousel: ({ section, autoRotateInterval, }: CarouselProps) => JSX.Element | null;
531
532
 
532
533
  type CarouselNavButtonProps = {
533
534
  direction: 'left' | 'right';
package/dist/native.js CHANGED
@@ -3670,7 +3670,7 @@ var carouselReducer = function (state, action) {
3670
3670
  }
3671
3671
  };
3672
3672
  var Carousel = function (_a) {
3673
- var section = _a.section;
3673
+ var section = _a.section, _b = _a.autoRotateInterval, autoRotateInterval = _b === void 0 ? 5000 : _b;
3674
3674
  if (!section)
3675
3675
  return null;
3676
3676
  var WINDOW_WIDTH = reactNative.useWindowDimensions().width;
@@ -3678,9 +3678,9 @@ var Carousel = function (_a) {
3678
3678
  var styles = useCarouselStyles(BUTTON_SIZE);
3679
3679
  var animatedIndex = React.useRef(new reactNative.Animated.Value(0)).current;
3680
3680
  var theme = useWllSdk().theme;
3681
- var _b = useResponsive(), isDesktop = _b.isDesktop, isTablet = _b.isTablet;
3681
+ var _c = useResponsive(), isDesktop = _c.isDesktop, isTablet = _c.isTablet;
3682
3682
  var scrollViewRef = React.useRef(null);
3683
- var _c = React.useReducer(carouselReducer, __assign(__assign({}, initialState), { containerWidth: WINDOW_WIDTH })), state = _c[0], dispatch = _c[1];
3683
+ var _d = React.useReducer(carouselReducer, __assign(__assign({}, initialState), { containerWidth: WINDOW_WIDTH })), state = _d[0], dispatch = _d[1];
3684
3684
  var currentIndex = state.currentIndex, containerWidth = state.containerWidth;
3685
3685
  var sortedTiles = sortByPriority(section.tiles.filter(function (tile) { return tile.type === exports.TileType.Banner; }));
3686
3686
  var handleScroll = React.useCallback(function (event) {
@@ -3703,12 +3703,34 @@ var Carousel = function (_a) {
3703
3703
  };
3704
3704
  var handleNext = function () {
3705
3705
  var _a;
3706
+ var nextIndex = Math.min(sortedTiles.length - 1, currentIndex + 1);
3706
3707
  dispatch({ type: 'NEXT_SLIDE', maxIndex: sortedTiles.length - 1 });
3707
3708
  (_a = scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({
3708
- x: (currentIndex + 1) * containerWidth,
3709
+ x: nextIndex * containerWidth,
3709
3710
  animated: true,
3710
3711
  });
3711
3712
  };
3713
+ var rotateToNextSlide = React.useCallback(function () {
3714
+ var _a;
3715
+ if (currentIndex >= sortedTiles.length - 1) {
3716
+ dispatch({ type: 'SET_CURRENT_INDEX', payload: 0 });
3717
+ (_a = scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({
3718
+ x: 0,
3719
+ animated: true,
3720
+ });
3721
+ }
3722
+ else {
3723
+ handleNext();
3724
+ }
3725
+ }, [currentIndex, containerWidth, sortedTiles.length]);
3726
+ React.useEffect(function () {
3727
+ if (sortedTiles.length <= 1)
3728
+ return;
3729
+ var rotationTimer = setInterval(function () {
3730
+ rotateToNextSlide();
3731
+ }, autoRotateInterval);
3732
+ return function () { return clearInterval(rotationTimer); };
3733
+ }, [rotateToNextSlide, autoRotateInterval, sortedTiles.length]);
3712
3734
  var displayControls = sortedTiles.length > 1;
3713
3735
  var showPrevButton = displayControls && currentIndex > 0;
3714
3736
  var showNextButton = displayControls && currentIndex < sortedTiles.length - 1;