@hero-design/rn 8.42.0-alpha.0 → 8.42.0

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 (36) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/es/index.js +614 -696
  3. package/lib/index.js +616 -700
  4. package/package.json +7 -8
  5. package/rollup.config.js +0 -1
  6. package/src/components/Carousel/__tests__/__snapshots__/CardCarousel.spec.tsx.snap +20 -0
  7. package/src/components/Carousel/__tests__/__snapshots__/StyledCardCarousel.spec.tsx.snap +15 -0
  8. package/src/components/Carousel/__tests__/__snapshots__/index.spec.tsx.snap +96 -3
  9. package/src/components/Carousel/__tests__/index.spec.tsx +47 -1
  10. package/src/components/Carousel/index.tsx +16 -22
  11. package/src/components/Error/StyledError.tsx +2 -1
  12. package/src/components/Error/__tests__/__snapshots__/index.spec.tsx.snap +115 -97
  13. package/src/components/Error/__tests__/index.spec.tsx +9 -6
  14. package/src/components/Modal/__tests__/__snapshots__/index.spec.tsx.snap +117 -0
  15. package/src/components/Modal/__tests__/index.spec.tsx +99 -0
  16. package/src/components/Modal/index.tsx +178 -82
  17. package/src/components/PageControl/__tests__/__snapshots__/index.spec.tsx.snap +15 -0
  18. package/src/components/PageControl/index.tsx +1 -0
  19. package/src/components/Success/StyledSuccess.tsx +2 -1
  20. package/src/components/Success/__tests__/__snapshots__/index.spec.tsx.snap +115 -95
  21. package/src/components/Success/__tests__/index.spec.tsx +9 -6
  22. package/src/index.ts +0 -2
  23. package/testUtils/setup.tsx +0 -18
  24. package/types/components/Carousel/index.d.ts +1 -1
  25. package/types/components/Error/StyledError.d.ts +3 -5
  26. package/types/components/Modal/index.d.ts +12 -8
  27. package/types/components/Success/StyledSuccess.d.ts +3 -5
  28. package/types/index.d.ts +1 -2
  29. package/src/components/Modal/ModalContentWrapper.tsx +0 -112
  30. package/src/components/Modal/ModalPresenter/ModalPresenter.tsx +0 -135
  31. package/src/components/Modal/ModalPresenter/index.tsx +0 -9
  32. package/src/components/Modal/ModalProvider.tsx +0 -8
  33. package/types/components/Modal/ModalContentWrapper.d.ts +0 -16
  34. package/types/components/Modal/ModalPresenter/ModalPresenter.d.ts +0 -34
  35. package/types/components/Modal/ModalPresenter/index.d.ts +0 -3
  36. package/types/components/Modal/ModalProvider.d.ts +0 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hero-design/rn",
3
- "version": "8.42.0-alpha.0",
3
+ "version": "8.42.0",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -21,14 +21,14 @@
21
21
  "dependencies": {
22
22
  "@emotion/native": "^11.9.3",
23
23
  "@emotion/react": "^11.9.3",
24
- "@hero-design/colors": "8.42.0-alpha.0",
24
+ "@hero-design/colors": "8.42.0",
25
25
  "date-fns": "^2.16.1",
26
26
  "events": "^3.2.0",
27
27
  "hero-editor": "^1.9.21",
28
28
  "nanoid": "^4.0.2"
29
29
  },
