@hero-design/rn 8.55.1-rc2.3 → 8.55.1
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +2 -37
- package/es/index.js +19 -4
- package/lib/index.js +18 -3
- package/package.json +8 -8
- package/sonar-project.properties +1 -0
- package/src/components/Carousel/__tests__/__snapshots__/index.spec.tsx.snap +26 -833
- package/src/components/Carousel/__tests__/index.spec.tsx +9 -3
- package/src/components/Carousel/index.tsx +19 -6
|
@@ -64,6 +64,14 @@ describe('Carousel', () => {
|
|
|
64
64
|
/>
|
|
65
65
|
);
|
|
66
66
|
|
|
67
|
+
fireEvent(getByTestId('carousel_flatlist'), 'layout', {
|
|
68
|
+
nativeEvent: {
|
|
69
|
+
layout: {
|
|
70
|
+
width: 300,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
67
75
|
expect(getByTestId('carousel')).toBeTruthy();
|
|
68
76
|
|
|
69
77
|
expect(queryByText('Skip')).toBeTruthy();
|
|
@@ -96,7 +104,7 @@ describe('Carousel', () => {
|
|
|
96
104
|
it('should call skip call back when press skip', () => {
|
|
97
105
|
const onSkip = jest.fn();
|
|
98
106
|
|
|
99
|
-
const { queryByText
|
|
107
|
+
const { queryByText } = renderWithTheme(
|
|
100
108
|
<Carousel
|
|
101
109
|
testID="carousel"
|
|
102
110
|
items={carouselData}
|
|
@@ -106,8 +114,6 @@ describe('Carousel', () => {
|
|
|
106
114
|
/>
|
|
107
115
|
);
|
|
108
116
|
|
|
109
|
-
expect(toJSON()).toMatchSnapshot();
|
|
110
|
-
|
|
111
117
|
expect(queryByText('Skip')).toBeTruthy();
|
|
112
118
|
|
|
113
119
|
fireEvent.press(queryByText('Skip'));
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
ViewProps,
|
|
15
15
|
ViewStyle,
|
|
16
16
|
ViewToken,
|
|
17
|
-
|
|
17
|
+
LayoutChangeEvent,
|
|
18
18
|
} from 'react-native';
|
|
19
19
|
|
|
20
20
|
import { useTheme } from '../../theme';
|
|
@@ -112,13 +112,22 @@ const Carousel = ({
|
|
|
112
112
|
const internalOnItemIndexChange = useCallback(
|
|
113
113
|
(index: number) => {
|
|
114
114
|
setCurrentSlideIndex(index);
|
|
115
|
+
|
|
115
116
|
if (onItemIndexChange) {
|
|
116
117
|
onItemIndexChange(index);
|
|
117
118
|
}
|
|
118
119
|
},
|
|
119
120
|
[setCurrentSlideIndex, onItemIndexChange]
|
|
120
121
|
);
|
|
121
|
-
const
|
|
122
|
+
const [flatListWidth, setFlatListWidth] = useState(0);
|
|
123
|
+
const itemWidth = flatListWidth;
|
|
124
|
+
const flatListOnLayout = useCallback(
|
|
125
|
+
(e: LayoutChangeEvent) => {
|
|
126
|
+
setFlatListWidth(e.nativeEvent.layout.width);
|
|
127
|
+
},
|
|
128
|
+
[setFlatListWidth]
|
|
129
|
+
);
|
|
130
|
+
const width = flatListWidth;
|
|
122
131
|
|
|
123
132
|
const scrollX = useRef(new Animated.Value(0)).current;
|
|
124
133
|
useEffect(() => {
|
|
@@ -133,8 +142,7 @@ const Carousel = ({
|
|
|
133
142
|
return () => {
|
|
134
143
|
clearTimeout(handle);
|
|
135
144
|
};
|
|
136
|
-
}, [currentSlideIndex, carouselRef]);
|
|
137
|
-
|
|
145
|
+
}, [currentSlideIndex, carouselRef, scrollX, width]);
|
|
138
146
|
const viewConfig = useRef({ viewAreaCoveragePercentThreshold: 50 }).current;
|
|
139
147
|
|
|
140
148
|
const onViewCallBack = useRef(
|
|
@@ -167,7 +175,8 @@ const Carousel = ({
|
|
|
167
175
|
</StyledPageControlWrapper>
|
|
168
176
|
|
|
169
177
|
<StyledCarouselView>
|
|
170
|
-
<FlatList
|
|
178
|
+
<FlatList<CarouselData>
|
|
179
|
+
onLayout={flatListOnLayout}
|
|
171
180
|
testID={testID ? `${testID}_flatlist` : undefined}
|
|
172
181
|
horizontal
|
|
173
182
|
showsHorizontalScrollIndicator={false}
|
|
@@ -186,7 +195,6 @@ const Carousel = ({
|
|
|
186
195
|
if (!item) return null;
|
|
187
196
|
|
|
188
197
|
const { image, heading, body, content } = item;
|
|
189
|
-
|
|
190
198
|
return (
|
|
191
199
|
<CarouselItem
|
|
192
200
|
image={image}
|
|
@@ -197,6 +205,11 @@ const Carousel = ({
|
|
|
197
205
|
/>
|
|
198
206
|
);
|
|
199
207
|
}}
|
|
208
|
+
getItemLayout={(_, index) => ({
|
|
209
|
+
length: itemWidth,
|
|
210
|
+
offset: itemWidth * index,
|
|
211
|
+
index,
|
|
212
|
+
})}
|
|
200
213
|
/>
|
|
201
214
|
<StyledCarouselFooterWrapper>
|
|
202
215
|
{renderActions && renderActions(currentSlideIndex)}
|