@proximus/lavender-carousel-native 0.1.0-alpha.4 → 0.1.0-beta.0
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 +54 -12
- package/package.json +5 -33
- package/CHANGELOG.md +0 -20
- package/dist/far/away/package.json +0 -32
- package/src/AppleSeed.tsx +0 -113
- package/src/Carousel.tsx +0 -108
- package/src/index.ts +0 -2
- package/tsconfig.json +0 -8
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,42 +4,84 @@ 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,
|
|
37
|
-
|
|
38
|
-
|
|
49
|
+
}, horizontal: true, ...(snap && {
|
|
50
|
+
snapToOffsets: offsets,
|
|
51
|
+
decelerationRate: 'fast',
|
|
52
|
+
snapToAlignment: numberOfItemsVisible === 1 ? 'center' : 'start',
|
|
53
|
+
}), showsHorizontalScrollIndicator: false, ...(data.length === 2 && {
|
|
54
|
+
onEndReached: () => {
|
|
55
|
+
onItemDisplayed?.(1);
|
|
56
|
+
setSelectedItemIndex(1);
|
|
57
|
+
},
|
|
58
|
+
onStartReached: () => {
|
|
59
|
+
onItemDisplayed?.(0);
|
|
60
|
+
setSelectedItemIndex(0);
|
|
61
|
+
},
|
|
62
|
+
}), onViewableItemsChanged: (event) => {
|
|
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) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (event.viewableItems.length === 2 && firstViewableIndex === 0) {
|
|
73
|
+
onItemDisplayed?.(0);
|
|
39
74
|
setSelectedItemIndex(0);
|
|
40
75
|
return;
|
|
41
76
|
}
|
|
77
|
+
// when keeping swiping left on ios on the last element,
|
|
78
|
+
// viewableItems contains only one element so we ignore that case
|
|
79
|
+
// because vent.viewableItems?.[1] is out of bounds
|
|
80
|
+
if (event.viewableItems.length === 1) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
onItemDisplayed?.(firstViewableIndex);
|
|
42
84
|
setSelectedItemIndex(event.viewableItems?.[1]?.index ?? 0);
|
|
43
85
|
} }),
|
|
44
|
-
withAppleSeed && elementsCount > 1 && (React.createElement(PxAppleSeed, { numberOfItems:
|
|
86
|
+
withAppleSeed && elementsCount > 1 && (React.createElement(PxAppleSeed, { numberOfItems: data.length, selectedItemIndex: selectedItemIndex }))));
|
|
45
87
|
}
|
package/package.json
CHANGED
|
@@ -1,42 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@proximus/lavender-carousel-native",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
4
|
"description": "Carousel component",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"main": "
|
|
7
|
-
"scripts": {
|
|
8
|
-
"clean": "rm -rf dist",
|
|
9
|
-
"transform-package-json": "node ../../../scripts/tranformPackageJson.js package.json dist/far/away",
|
|
10
|
-
"prepublish": "yarn clean && yarn transform-package-json && yarn build",
|
|
11
|
-
"build": "npx tsc -p tsconfig.json"
|
|
12
|
-
},
|
|
6
|
+
"main": "dist/index.js",
|
|
13
7
|
"peerDependencies": {
|
|
14
|
-
"@proximus/lavender-common-native": "
|
|
15
|
-
"@proximus/lavender-styling-native": "
|
|
16
|
-
},
|
|
17
|
-
"devDependencies": {
|
|
18
|
-
"@proximus/lavender-common-native": "0.1.0-alpha.6",
|
|
19
|
-
"@proximus/lavender-styling-native": "0.1.0-alpha.5"
|
|
8
|
+
"@proximus/lavender-common-native": "*",
|
|
9
|
+
"@proximus/lavender-styling-native": "*"
|
|
20
10
|
},
|
|
21
11
|
"publishConfig": {
|
|
22
12
|
"access": "public"
|
|
23
|
-
}
|
|
24
|
-
"lerna": {
|
|
25
|
-
"command": {
|
|
26
|
-
"publish": {
|
|
27
|
-
"assets": [
|
|
28
|
-
{
|
|
29
|
-
"from": "dist/far/away/package.json",
|
|
30
|
-
"to": "."
|
|
31
|
-
},
|
|
32
|
-
"dist/*.js",
|
|
33
|
-
"dist/*.d.ts",
|
|
34
|
-
"dist/*.d.ts.map",
|
|
35
|
-
"src",
|
|
36
|
-
"package.json"
|
|
37
|
-
]
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
"gitHead": "a1feec25c51a94781f121bd6daba378d09021174"
|
|
13
|
+
}
|
|
42
14
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
# [0.1.0-alpha.4](https://github.com/Pxs-Corporate/react-native-lavender/compare/@proximus/lavender-carousel-native@0.1.0-alpha.3...@proximus/lavender-carousel-native@0.1.0-alpha.4) (2025-09-26)
|
|
7
|
-
|
|
8
|
-
### Features
|
|
9
|
-
|
|
10
|
-
- **BCRI-000000:** datasource based mendix carousel ([#35](https://github.com/Pxs-Corporate/react-native-lavender/issues/35)) ([c627206](https://github.com/Pxs-Corporate/react-native-lavender/commit/c6272061736ee196d2c2dcea0d239e8819e0489b))
|
|
11
|
-
|
|
12
|
-
# [0.1.0-alpha.3](https://github.com/Pxs-Corporate/react-native-lavender/compare/@proximus/lavender-carousel-native@0.1.0-alpha.2...@proximus/lavender-carousel-native@0.1.0-alpha.3) (2025-09-26)
|
|
13
|
-
|
|
14
|
-
**Note:** Version bump only for package @proximus/lavender-carousel-native
|
|
15
|
-
|
|
16
|
-
# 0.1.0-alpha.2 (2025-09-25)
|
|
17
|
-
|
|
18
|
-
### Bug Fixes
|
|
19
|
-
|
|
20
|
-
- **BCRI-000000:** no free space on gh runner during build ([#27](https://github.com/Pxs-Corporate/react-native-lavender/issues/27)) ([a7c8604](https://github.com/Pxs-Corporate/react-native-lavender/commit/a7c86043b5cefcb10fd768d449c5718fbabe87ec))
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@proximus/lavender-carousel-native",
|
|
3
|
-
"version": "0.1.0-alpha.4",
|
|
4
|
-
"description": "Carousel component",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"peerDependencies": {
|
|
8
|
-
"@proximus/lavender-common-native": "*",
|
|
9
|
-
"@proximus/lavender-styling-native": "*"
|
|
10
|
-
},
|
|
11
|
-
"publishConfig": {
|
|
12
|
-
"access": "public"
|
|
13
|
-
},
|
|
14
|
-
"lerna": {
|
|
15
|
-
"command": {
|
|
16
|
-
"publish": {
|
|
17
|
-
"assets": [
|
|
18
|
-
{
|
|
19
|
-
"from": "dist/far/away/package.json",
|
|
20
|
-
"to": "."
|
|
21
|
-
},
|
|
22
|
-
"dist/*.js",
|
|
23
|
-
"dist/*.d.ts",
|
|
24
|
-
"dist/*.d.ts.map",
|
|
25
|
-
"src",
|
|
26
|
-
"package.json"
|
|
27
|
-
]
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
"gitHead": "a1feec25c51a94781f121bd6daba378d09021174"
|
|
32
|
-
}
|
package/src/AppleSeed.tsx
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from 'react';
|
|
2
|
-
import { Animated, View } from 'react-native';
|
|
3
|
-
import { useTheme } from '@proximus/lavender-styling-native';
|
|
4
|
-
|
|
5
|
-
const appleSeedSizeL = 14;
|
|
6
|
-
const appleSeedSizeM = 10;
|
|
7
|
-
const appleSeedSizeS = 6;
|
|
8
|
-
const appleSeedSizeXS = 4;
|
|
9
|
-
|
|
10
|
-
export function PxAppleSeed({
|
|
11
|
-
numberOfItems,
|
|
12
|
-
selectedItemIndex,
|
|
13
|
-
}: {
|
|
14
|
-
numberOfItems: number;
|
|
15
|
-
selectedItemIndex: number;
|
|
16
|
-
}) {
|
|
17
|
-
const { theme } = useTheme();
|
|
18
|
-
const tx = useRef(new Animated.Value(0)).current;
|
|
19
|
-
const prevSelectedItemIndex = useRef(selectedItemIndex);
|
|
20
|
-
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
if (
|
|
23
|
-
(selectedItemIndex <= 2 && prevSelectedItemIndex.current != 3) ||
|
|
24
|
-
numberOfItems - selectedItemIndex < 3
|
|
25
|
-
) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const translateLeft =
|
|
30
|
-
selectedItemIndex > prevSelectedItemIndex.current ? -1 : 1;
|
|
31
|
-
|
|
32
|
-
const toValue = translateLeft
|
|
33
|
-
? -1 * (selectedItemIndex - 2) * theme.t('SizeIconS').number
|
|
34
|
-
: (selectedItemIndex - 3) * theme.t('SizeIconS').number;
|
|
35
|
-
|
|
36
|
-
Animated.spring(tx, {
|
|
37
|
-
toValue,
|
|
38
|
-
useNativeDriver: true,
|
|
39
|
-
}).start();
|
|
40
|
-
|
|
41
|
-
prevSelectedItemIndex.current = selectedItemIndex;
|
|
42
|
-
}, [numberOfItems, selectedItemIndex, theme, tx]);
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<View
|
|
46
|
-
style={{
|
|
47
|
-
flexDirection: 'row',
|
|
48
|
-
width: 5 * theme.t('SizeIconS').number,
|
|
49
|
-
justifyContent: numberOfItems < 5 ? 'center' : 'flex-start',
|
|
50
|
-
alignSelf: 'center',
|
|
51
|
-
overflow: 'hidden',
|
|
52
|
-
alignItems: 'center',
|
|
53
|
-
}}
|
|
54
|
-
>
|
|
55
|
-
{Array.from({ length: numberOfItems }).map((_, index) => (
|
|
56
|
-
<Animated.View
|
|
57
|
-
key={index}
|
|
58
|
-
style={{
|
|
59
|
-
width: theme.t('SizeIconS').number,
|
|
60
|
-
height: theme.t('SizeIconS').number,
|
|
61
|
-
alignItems: 'center',
|
|
62
|
-
justifyContent: 'center',
|
|
63
|
-
transform: [
|
|
64
|
-
{
|
|
65
|
-
translateX: tx,
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
}}
|
|
69
|
-
>
|
|
70
|
-
<View
|
|
71
|
-
key={index}
|
|
72
|
-
style={{
|
|
73
|
-
borderWidth: theme.t('SizeBorderS').number,
|
|
74
|
-
height: numberOfItems > 5 ? appleSeedSizeXS : appleSeedSizeM,
|
|
75
|
-
width: numberOfItems > 5 ? appleSeedSizeXS : appleSeedSizeM,
|
|
76
|
-
borderRadius: theme.t('RadiusMain').number,
|
|
77
|
-
borderColor: theme.t('ColorBackgroundStateActiveDefault'),
|
|
78
|
-
...(index === numberOfItems - 2 &&
|
|
79
|
-
numberOfItems > 6 && {
|
|
80
|
-
height: appleSeedSizeM,
|
|
81
|
-
width: appleSeedSizeM,
|
|
82
|
-
}),
|
|
83
|
-
...(index === numberOfItems - 3 &&
|
|
84
|
-
numberOfItems > 5 && {
|
|
85
|
-
height: appleSeedSizeS,
|
|
86
|
-
width: appleSeedSizeS,
|
|
87
|
-
}),
|
|
88
|
-
...((index === selectedItemIndex - 2 ||
|
|
89
|
-
index === selectedItemIndex + 2) &&
|
|
90
|
-
numberOfItems > 5 && {
|
|
91
|
-
height: appleSeedSizeS,
|
|
92
|
-
width: appleSeedSizeS,
|
|
93
|
-
}),
|
|
94
|
-
...((index === selectedItemIndex - 1 ||
|
|
95
|
-
index === selectedItemIndex + 1) &&
|
|
96
|
-
numberOfItems > 5 && {
|
|
97
|
-
height: appleSeedSizeM,
|
|
98
|
-
width: appleSeedSizeM,
|
|
99
|
-
}),
|
|
100
|
-
...(index === selectedItemIndex && {
|
|
101
|
-
backgroundColor: theme.t('ColorBackgroundStateActiveDefault'),
|
|
102
|
-
...(numberOfItems > 5 && {
|
|
103
|
-
height: appleSeedSizeL,
|
|
104
|
-
width: appleSeedSizeL,
|
|
105
|
-
}),
|
|
106
|
-
}),
|
|
107
|
-
}}
|
|
108
|
-
/>
|
|
109
|
-
</Animated.View>
|
|
110
|
-
))}
|
|
111
|
-
</View>
|
|
112
|
-
);
|
|
113
|
-
}
|
package/src/Carousel.tsx
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
AccessibilityProps,
|
|
4
|
-
Dimensions,
|
|
5
|
-
FlatList,
|
|
6
|
-
StyleProp,
|
|
7
|
-
View,
|
|
8
|
-
ViewStyle,
|
|
9
|
-
} from 'react-native';
|
|
10
|
-
import { useTheme } from '@proximus/lavender-styling-native';
|
|
11
|
-
import { PxAppleSeed } from './AppleSeed';
|
|
12
|
-
import { a11y, e2eID } from '@proximus/lavender-common-native';
|
|
13
|
-
|
|
14
|
-
const inset = 24;
|
|
15
|
-
|
|
16
|
-
export function PxCarousel({
|
|
17
|
-
numberOfItemsVisible = 1,
|
|
18
|
-
children,
|
|
19
|
-
withAppleSeed = true,
|
|
20
|
-
containerStyle,
|
|
21
|
-
testID,
|
|
22
|
-
accessibilityProps,
|
|
23
|
-
}: {
|
|
24
|
-
numberOfItemsVisible?: number;
|
|
25
|
-
children?: React.ReactNode;
|
|
26
|
-
withAppleSeed?: boolean;
|
|
27
|
-
containerStyle?: StyleProp<ViewStyle>;
|
|
28
|
-
testID?: string;
|
|
29
|
-
accessibilityProps?: AccessibilityProps;
|
|
30
|
-
}) {
|
|
31
|
-
const [width, setWidth] = useState(0);
|
|
32
|
-
const [computedGap, setComputedGap] = useState(0);
|
|
33
|
-
const [elementsCount, setElementsCount] = useState(0);
|
|
34
|
-
const [selectedItemIndex, setSelectedItemIndex] = useState(0);
|
|
35
|
-
const [offsets, setOffsets] = useState([]);
|
|
36
|
-
const { theme } = useTheme();
|
|
37
|
-
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
setWidth(
|
|
40
|
-
(Dimensions.get('window').width -
|
|
41
|
-
numberOfItemsVisible * computedGap -
|
|
42
|
-
2 * inset) /
|
|
43
|
-
numberOfItemsVisible
|
|
44
|
-
);
|
|
45
|
-
}, [numberOfItemsVisible, computedGap, theme]);
|
|
46
|
-
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
setElementsCount(React.Children.count(children));
|
|
49
|
-
}, [children]);
|
|
50
|
-
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
setComputedGap(theme.t(`SpacingSMobile`).number);
|
|
53
|
-
}, [theme]);
|
|
54
|
-
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
setOffsets(
|
|
57
|
-
new Array(elementsCount).fill(0).reduce(
|
|
58
|
-
(prev, _, i) => {
|
|
59
|
-
return [...prev, prev[i] + width + computedGap];
|
|
60
|
-
},
|
|
61
|
-
[width]
|
|
62
|
-
)
|
|
63
|
-
);
|
|
64
|
-
}, [computedGap, elementsCount, width]);
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<View
|
|
68
|
-
style={[containerStyle, { flexDirection: 'column', gap: 27.15, flex: 1 }]}
|
|
69
|
-
{...e2eID(testID)}
|
|
70
|
-
{...a11y(accessibilityProps)}
|
|
71
|
-
>
|
|
72
|
-
<FlatList
|
|
73
|
-
data={new Array(React.Children.count(children)).fill(0)}
|
|
74
|
-
renderItem={({ index }) => (
|
|
75
|
-
<View style={{ width }}>
|
|
76
|
-
{[...(children as Iterable<any>)]?.[index]}
|
|
77
|
-
</View>
|
|
78
|
-
)}
|
|
79
|
-
contentContainerStyle={{
|
|
80
|
-
gap: computedGap,
|
|
81
|
-
alignItems: 'stretch',
|
|
82
|
-
paddingLeft: computedGap,
|
|
83
|
-
}}
|
|
84
|
-
horizontal
|
|
85
|
-
snapToOffsets={offsets}
|
|
86
|
-
decelerationRate="fast"
|
|
87
|
-
snapToAlignment={numberOfItemsVisible === 1 ? 'center' : 'start'}
|
|
88
|
-
showsHorizontalScrollIndicator={false}
|
|
89
|
-
onViewableItemsChanged={(event) => {
|
|
90
|
-
if (
|
|
91
|
-
event.viewableItems.length === 2 &&
|
|
92
|
-
event.viewableItems?.[0]?.index === 0
|
|
93
|
-
) {
|
|
94
|
-
setSelectedItemIndex(0);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
setSelectedItemIndex(event.viewableItems?.[1]?.index ?? 0);
|
|
98
|
-
}}
|
|
99
|
-
/>
|
|
100
|
-
{withAppleSeed && elementsCount > 1 && (
|
|
101
|
-
<PxAppleSeed
|
|
102
|
-
numberOfItems={React.Children.count(children)}
|
|
103
|
-
selectedItemIndex={selectedItemIndex}
|
|
104
|
-
/>
|
|
105
|
-
)}
|
|
106
|
-
</View>
|
|
107
|
-
);
|
|
108
|
-
}
|
package/src/index.ts
DELETED