@proximus/lavender-carousel-native 0.1.0-alpha.10 → 0.1.0-alpha.11
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 +5 -1
- package/dist/Carousel.d.ts.map +1 -1
- package/dist/Carousel.js +14 -6
- package/package.json +1 -1
package/dist/Carousel.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { AccessibilityProps, StyleProp, ViewStyle } from 'react-native';
|
|
3
|
-
export
|
|
3
|
+
export type Gap = '2xs' | 'Xs' | 'S' | 'Default' | 'L';
|
|
4
|
+
export declare function PxCarousel({ numberOfItemsVisible, children, withAppleSeed, containerStyle, testID, accessibilityProps, hasPreview, snap, gap, }: {
|
|
4
5
|
numberOfItemsVisible?: number;
|
|
5
6
|
children?: React.ReactNode;
|
|
6
7
|
withAppleSeed?: boolean;
|
|
7
8
|
containerStyle?: StyleProp<ViewStyle>;
|
|
8
9
|
testID?: string;
|
|
9
10
|
accessibilityProps?: AccessibilityProps;
|
|
11
|
+
hasPreview?: boolean;
|
|
12
|
+
snap?: boolean;
|
|
13
|
+
gap?: Gap;
|
|
10
14
|
}): React.JSX.Element;
|
|
11
15
|
//# 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,wBAAgB,UAAU,CAAC,EACzB,oBAAwB,EACxB,QAAQ,EACR,aAAoB,EACpB,cAAc,EACd,MAAM,EACN,kBAAkB,
|
|
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,wBAAgB,UAAU,CAAC,EACzB,oBAAwB,EACxB,QAAQ,EACR,aAAoB,EACpB,cAAc,EACd,MAAM,EACN,kBAAkB,EAClB,UAAiB,EACjB,IAAW,EACX,GAAS,GACV,EAAE;IACD,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,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;CACX,qBA2GA"}
|
package/dist/Carousel.js
CHANGED
|
@@ -4,25 +4,26 @@ 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({ numberOfItemsVisible = 1, children, withAppleSeed = true, containerStyle, testID, accessibilityProps, }) {
|
|
7
|
+
export function PxCarousel({ numberOfItemsVisible = 1, children, withAppleSeed = true, containerStyle, testID, accessibilityProps, hasPreview = true, snap = true, gap = 'S', }) {
|
|
8
8
|
const [width, setWidth] = useState(0);
|
|
9
9
|
const [computedGap, setComputedGap] = useState(0);
|
|
10
10
|
const [elementsCount, setElementsCount] = useState(0);
|
|
11
11
|
const [selectedItemIndex, setSelectedItemIndex] = useState(0);
|
|
12
12
|
const [offsets, setOffsets] = useState([]);
|
|
13
13
|
const { theme } = useTheme();
|
|
14
|
+
const computedInset = hasPreview ? inset : 0;
|
|
14
15
|
useEffect(() => {
|
|
15
16
|
setWidth((Dimensions.get('window').width -
|
|
16
17
|
numberOfItemsVisible * computedGap -
|
|
17
|
-
2 *
|
|
18
|
+
2 * computedInset) /
|
|
18
19
|
numberOfItemsVisible);
|
|
19
|
-
}, [numberOfItemsVisible, computedGap, theme]);
|
|
20
|
+
}, [numberOfItemsVisible, computedGap, theme, computedInset]);
|
|
20
21
|
useEffect(() => {
|
|
21
22
|
setElementsCount(React.Children.count(children));
|
|
22
23
|
}, [children]);
|
|
23
24
|
useEffect(() => {
|
|
24
|
-
setComputedGap(theme.t(`
|
|
25
|
-
}, [theme]);
|
|
25
|
+
setComputedGap(hasPreview ? theme.t(`Spacing${gap}Mobile`).number : 0);
|
|
26
|
+
}, [theme, hasPreview, gap]);
|
|
26
27
|
useEffect(() => {
|
|
27
28
|
setOffsets(new Array(elementsCount).fill(0).reduce((prev, _, i) => {
|
|
28
29
|
return [...prev, prev[i] + width + computedGap];
|
|
@@ -33,7 +34,11 @@ export function PxCarousel({ numberOfItemsVisible = 1, children, withAppleSeed =
|
|
|
33
34
|
gap: computedGap,
|
|
34
35
|
alignItems: 'stretch',
|
|
35
36
|
paddingLeft: computedGap,
|
|
36
|
-
}, horizontal: true,
|
|
37
|
+
}, horizontal: true, ...(snap && {
|
|
38
|
+
snapToOffsets: offsets,
|
|
39
|
+
decelerationRate: 'fast',
|
|
40
|
+
snapToAlignment: numberOfItemsVisible === 1 ? 'center' : 'start',
|
|
41
|
+
}), showsHorizontalScrollIndicator: false, ...(children?.length === 2 && {
|
|
37
42
|
onEndReached: () => {
|
|
38
43
|
setSelectedItemIndex(1);
|
|
39
44
|
},
|
|
@@ -41,6 +46,9 @@ export function PxCarousel({ numberOfItemsVisible = 1, children, withAppleSeed =
|
|
|
41
46
|
setSelectedItemIndex(0);
|
|
42
47
|
},
|
|
43
48
|
}), onViewableItemsChanged: (event) => {
|
|
49
|
+
if (!hasPreview) {
|
|
50
|
+
setSelectedItemIndex(event.viewableItems?.[0]?.index ?? 0);
|
|
51
|
+
}
|
|
44
52
|
// @ts-ignore
|
|
45
53
|
if (children?.length === 2) {
|
|
46
54
|
return;
|