@wlloyalty/wll-react-sdk 1.0.30 → 1.0.31

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.js CHANGED
@@ -18870,7 +18870,6 @@ MemoedPressable.displayName = 'Pressable';
18870
18870
  var Pressable$1 = MemoedPressable;
18871
18871
 
18872
18872
  var MAX_WIDTH = 1080;
18873
- var SLIDE_WIDTH = MAX_WIDTH;
18874
18873
  var BUTTON_SIZE = 42;
18875
18874
 
18876
18875
  var useHandleTilePress = function (ctaLink, ctaLinkTarget) {
@@ -19559,7 +19558,7 @@ var useBannerTileStyles = function () {
19559
19558
  position: 'relative',
19560
19559
  overflow: 'hidden',
19561
19560
  marginRight: useResponsiveValue(theme.sizes.xxl, theme.sizes.xxs, isDesktop, isTablet),
19562
- height: 320
19561
+ maxHeight: 320
19563
19562
  },
19564
19563
  media: {
19565
19564
  position: 'absolute',
@@ -19728,6 +19727,39 @@ exports.SectionType = void 0;
19728
19727
  SectionType["Banner"] = "BANNER";
19729
19728
  })(exports.SectionType || (exports.SectionType = {}));
19730
19729
 
19730
+ /**
19731
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
19732
+ *
19733
+ * This source code is licensed under the MIT license found in the
19734
+ * LICENSE file in the root directory of this source tree.
19735
+ *
19736
+ * @format
19737
+ *
19738
+ */
19739
+
19740
+ function useWindowDimensions() {
19741
+ var _useState = React$1.useState(() => Dimensions.get('window')),
19742
+ dims = _useState[0],
19743
+ setDims = _useState[1];
19744
+ React$1.useEffect(() => {
19745
+ function handleChange(_ref) {
19746
+ var window = _ref.window;
19747
+ if (window != null) {
19748
+ setDims(window);
19749
+ }
19750
+ }
19751
+ Dimensions.addEventListener('change', handleChange);
19752
+ // We might have missed an update between calling `get` in render and
19753
+ // `addEventListener` in this handler, so we set it here. If there was
19754
+ // no change, React will filter out this update as a no-op.
19755
+ setDims(Dimensions.get('window'));
19756
+ return () => {
19757
+ Dimensions.removeEventListener('change', handleChange);
19758
+ };
19759
+ }, []);
19760
+ return dims;
19761
+ }
19762
+
19731
19763
  var useSectionHeaderStyles = function () {
19732
19764
  var _a = useResponsive$1(),
19733
19765
  isDesktop = _a.isDesktop,
@@ -19772,7 +19804,7 @@ var SectionHeader = function (_a) {
19772
19804
  }, description));
19773
19805
  };
19774
19806
 
