@shoutem/ui 9.3.1-rc.0 → 9.3.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.
@@ -98,6 +98,12 @@ const slideFillStyle = { flex: 1 };
98
98
  * rendered over a slide's image until it has loaded.
99
99
  * @param {Function} [onIndexChange] `(index) => void`, called when the active
100
100
  * slide changes (not on mount).
101
+ * @param {Function} [onImageLoadEnd] `(item, { index }) => void`, called when a
102
+ * slide's image finishes loading, whether it succeeded or failed.
103
+ * @param {boolean} [scrollEnabled] Whether the user can swipe between slides.
104
+ * Defaults to true. When false, autoplay does not advance and arrows are
105
+ * hidden; page indicators are unaffected. Swiping is also disabled when
106
+ * there's only one slide.
101
107
  * @param {Object} style Resolved styles, injected by connectStyle. Geometry is
102
108
  * read from the `cardWidth`, `cardSpacing`, `inactiveScale` and
103
109
  * `inactiveOpacity` scalars. `style.slide` is passed to every
@@ -122,6 +128,8 @@ const ImageCarousel = ({
122
128
  renderOverlay,
123
129
  renderImagePlaceholder,
124
130
  onIndexChange,
131
+ onImageLoadEnd,
132
+ scrollEnabled = true,
125
133
  style = {},
126
134
  }) => {
127
135
  const { width: windowWidth } = useWindowDimensions();
@@ -174,7 +182,13 @@ const ImageCarousel = ({
174
182
  );
175
183
 
176
184
  useEffect(() => {
177
- if (!autoplay || data.length < 2 || !snapInterval || isInteracting) {
185
+ if (
186
+ !autoplay ||
187
+ !scrollEnabled ||
188
+ data.length < 2 ||
189
+ !snapInterval ||
190
+ isInteracting
191
+ ) {
178
192
  return undefined;
179
193
  }
180
194
 
@@ -186,6 +200,7 @@ const ImageCarousel = ({
186
200
  }, [
187
201
  autoplay,
188
202
  autoplayIntervalMs,
203
+ scrollEnabled,
189
204
  activeIndex,
190
205
  isInteracting,
191
206
  data.length,
@@ -334,6 +349,7 @@ const ImageCarousel = ({
334
349
  source={getImageSource(item)}
335
350
  renderOverlay={renderOverlay}
336
351
  renderImagePlaceholder={renderImagePlaceholder}
352
+ onImageLoadEnd={onImageLoadEnd}
337
353
  style={style.slide}
338
354
  />
339
355
  </Animated.View>
@@ -344,6 +360,7 @@ const ImageCarousel = ({
344
360
  getImageSource,
345
361
  renderOverlay,
346
362
  renderImagePlaceholder,
363
+ onImageLoadEnd,
347
364
  itemWrapperStyle,
348
365
  scrollX,
349
366
  snapOffsets,
@@ -374,7 +391,7 @@ const ImageCarousel = ({
374
391
  decelerationRate="fast"
375
392
  disableIntervalMomentum
376
393
  getItemLayout={getItemLayout}
377
- scrollEnabled={data.length > 1}
394
+ scrollEnabled={scrollEnabled && data.length > 1}
378
395
  bounces={false}
379
396
  scrollEventThrottle={16}
380
397
  removeClippedSubviews={false}
@@ -394,7 +411,7 @@ const ImageCarousel = ({
394
411
  style={style.pageIndicators}
395
412
  />
396
413
  )}
397
- {showArrows && activeIndex > 0 && (
414
+ {showArrows && scrollEnabled && activeIndex > 0 && (
398
415
  <TouchableOpacity
399
416
  style={style.leftArrow}
400
417
  onPress={handlePrevArrowPress}
@@ -402,7 +419,7 @@ const ImageCarousel = ({
402
419
  <Icon name="left-arrow" style={style.arrowIcon} />
403
420
  </TouchableOpacity>
404
421
  )}
405
- {showArrows && activeIndex < data.length - 1 && (
422
+ {showArrows && scrollEnabled && activeIndex < data.length - 1 && (
406
423
  <TouchableOpacity
407
424
  style={style.rightArrow}
408
425
  onPress={handleNextArrowPress}
@@ -426,9 +443,11 @@ ImageCarousel.propTypes = {
426
443
  maxPageIndicators: PropTypes.number,
427
444
  renderImagePlaceholder: PropTypes.func,
428
445
  renderOverlay: PropTypes.func,
446
+ scrollEnabled: PropTypes.bool,
429
447
  showArrows: PropTypes.bool,
430
448
  showPageIndicators: PropTypes.bool,
431
449
  style: PropTypes.object,
450
+ onImageLoadEnd: PropTypes.func,
432
451
  onIndexChange: PropTypes.func,
433
452
  };
434
453
 
@@ -17,6 +17,8 @@ import { View } from '../View';
17
17
  * rendered on top of the image.
18
18
  * @param {Function} [renderImagePlaceholder] `(item, { index }) => JSX.Element`
19
19
  * rendered over the image until it finishes loading.
20
+ * @param {Function} [onImageLoadEnd] `(item, { index }) => void`, called once
21
+ * the image finishes loading, whether it succeeded or failed.
20
22
  * @param {Object} style Resolved styles, injected by connectStyle.
21
23
  * @returns {JSX.Element}
22
24
  */
@@ -27,13 +29,18 @@ const ImageCarouselSlide = ({
27
29
  source,
28
30
  renderOverlay,
29
31
  renderImagePlaceholder,
32
+ onImageLoadEnd,
30
33
  style = {},
31
34
  }) => {
32
35
  const [isImageLoaded, setImageLoaded] = useState(false);
33
36
 
34
37
  const handleImageLoadEnd = useCallback(() => {
35
38
  setImageLoaded(true);
36
- }, []);
39
+
40
+ if (onImageLoadEnd) {
41
+ onImageLoadEnd(item, { index });
42
+ }
43
+ }, [onImageLoadEnd, item, index]);
37
44
 
38
45
  const placeholder =
39
46
  !isImageLoaded && renderImagePlaceholder
@@ -65,6 +72,7 @@ ImageCarouselSlide.propTypes = {
65
72
  renderOverlay: PropTypes.func,
66
73
  source: PropTypes.oneOfType([PropTypes.object, PropTypes.number]),
67
74
  style: PropTypes.object,
75
+ onImageLoadEnd: PropTypes.func,
68
76
  };
69
77
 
70
78
  const StyledImageCarouselSlide = connectStyle('shoutem.ui.ImageCarouselSlide')(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shoutem/ui",
3
- "version": "9.3.1-rc.0",
3
+ "version": "9.3.1",
4
4
  "description": "Styleable set of components for React Native applications",
5
5
  "scripts": {
6
6
  "lint": "eslint .",