30
30
  "peerDependencies": {
31
- "@hero-design/react-native-month-year-picker": "^8.42.0-alpha.0",
31
+ "@hero-design/react-native-month-year-picker": "^8.42.0",
32
32
  "@react-native-community/datetimepicker": "^3.5.2",
33
33
  "@react-native-community/slider": "4.1.12",
34
34
  "react": "18.0.0",
@@ -36,7 +36,6 @@
36
36
  "react-native-gesture-handler": "^1.10.3 | ~2.5.0",
37
37
  "react-native-linear-gradient": "^2.6.2",
38
38
  "react-native-pager-view": "^5.4.25",
39
- "react-native-root-siblings": "^4.1.1",
40
39
  "react-native-safe-area-context": "^3.0.2",
41
40
  "react-native-vector-icons": "^9.1.0",
42
41
  "react-native-webview": "^11.2.5"
@@ -48,8 +47,8 @@
48
47
  "@babel/preset-typescript": "^7.17.12",
49
48
  "@babel/runtime": "^7.18.9",
50
49
  "@emotion/jest": "^11.11.0",
51
- "@hero-design/eslint-plugin": "8.42.0-alpha.0",
52
- "@hero-design/react-native-month-year-picker": "^8.42.0-alpha.0",
50
+ "@hero-design/eslint-plugin": "8.42.0",
51
+ "@hero-design/react-native-month-year-picker": "^8.42.0",
53
52
  "@react-native-community/datetimepicker": "^3.5.2",
54
53
  "@react-native-community/slider": "4.1.12",
55
54
  "@rollup/plugin-babel": "^5.3.1",
@@ -65,12 +64,12 @@
65
64
  "@types/react-native": "^0.67.7",
66
65
  "@types/react-native-vector-icons": "^6.4.10",
67
66
  "babel-plugin-inline-import": "^3.0.0",
68
- "eslint-config-hd": "8.42.0-alpha.0",
67
+ "eslint-config-hd": "8.42.0",
69
68
  "eslint-plugin-import": "^2.27.5",
70
69
  "jest": "^29.6.2",
71
70
  "jest-environment-jsdom": "^29.6.2",
72
71
  "jest-junit": "^16.0.0",
73
- "prettier-config-hd": "8.42.0-alpha.0",
72
+ "prettier-config-hd": "8.42.0",
74
73
  "react": "18.0.0",
75
74
  "react-native": "0.69.7",
76
75
  "react-native-gesture-handler": "~2.5.0",
package/rollup.config.js CHANGED
@@ -35,7 +35,6 @@ export default {
35
35
  'react-native-vector-icons',
36
36
  'react-native-linear-gradient',
37
37
  '@hero-design/react-native-month-year-picker',
38
- 'react-native-root-siblings',
39
38
  ],
40
39
  plugins: [
41
40
  replace({
@@ -264,6 +264,11 @@ exports[`CardCarousel android should render correctly on iOS 1`] = `
264
264
  testID="pageControl"
265
265
  >
266
266
  <View
267
+ accessibilityState={
268
+ {
269
+ "selected": true,
270
+ }
271
+ }
267
272
  collapsable={false}
268
273
  style={
269
274
  {
@@ -278,6 +283,11 @@ exports[`CardCarousel android should render correctly on iOS 1`] = `
278
283
  testID="page-control-indicator0"
279
284
  />
280
285
  <View
286
+ accessibilityState={
287
+ {
288
+ "selected": false,
289
+ }
290
+ }
281
291
  collapsable={false}
282
292
  style={
283
293
  {
@@ -559,6 +569,11 @@ exports[`CardCarousel ios should render correctly on iOS 1`] = `
559
569
  testID="pageControl"
560
570
  >
561
571
  <View
572
+ accessibilityState={
573
+ {
574
+ "selected": true,
575
+ }
576
+ }
562
577
  collapsable={false}
563
578
  style={
564
579
  {
@@ -573,6 +588,11 @@ exports[`CardCarousel ios should render correctly on iOS 1`] = `
573
588
  testID="page-control-indicator0"
574
589
  />
575
590
  <View
591
+ accessibilityState={
592
+ {
593
+ "selected": false,
594
+ }
595
+ }
576
596
  collapsable={false}
577
597
  style={
578
598
  {
@@ -53,6 +53,11 @@ exports[`StyledPageControl should render correctly 1`] = `
53
53
  }
54
54
  >
55
55
  <View
56
+ accessibilityState={
57
+ {
58
+ "selected": false,
59
+ }
60
+ }
56
61
  collapsable={false}
57
62
  style={
58
63
  {
@@ -67,6 +72,11 @@ exports[`StyledPageControl should render correctly 1`] = `
67
72
  testID="page-control-indicator0"
68
73
  />
69
74
  <View
75
+ accessibilityState={
76
+ {
77
+ "selected": true,
78
+ }
79
+ }
70
80
  collapsable={false}
71
81
  style={
72
82
  {
@@ -81,6 +91,11 @@ exports[`StyledPageControl should render correctly 1`] = `
81
91
  testID="page-control-indicator1"
82
92
  />
83
93
  <View
94
+ accessibilityState={
95
+ {
96
+ "selected": false,
97
+ }
98
+ }
84
99
  collapsable={false}
85
100
  style={
86
101
  {
@@ -99,18 +99,29 @@ exports[`Carousel renders correctly with pageControlPosition bottom 1`] = `
99
99
  onScroll={[Function]}
100
100
  onScrollBeginDrag={[Function]}
101
101
  onScrollEndDrag={[Function]}
102
+ onViewableItemsChanged={[Function]}
102
103
  pagingEnabled={true}
103
104
  removeClippedSubviews={false}
104
105
  renderItem={[Function]}
105
106
  scrollEventThrottle={32}
106
107
  showsHorizontalScrollIndicator={false}
107
108
  stickyHeaderIndices={[]}
109
+ testID="carousel_flatlist"
108
110
  viewabilityConfig={
109
111
  {
110
112
  "viewAreaCoveragePercentThreshold": 50,
111
113
  }
112
114
  }
113
- viewabilityConfigCallbackPairs={[]}
115
+ viewabilityConfigCallbackPairs={
116
+ [
117
+ {
118
+ "onViewableItemsChanged": [Function],
119
+ "viewabilityConfig": {
120
+ "viewAreaCoveragePercentThreshold": 50,
121
+ },
122
+ },
123
+ ]
124
+ }
114
125
  >
115
126
  <View>
116
127
  <View
@@ -667,6 +678,11 @@ exports[`Carousel renders correctly with pageControlPosition bottom 1`] = `
667
678
  }
668
679
  >
669
680
  <View
681
+ accessibilityState={
682
+ {
683
+ "selected": true,
684
+ }
685
+ }
670
686
  collapsable={false}
671
687
  style={
672
688
  {
@@ -681,6 +697,11 @@ exports[`Carousel renders correctly with pageControlPosition bottom 1`] = `
681
697
  testID="page-control-indicator0"
682
698
  />
683
699
  <View
700
+ accessibilityState={
701
+ {
702
+ "selected": false,
703
+ }
704
+ }
684
705
  collapsable={false}
685
706
  style={
686
707
  {
@@ -695,6 +716,11 @@ exports[`Carousel renders correctly with pageControlPosition bottom 1`] = `
695
716
  testID="page-control-indicator1"
696
717
  />
697
718
  <View
719
+ accessibilityState={
720
+ {
721
+ "selected": false,
722
+ }
723
+ }
698
724
  collapsable={false}
699
725
  style={
700
726
  {
@@ -709,6 +735,11 @@ exports[`Carousel renders correctly with pageControlPosition bottom 1`] = `
709
735
  testID="page-control-indicator2"
710
736
  />
711
737
  <View
738
+ accessibilityState={
739
+ {
740
+ "selected": false,
741
+ }
742
+ }
712
743
  collapsable={false}
713
744
  style={
714
745
  {
@@ -777,6 +808,11 @@ exports[`Carousel renders correctly with pageControlPosition top 1`] = `
777
808
  }
778
809
  >
779
810
  <View
811
+ accessibilityState={
812
+ {
813
+ "selected": true,
814
+ }
815
+ }
780
816
  collapsable={false}
781
817
  style={
782
818
  {
@@ -791,6 +827,11 @@ exports[`Carousel renders correctly with pageControlPosition top 1`] = `
791
827
  testID="page-control-indicator0"
792
828
  />
793
829
  <View
830
+ accessibilityState={
831
+ {
832
+ "selected": false,
833
+ }
834
+ }
794
835
  collapsable={false}
795
836
  style={
796
837
  {
@@ -805,6 +846,11 @@ exports[`Carousel renders correctly with pageControlPosition top 1`] = `
805
846
  testID="page-control-indicator1"
806
847
  />
807
848
  <View
849
+ accessibilityState={
850
+ {
851
+ "selected": false,
852
+ }
853
+ }
808
854
  collapsable={false}
809
855
  style={
810
856
  {
@@ -819,6 +865,11 @@ exports[`Carousel renders correctly with pageControlPosition top 1`] = `
819
865
  testID="page-control-indicator2"
820
866
  />
821
867
  <View
868
+ accessibilityState={
869
+ {
870
+ "selected": false,
871
+ }
872
+ }
822
873
  collapsable={false}
823
874
  style={
824
875
  {
@@ -901,18 +952,29 @@ exports[`Carousel renders correctly with pageControlPosition top 1`] = `
901
952
  onScroll={[Function]}
902
953
  onScrollBeginDrag={[Function]}
903
954
  onScrollEndDrag={[Function]}
955
+ onViewableItemsChanged={[Function]}
904
956
  pagingEnabled={true}
905
957
  removeClippedSubviews={false}
906
958
  renderItem={[Function]}
907
959
  scrollEventThrottle={32}
908
960
  showsHorizontalScrollIndicator={false}
909
961
  stickyHeaderIndices={[]}
962
+ testID="carousel_flatlist"
910
963
  viewabilityConfig={
911
964
  {
912
965
  "viewAreaCoveragePercentThreshold": 50,
913
966
  }
914
967
  }
915
- viewabilityConfigCallbackPairs={[]}
968
+ viewabilityConfigCallbackPairs={
969
+ [
970
+ {
971
+ "onViewableItemsChanged": [Function],
972
+ "viewabilityConfig": {
973
+ "viewAreaCoveragePercentThreshold": 50,
974
+ },
975
+ },
976
+ ]
977
+ }
916
978
  >
917
979
  <View>
918
980
  <View
@@ -1506,6 +1568,11 @@ exports[`Carousel should call skip call back when press skip 1`] = `
1506
1568
  }
1507
1569
  >
1508
1570
  <View
1571
+ accessibilityState={
1572
+ {
1573
+ "selected": true,
1574
+ }
1575
+ }
1509
1576
  collapsable={false}
1510
1577
  style={
1511
1578
  {
@@ -1520,6 +1587,11 @@ exports[`Carousel should call skip call back when press skip 1`] = `
1520
1587
  testID="page-control-indicator0"
1521
1588
  />
1522
1589
  <View
1590
+ accessibilityState={
1591
+ {
1592
+ "selected": false,
1593
+ }
1594
+ }
1523
1595
  collapsable={false}
1524
1596
  style={
1525
1597
  {
@@ -1534,6 +1606,11 @@ exports[`Carousel should call skip call back when press skip 1`] = `
1534
1606
  testID="page-control-indicator1"
1535
1607
  />
1536
1608
  <View
1609
+ accessibilityState={
1610
+ {
1611
+ "selected": false,
1612
+ }
1613
+ }
1537
1614
  collapsable={false}
1538
1615
  style={
1539
1616
  {
@@ -1548,6 +1625,11 @@ exports[`Carousel should call skip call back when press skip 1`] = `
1548
1625
  testID="page-control-indicator2"
1549
1626
  />
1550
1627
  <View
1628
+ accessibilityState={
1629
+ {
1630
+ "selected": false,
1631
+ }
1632
+ }
1551
1633
  collapsable={false}
1552
1634
  style={
1553
1635
  {
@@ -1630,18 +1712,29 @@ exports[`Carousel should call skip call back when press skip 1`] = `
1630
1712
  onScroll={[Function]}
1631
1713
  onScrollBeginDrag={[Function]}
1632
1714
  onScrollEndDrag={[Function]}
1715
+ onViewableItemsChanged={[Function]}
1633
1716
  pagingEnabled={true}
1634
1717
  removeClippedSubviews={false}
1635
1718
  renderItem={[Function]}
1636
1719
  scrollEventThrottle={32}
1637
1720
  showsHorizontalScrollIndicator={false}
1638
1721
  stickyHeaderIndices={[]}
1722
+ testID="carousel_flatlist"
1639
1723
  viewabilityConfig={
1640
1724
  {
1641
1725
  "viewAreaCoveragePercentThreshold": 50,
1642
1726
  }
1643
1727
  }
1644
- viewabilityConfigCallbackPairs={[]}
1728
+ viewabilityConfigCallbackPairs={
1729
+ [
1730
+ {
1731
+ "onViewableItemsChanged": [Function],
1732
+ "viewabilityConfig": {
1733
+ "viewAreaCoveragePercentThreshold": 50,
1734
+ },
1735
+ },
1736
+ ]
1737
+ }
1645
1738
  >
1646
1739
  <View>
1647
1740
  <View
@@ -4,7 +4,7 @@ import { ImageResizeMode } from 'react-native';
4
4
  import renderWithTheme from '../../../testHelpers/renderWithTheme';
5
5
  import Carousel from '..';
6
6
  import Image from '../../Image';
7
- import { theme } from '../../..';
7
+ import { ThemeProvider, theme } from '../../..';
8
8
  import Button from '../../Button/Button';
9
9
 
10
10
  const carouselData = [
@@ -112,4 +112,50 @@ describe('Carousel', () => {
112
112
  fireEvent.press(queryByText('Skip'));
113
113
  expect(onSkip).toBeCalled();
114
114
  });
115
+
116
+ it("pageControl' current index should change to 1 when scroll", async () => {
117
+ const onSkip = jest.fn();
118
+
119
+ const { rerender, getByTestId } = renderWithTheme(
120
+ <Carousel
121
+ testID="carousel"
122
+ items={carouselData}
123
+ renderActions={(_) => {
124
+ return <Button text="Skip" onPress={onSkip} />;
125
+ }}
126
+ />
127
+ );
128
+ const eventData = {
129
+ viewableItems: [
130
+ {
131
+ index: 0,
132
+ isViewable: false,
133
+ },
134
+ {
135
+ index: 1,
136
+ isViewable: true,
137
+ },
138
+ ],
139
+ };
140
+ fireEvent(
141
+ getByTestId('carousel_flatlist'),
142
+ 'onViewableItemsChanged',
143
+ eventData
144
+ );
145
+ rerender(
146
+ <ThemeProvider theme={theme}>
147
+ <Carousel
148
+ testID="carousel"
149
+ items={carouselData}
150
+ renderActions={(_) => {
151
+ return <Button text="Skip" onPress={onSkip} />;
152
+ }}
153
+ />
154
+ </ThemeProvider>
155
+ );
156
+
157
+ expect(getByTestId('page-control-indicator1')).toHaveAccessibilityState({
158
+ selected: true,
159
+ });
160
+ });
115
161
  });
@@ -9,13 +9,12 @@ import React, {
9
9
  import {
10
10
  Animated,
11
11
  FlatList,
12
- NativeScrollEvent,
13
- NativeSyntheticEvent,
14
12
  StyleProp,
15
13
  useWindowDimensions,
16
14
  View,
17
15
  ViewProps,
18
16
  ViewStyle,
17
+ ViewToken,
19
18
  } from 'react-native';
20
19
 
21
20
  import { CarouselData } from './types';
@@ -87,6 +86,7 @@ const Carousel = ({
87
86
  selectedItemIndex = 0,
88
87
  style,
89
88
  shouldShowPagination = noop,
89
+ testID,
90
90
  pageControlPosition = 'top',
91
91
  ...nativeProps
92
92
  }: CarouselProps) => {
@@ -129,27 +129,20 @@ const Carousel = ({
129
129
  };
130
130
  }, [currentSlideIndex, carouselRef]);
131
131
 
132
- const handleMomentumScrollEnd = (
133
- event: NativeSyntheticEvent<NativeScrollEvent>
134
- ) => {
135
- // Calculate the current index based on the scroll position and container width
136
- const containerWidth = event.nativeEvent.layoutMeasurement.width;
137
- const scrollPosition = event.nativeEvent.contentOffset.x;
138
-
139
- /**
140
- * By rounding down, we ensure that any partial visibility of the next item does not affect the index value
141
- * This helps maintain consistent behavior and aligns with the desired functionality of considering the left-most visible item as the current item.
142
- */
143
- const index = Math.floor(scrollPosition / containerWidth);
144
-
145
- // Call the callback function with the current index
146
- internalOnItemIndexChange(index);
147
- };
148
-
149
132
  const viewConfig = useRef({ viewAreaCoveragePercentThreshold: 50 }).current;
150
-
133
+ const onViewCallBack = React.useCallback(
134
+ (info: { viewableItems: Array<ViewToken>; changed: Array<ViewToken> }) => {
135
+ const firstVisibleItem = info.viewableItems.find(
136
+ (view) => view.index != null && view.isViewable
137
+ );
138
+ if (firstVisibleItem) {
139
+ internalOnItemIndexChange(firstVisibleItem.index || 0);
140
+ }
141
+ },
142
+ [internalOnItemIndexChange]
143
+ );
151
144
  return (
152
- <View style={style} {...nativeProps}>
145
+ <View style={style} testID={testID} {...nativeProps}>
153
146
  <StyledBackDrop
154
147
  themeSlideBackground={items[currentSlideIndex].background}
155
148
  />
@@ -166,12 +159,13 @@ const Carousel = ({
166
159
 
167
160
  <StyledCarouselView>
168
161
  <FlatList
162
+ testID={testID ? `${testID}_flatlist` : undefined}
169
163
  horizontal
170
164
  showsHorizontalScrollIndicator={false}
171
165
  pagingEnabled
172
166
  bounces={false}
173
167
  data={items}
174
- onMomentumScrollEnd={handleMomentumScrollEnd}
168
+ onViewableItemsChanged={onViewCallBack}
175
169
  viewabilityConfig={viewConfig}
176
170
  scrollEventThrottle={32}
177
171
  ref={carouselRef}
@@ -1,8 +1,9 @@
1
1
  import styled from '@emotion/native';
2
- import { Modal, View } from 'react-native';
2
+ import { View } from 'react-native';
3
3
  import Image from '../Image';
4
4
  import Typography from '../Typography';
5
5
  import Button from '../Button';
6
+ import Modal from '../Modal';
6
7
 
7
8
  type ErrorVariant = 'full-screen' | 'in-page';
8
9