19775
- var useCarouselStyles = function (buttonSize, slideWidth) {
19807
+ var useCarouselStyles = function (buttonSize) {
19776
19808
  if (buttonSize === void 0) {
19777
19809
  buttonSize = 42;
19778
19810
  }
@@ -19782,8 +19814,8 @@ var useCarouselStyles = function (buttonSize, slideWidth) {
19782
19814
  var theme = useWllSdk().theme;
19783
19815
  return StyleSheet$1.create({
19784
19816
  container: {
19785
- flex: 1,
19786
- maxWidth: MAX_WIDTH
19817
+ width: '100%',
19818
+ flex: 1
19787
19819
  },
19788
19820
  sectionTitle: {
19789
19821
  fontSize: 31,
@@ -19799,13 +19831,18 @@ var useCarouselStyles = function (buttonSize, slideWidth) {
19799
19831
  marginBottom: 20
19800
19832
  },
19801
19833
  carouselContainer: {
19834
+ width: '100%',
19802
19835
  flexDirection: 'row',
19803
19836
  alignItems: 'center',
19804
- justifyContent: 'center'
19837
+ justifyContent: 'center',
19838
+ position: 'relative'
19805
19839
  },
19806
19840
  carouselContent: {
19807
- overflow: 'hidden',
19808
- width: slideWidth
19841
+ width: '100%',
19842
+ overflow: 'hidden'
19843
+ },
19844
+ slideContainer: {
19845
+ width: '100%'
19809
19846
  },
19810
19847
  navButton: {
19811
19848
  position: 'absolute',
@@ -19828,9 +19865,6 @@ var useCarouselStyles = function (buttonSize, slideWidth) {
19828
19865
  right: -buttonSize / 2,
19829
19866
  backgroundColor: theme.surface
19830
19867
  },
19831
- slideContainer: {
19832
- width: slideWidth
19833
- },
19834
19868
  indicators: {
19835
19869
  flexDirection: 'row',
19836
19870
  justifyContent: 'center',
@@ -19851,36 +19885,41 @@ var useCarouselStyles = function (buttonSize, slideWidth) {
19851
19885
 
19852
19886
  var Carousel = function (_a) {
19853
19887
  var section = _a.section;
19854
- var styles = useCarouselStyles(BUTTON_SIZE, SLIDE_WIDTH);
19888
+ var windowWidth = useWindowDimensions().width;
19889
+ var containerRef = React$1.useRef(null);
19890
+ var _b = React$1.useState(windowWidth),
19891
+ containerWidth = _b[0],
19892
+ setContainerWidth = _b[1];
19893
+ var styles = useCarouselStyles(BUTTON_SIZE);
19855
19894
  var animatedIndex = React$1.useRef(new Animated$1.Value(0)).current;
19856
19895
  var theme = useWllSdk().theme;
19857
- var _b = useResponsive(),
19858
- isDesktop = _b.isDesktop,
19859
- isTablet = _b.isTablet;
19896
+ var _c = useResponsive(),
19897
+ isDesktop = _c.isDesktop,
19898
+ isTablet = _c.isTablet;
19860
19899
  var scrollViewRef = React$1.useRef(null);
19861
- var _c = React$1.useState(0),
19862
- currentIndex = _c[0],
19863
- setCurrentIndex = _c[1];
19900
+ var _d = React$1.useState(0),
19901
+ currentIndex = _d[0],
19902
+ setCurrentIndex = _d[1];
19864
19903
  var bannerTiles = section.tiles.filter(function (tile) {
19865
19904
  return tile.type === exports.TileType.Banner;
19866
19905
  });
19867
19906
  var sortedTiles = sortByPriority(bannerTiles);
19868
19907
  var handleScroll = React$1.useCallback(function (event) {
19869
19908
  var contentOffsetX = event.nativeEvent.contentOffset.x;
19870
- var newIndex = contentOffsetX / SLIDE_WIDTH;
19909
+ var newIndex = contentOffsetX / containerWidth;
19871
19910
  animatedIndex.setValue(newIndex);
19872
- }, [SLIDE_WIDTH, animatedIndex]);
19911
+ }, [containerWidth, animatedIndex]);
19873
19912
  var handleScrollEnd = React$1.useCallback(function (event) {
19874
19913
  var contentOffsetX = event.nativeEvent.contentOffset.x;
19875
- var newIndex = Math.round(contentOffsetX / SLIDE_WIDTH);
19914
+ var newIndex = Math.round(contentOffsetX / containerWidth);
19876
19915
  setCurrentIndex(newIndex);
19877
- }, [SLIDE_WIDTH]);
19916
+ }, [containerWidth]);
19878
19917
  var handlePrev = function () {
19879
19918
  var _a;
19880
19919
  var newIndex = Math.max(0, currentIndex - 1);
19881
19920
  setCurrentIndex(newIndex);
19882
19921
  (_a = scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({
19883
- x: newIndex * SLIDE_WIDTH,
19922
+ x: newIndex * containerWidth,
19884
19923
  animated: true
19885
19924
  });
19886
19925
  };
@@ -19889,7 +19928,7 @@ var Carousel = function (_a) {
19889
19928
  var newIndex = Math.min(sortedTiles.length - 1, currentIndex + 1);
19890
19929
  setCurrentIndex(newIndex);
19891
19930
  (_a = scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({
19892
- x: newIndex * SLIDE_WIDTH,
19931
+ x: newIndex * containerWidth,
19893
19932
  animated: true
19894
19933
  });
19895
19934
  };
@@ -19905,7 +19944,12 @@ var Carousel = function (_a) {
19905
19944
  title: section.title,
19906
19945
  description: section.description
19907
19946
  }), /*#__PURE__*/React$1.createElement(View$2, {
19908
- style: styles.container
19947
+ ref: containerRef,
19948
+ style: styles.container,
19949
+ onLayout: function (event) {
19950
+ var width = event.nativeEvent.layout.width;
19951
+ setContainerWidth(width);
19952
+ }
19909
19953
  }, /*#__PURE__*/React$1.createElement(View$2, {
19910
19954
  style: styles.carouselContainer
19911
19955
  }, displayControls && /*#__PURE__*/React$1.createElement(TouchableOpacity$1, {
@@ -19925,20 +19969,18 @@ var Carousel = function (_a) {
19925
19969
  onScroll: handleScroll,
19926
19970
  onMomentumScrollEnd: handleScrollEnd,
19927
19971
  scrollEventThrottle: 16,
19928
- style: [styles.carouselContent, {
19929
- width: SLIDE_WIDTH
19930
- }],
19972
+ style: [styles.carouselContent],
19931
19973
  contentContainerStyle: {
19932
- width: SLIDE_WIDTH * sortedTiles.length
19974
+ width: containerWidth * sortedTiles.length
19933
19975
  },
19934
19976
  decelerationRate: "fast",
19935
- snapToInterval: SLIDE_WIDTH,
19977
+ snapToInterval: containerWidth,
19936
19978
  snapToAlignment: "start"
19937
19979
  }, sortedTiles.map(function (tile, index) {
19938
19980
  return /*#__PURE__*/React$1.createElement(View$2, {
19939
19981
  key: index,
19940
- style: [{
19941
- width: SLIDE_WIDTH
19982
+ style: [styles.slideContainer, {
19983
+ width: containerWidth
19942
19984
  }]
19943
19985
  }, /*#__PURE__*/React$1.createElement(BannerTile, {
19944
19986
  tile: tile