@proximus/lavender-carousel-native 0.1.0-alpha.10 → 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 +11 -4
- package/dist/Carousel.d.ts.map +1 -1
- package/dist/Carousel.js +39 -14
- package/package.json +1 -1
package/dist/Carousel.d.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { AccessibilityProps, StyleProp, ViewStyle } from 'react-native';
|
|
3
|
-
export
|
|
2
|
+
import { AccessibilityProps, ListRenderItem, StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
export type Gap = '2xs' | 'Xs' | 'S' | 'Default' | 'L';
|
|
4
|
+
export interface CarouselProps {
|
|
4
5
|
numberOfItemsVisible?: number;
|
|
5
|
-
|
|
6
|
+
renderItem?: ListRenderItem<any>;
|
|
7
|
+
data: any[];
|
|
6
8
|
withAppleSeed?: boolean;
|
|
7
9
|
containerStyle?: StyleProp<ViewStyle>;
|
|
8
10
|
testID?: string;
|
|
9
11
|
accessibilityProps?: AccessibilityProps;
|
|
10
|
-
|
|
12
|
+
hasPreview?: boolean;
|
|
13
|
+
snap?: boolean;
|
|
14
|
+
gap?: Gap;
|
|
15
|
+
onItemDisplayed?: (index: number) => void;
|
|
16
|
+
}
|
|
17
|
+
export declare function PxCarousel(props: CarouselProps): React.JSX.Element | null;
|
|
11
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,
|
|
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,49 +4,73 @@ 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);
|
|
11
23
|
const [selectedItemIndex, setSelectedItemIndex] = useState(0);
|
|
12
24
|
const [offsets, setOffsets] = useState([]);
|
|
13
25
|
const { theme } = useTheme();
|
|
26
|
+
const computedInset = hasPreview ? inset : 0;
|
|
14
27
|
useEffect(() => {
|
|
15
28
|
setWidth((Dimensions.get('window').width -
|
|
16
29
|
numberOfItemsVisible * computedGap -
|
|
17
|
-
2 *
|
|
30
|
+
2 * computedInset) /
|
|
18
31
|
numberOfItemsVisible);
|
|
19
|
-
}, [numberOfItemsVisible, computedGap, theme]);
|
|
32
|
+
}, [numberOfItemsVisible, computedGap, theme, computedInset]);
|
|
20
33
|
useEffect(() => {
|
|
21
|
-
setElementsCount(
|
|
22
|
-
}, [
|
|
34
|
+
setElementsCount(data.length);
|
|
35
|
+
}, [data]);
|
|
23
36
|
useEffect(() => {
|
|
24
|
-
setComputedGap(theme.t(`
|
|
25
|
-
}, [theme]);
|
|
37
|
+
setComputedGap(hasPreview ? theme.t(`Spacing${gap}Mobile`).number : 0);
|
|
38
|
+
}, [theme, hasPreview, gap]);
|
|
26
39
|
useEffect(() => {
|
|
27
40
|
setOffsets(new Array(elementsCount).fill(0).reduce((prev, _, i) => {
|
|
28
41
|
return [...prev, prev[i] + width + computedGap];
|
|
29
42
|
}, [width]));
|
|
30
43
|
}, [computedGap, elementsCount, width]);
|
|
31
44
|
return (React.createElement(View, { style: [containerStyle, { flexDirection: 'column', gap: 27.15, flex: 1 }], ...e2eID(testID), ...a11y(accessibilityProps) },
|
|
32
|
-
React.createElement(FlatList, { data:
|
|
45
|
+
React.createElement(FlatList, { data: data, renderItem: (data) => (React.createElement(View, { style: { width } }, renderItem?.(data))), contentContainerStyle: {
|
|
33
46
|
gap: computedGap,
|
|
34
47
|
alignItems: 'stretch',
|
|
35
48
|
paddingLeft: computedGap,
|
|
36
|
-
}, horizontal: true,
|
|
49
|
+
}, horizontal: true, ...(snap && {
|
|
50
|
+
snapToOffsets: offsets,
|
|
51
|
+
decelerationRate: 'fast',
|
|
52
|
+
snapToAlignment: numberOfItemsVisible === 1 ? 'center' : 'start',
|
|
53
|
+
}), showsHorizontalScrollIndicator: false, ...(data.length === 2 && {
|
|
37
54
|
onEndReached: () => {
|
|
55
|
+
onItemDisplayed?.(1);
|
|
38
56
|
setSelectedItemIndex(1);
|
|
39
57
|
},
|
|
40
58
|
onStartReached: () => {
|
|
59
|
+
onItemDisplayed?.(0);
|
|
41
60
|
setSelectedItemIndex(0);
|
|
42
61
|
},
|
|
43
62
|
}), onViewableItemsChanged: (event) => {
|
|
44
|
-
|
|
45
|
-
if (
|
|
63
|
+
const firstViewableIndex = event.viewableItems?.[0]?.index ?? 0;
|
|
64
|
+
if (!hasPreview) {
|
|
65
|
+
onItemDisplayed?.(firstViewableIndex);
|
|
66
|
+
setSelectedItemIndex(firstViewableIndex);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (data.length === 2) {
|
|
46
70
|
return;
|
|
47
71
|
}
|
|
48
|
-
if (event.viewableItems.length === 2 &&
|
|
49
|
-
|
|
72
|
+
if (event.viewableItems.length === 2 && firstViewableIndex === 0) {
|
|
73
|
+
onItemDisplayed?.(0);
|
|
50
74
|
setSelectedItemIndex(0);
|
|
51
75
|
return;
|
|
52
76
|
}
|
|
@@ -56,7 +80,8 @@ export function PxCarousel({ numberOfItemsVisible = 1, children, withAppleSeed =
|
|
|
56
80
|
if (event.viewableItems.length === 1) {
|
|
57
81
|
return;
|
|
58
82
|
}
|
|
83
|
+
onItemDisplayed?.(firstViewableIndex);
|
|
59
84
|
setSelectedItemIndex(event.viewableItems?.[1]?.index ?? 0);
|
|
60
85
|
} }),
|
|
61
|
-
withAppleSeed && elementsCount > 1 && (React.createElement(PxAppleSeed, { numberOfItems:
|
|
86
|
+
withAppleSeed && elementsCount > 1 && (React.createElement(PxAppleSeed, { numberOfItems: data.length, selectedItemIndex: selectedItemIndex }))));
|
|
62
87
|
}
|