@proximus/lavender-carousel-native 0.1.0-alpha.11 → 0.1.0-alpha.12
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/Carousel.d.ts +7 -4
- package/dist/Carousel.d.ts.map +1 -1
- package/dist/Carousel.js +28 -11
- package/package.json +1 -1
package/dist/Carousel.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { AccessibilityProps, StyleProp, ViewStyle } from 'react-native';
|
|
2
|
+
import { AccessibilityProps, ListRenderItem, StyleProp, ViewStyle } from 'react-native';
|
|
3
3
|
export type Gap = '2xs' | 'Xs' | 'S' | 'Default' | 'L';
|
|
4
|
-
export
|
|
4
|
+
export interface CarouselProps {
|
|
5
5
|
numberOfItemsVisible?: number;
|
|
6
|
-
|
|
6
|
+
renderItem?: ListRenderItem<any>;
|
|
7
|
+
data: any[];
|
|
7
8
|
withAppleSeed?: boolean;
|
|
8
9
|
containerStyle?: StyleProp<ViewStyle>;
|
|
9
10
|
testID?: string;
|
|
@@ -11,5 +12,7 @@ export declare function PxCarousel({ numberOfItemsVisible, children, withAppleSe
|
|
|
11
12
|
hasPreview?: boolean;
|
|
12
13
|
snap?: boolean;
|
|
13
14
|
gap?: Gap;
|
|
14
|
-
|
|
15
|
+
onItemDisplayed?: (index: number) => void;
|
|
16
|
+
}
|
|
17
|
+
export declare function PxCarousel(props: CarouselProps): React.JSX.Element | null;
|
|
15
18
|
//# sourceMappingURL=Carousel.d.ts.map
|
package/dist/Carousel.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Carousel.d.ts","sourceRoot":"","sources":["../src/Carousel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,EACL,kBAAkB,EAGlB,SAAS,EAET,SAAS,EACV,MAAM,cAAc,CAAC;AAOtB,MAAM,MAAM,GAAG,GAAG,KAAK,GAAG,IAAI,GAAG,GAAG,GAAG,SAAS,GAAG,GAAG,CAAC;AAEvD,
|
|
1
|
+
{"version":3,"file":"Carousel.d.ts","sourceRoot":"","sources":["../src/Carousel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,EACL,kBAAkB,EAGlB,cAAc,EACd,SAAS,EAET,SAAS,EACV,MAAM,cAAc,CAAC;AAOtB,MAAM,MAAM,GAAG,GAAG,KAAK,GAAG,IAAI,GAAG,GAAG,GAAG,SAAS,GAAG,GAAG,CAAC;AAEvD,MAAM,WAAW,aAAa;IAC5B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,UAAU,CAAC,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,cAAc,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3C;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,4BAiB9C"}
|
package/dist/Carousel.js
CHANGED
|
@@ -4,7 +4,19 @@ import { useTheme } from '@proximus/lavender-styling-native';
|
|
|
4
4
|
import { PxAppleSeed } from './AppleSeed';
|
|
5
5
|
import { a11y, e2eID } from '@proximus/lavender-common-native';
|
|
6
6
|
const inset = 24;
|
|
7
|
-
export function PxCarousel(
|
|
7
|
+
export function PxCarousel(props) {
|
|
8
|
+
const { data } = props;
|
|
9
|
+
if (!data || data.length === 0) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
else if (data.length === 1) {
|
|
13
|
+
return (React.createElement(View, { style: [props.containerStyle, { flex: 1 }], ...e2eID(props.testID), ...a11y(props.accessibilityProps) }, props.renderItem?.({ item: data[0], index: 0, separators: {} })));
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return React.createElement(_PxCarousel, { ...props });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function _PxCarousel({ numberOfItemsVisible = 1, renderItem, data, withAppleSeed = true, containerStyle, testID, accessibilityProps, hasPreview = true, snap = true, gap = 'S', onItemDisplayed, }) {
|
|
8
20
|
const [width, setWidth] = useState(0);
|
|
9
21
|
const [computedGap, setComputedGap] = useState(0);
|
|
10
22
|
const [elementsCount, setElementsCount] = useState(0);
|
|
@@ -19,8 +31,8 @@ export function PxCarousel({ numberOfItemsVisible = 1, children, withAppleSeed =
|
|
|
19
31
|
numberOfItemsVisible);
|
|
20
32
|
}, [numberOfItemsVisible, computedGap, theme, computedInset]);
|
|
21
33
|
useEffect(() => {
|
|
22
|
-
setElementsCount(
|
|
23
|
-
}, [
|
|
34
|
+
setElementsCount(data.length);
|
|
35
|
+
}, [data]);
|
|
24
36
|
useEffect(() => {
|
|
25
37
|
setComputedGap(hasPreview ? theme.t(`Spacing${gap}Mobile`).number : 0);
|
|
26
38
|
}, [theme, hasPreview, gap]);
|
|
@@ -30,7 +42,7 @@ export function PxCarousel({ numberOfItemsVisible = 1, children, withAppleSeed =
|
|
|
30
42
|
}, [width]));
|
|
31
43
|
}, [computedGap, elementsCount, width]);
|
|
32
44
|
return (React.createElement(View, { style: [containerStyle, { flexDirection: 'column', gap: 27.15, flex: 1 }], ...e2eID(testID), ...a11y(accessibilityProps) },
|
|
33
|
-
React.createElement(FlatList, { data:
|
|
45
|
+
React.createElement(FlatList, { data: data, renderItem: (data) => (React.createElement(View, { style: { width } }, renderItem?.(data))), contentContainerStyle: {
|
|
34
46
|
gap: computedGap,
|
|
35
47
|
alignItems: 'stretch',
|
|
36
48
|
paddingLeft: computedGap,
|
|
@@ -38,23 +50,27 @@ export function PxCarousel({ numberOfItemsVisible = 1, children, withAppleSeed =
|
|
|
38
50
|
snapToOffsets: offsets,
|
|
39
51
|
decelerationRate: 'fast',
|
|
40
52
|
snapToAlignment: numberOfItemsVisible === 1 ? 'center' : 'start',
|
|
41
|
-
}), showsHorizontalScrollIndicator: false, ...(
|
|
53
|
+
}), showsHorizontalScrollIndicator: false, ...(data.length === 2 && {
|
|
42
54
|
onEndReached: () => {
|
|
55
|
+
onItemDisplayed?.(1);
|
|
43
56
|
setSelectedItemIndex(1);
|
|
44
57
|
},
|
|
45
58
|
onStartReached: () => {
|
|
59
|
+
onItemDisplayed?.(0);
|
|
46
60
|
setSelectedItemIndex(0);
|
|
47
61
|
},
|
|
48
62
|
}), onViewableItemsChanged: (event) => {
|
|
63
|
+
const firstViewableIndex = event.viewableItems?.[0]?.index ?? 0;
|
|
49
64
|
if (!hasPreview) {
|
|
50
|
-
|
|
65
|
+
onItemDisplayed?.(firstViewableIndex);
|
|
66
|
+
setSelectedItemIndex(firstViewableIndex);
|
|
67
|
+
return;
|
|
51
68
|
}
|
|
52
|
-
|
|
53
|
-
if (children?.length === 2) {
|
|
69
|
+
if (data.length === 2) {
|
|
54
70
|
return;
|
|
55
71
|
}
|
|
56
|
-
if (event.viewableItems.length === 2 &&
|
|
57
|
-
|
|
72
|
+
if (event.viewableItems.length === 2 && firstViewableIndex === 0) {
|
|
73
|
+
onItemDisplayed?.(0);
|
|
58
74
|
setSelectedItemIndex(0);
|
|
59
75
|
return;
|
|
60
76
|
}
|
|
@@ -64,7 +80,8 @@ export function PxCarousel({ numberOfItemsVisible = 1, children, withAppleSeed =
|
|
|
64
80
|
if (event.viewableItems.length === 1) {
|
|
65
81
|
return;
|
|
66
82
|
}
|
|
83
|
+
onItemDisplayed?.(firstViewableIndex);
|
|
67
84
|
setSelectedItemIndex(event.viewableItems?.[1]?.index ?? 0);
|
|
68
85
|
} }),
|
|
69
|
-
withAppleSeed && elementsCount > 1 && (React.createElement(PxAppleSeed, { numberOfItems:
|
|
86
|
+
withAppleSeed && elementsCount > 1 && (React.createElement(PxAppleSeed, { numberOfItems: data.length, selectedItemIndex: selectedItemIndex }))));
|
|
70
87
|
}
|