@draftbit/core 49.7.6-e09d3d.2 → 49.7.7-ba2f6c.2
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/lib/commonjs/components/BottomSheet/BottomSheet.js +1 -1
- package/lib/commonjs/components/Swiper/Swiper.js +1 -1
- package/lib/typescript/src/components/BottomSheet/BottomSheet.d.ts +1 -0
- package/lib/typescript/src/components/BottomSheet/BottomSheet.js +8 -3
- package/lib/typescript/src/components/BottomSheet/BottomSheet.js.map +1 -1
- package/lib/typescript/src/components/Swiper/Swiper.d.ts +6 -1
- package/lib/typescript/src/components/Swiper/Swiper.js +17 -3
- package/lib/typescript/src/components/Swiper/Swiper.js.map +1 -1
- package/lib/typescript/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/components/BottomSheet/BottomSheet.js +8 -3
- package/src/components/BottomSheet/BottomSheet.js.map +1 -1
- package/src/components/BottomSheet/BottomSheet.tsx +10 -1
- package/src/components/Swiper/Swiper.js +17 -3
- package/src/components/Swiper/Swiper.js.map +1 -1
- package/src/components/Swiper/Swiper.tsx +134 -111
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@draftbit/core",
|
|
3
|
-
"version": "49.7.
|
|
3
|
+
"version": "49.7.7-ba2f6c.2+ba2f6c0",
|
|
4
4
|
"description": "Core (non-native) Components",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"types": "lib/typescript/src/index.d.ts",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@date-io/date-fns": "^1.3.13",
|
|
43
43
|
"@dotlottie/react-player": "1.6.1",
|
|
44
44
|
"@draftbit/react-theme-provider": "^2.1.1",
|
|
45
|
-
"@draftbit/theme": "^49.7.
|
|
45
|
+
"@draftbit/theme": "^49.7.7-ba2f6c.2+ba2f6c0",
|
|
46
46
|
"@expo/vector-icons": "^13.0.0",
|
|
47
47
|
"@gorhom/bottom-sheet": "5.0.0-alpha.7",
|
|
48
48
|
"@lottiefiles/react-lottie-player": "3.5.3",
|
|
@@ -120,5 +120,5 @@
|
|
|
120
120
|
],
|
|
121
121
|
"testEnvironment": "node"
|
|
122
122
|
},
|
|
123
|
-
"gitHead": "
|
|
123
|
+
"gitHead": "ba2f6c09749aac6bf01271ef53289e32024bae12"
|
|
124
124
|
}
|
|
@@ -7,7 +7,7 @@ const windowHeight = Dimensions.get("window").height;
|
|
|
7
7
|
// Clarification:
|
|
8
8
|
// Input of snap points is sorted top -> bottom where each value represents distance from top
|
|
9
9
|
// Implementation using `@gorhom/bottom-sheet` is sorted bottom -> top where each value represents distance from bottom
|
|
10
|
-
const BottomSheet = React.forwardRef(({ snapPoints: snapPointsProp, topSnapPosition = "10%", middleSnapPosition = "50%", bottomSnapPosition = "80%", initialSnapIndex, initialSnapPosition = "bottom", showHandle = true, handleColor, topBorderRadius = 20, borderWidth = 1, borderColor, onSettle, style, children, ...rest }, ref) => {
|
|
10
|
+
const BottomSheet = React.forwardRef(({ snapPoints: snapPointsProp, topSnapPosition = "10%", middleSnapPosition = "50%", bottomSnapPosition = "80%", initialSnapIndex, initialSnapPosition = "bottom", showHandle = true, handleColor, topBorderRadius = 20, borderWidth = 1, borderColor, enableDynamicSizing = true, onSettle, style, children, ...rest }, ref) => {
|
|
11
11
|
const theme = useTheme();
|
|
12
12
|
const backgroundColor = (style === null || style === void 0 ? void 0 : style.backgroundColor) || theme.colors.background.brand;
|
|
13
13
|
const snapPoints = snapPointsProp !== null && snapPointsProp !== void 0 ? snapPointsProp : [
|
|
@@ -26,7 +26,7 @@ const BottomSheet = React.forwardRef(({ snapPoints: snapPointsProp, topSnapPosit
|
|
|
26
26
|
return 2;
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
|
-
return (React.createElement(BottomSheetComponent, { ref: ref, snapPoints: mappedSnapPoints, index: initialSnapIndex !== undefined
|
|
29
|
+
return (React.createElement(BottomSheetComponent, { ref: ref, enableDynamicSizing: enableDynamicSizing, snapPoints: mappedSnapPoints, index: initialSnapIndex !== undefined
|
|
30
30
|
? mappedSnapPoints.length - initialSnapIndex - 1
|
|
31
31
|
: getSnapIndexFromPosition(initialSnapPosition), handleIndicatorStyle: [
|
|
32
32
|
{ backgroundColor: handleColor !== null && handleColor !== void 0 ? handleColor : theme.colors.border.brand },
|
|
@@ -37,7 +37,12 @@ const BottomSheet = React.forwardRef(({ snapPoints: snapPointsProp, topSnapPosit
|
|
|
37
37
|
borderTopRightRadius: topBorderRadius,
|
|
38
38
|
borderWidth,
|
|
39
39
|
borderColor: borderColor !== null && borderColor !== void 0 ? borderColor : theme.colors.border.brand,
|
|
40
|
-
}, onChange: (index) =>
|
|
40
|
+
}, onChange: (index) =>
|
|
41
|
+
// Convert bottom-sheet index to match our top-to-bottom ordering
|
|
42
|
+
// When dynamic sizing is enabled, we don't need to subtract 1 since an extra snap point may be added
|
|
43
|
+
enableDynamicSizing
|
|
44
|
+
? onSettle === null || onSettle === void 0 ? void 0 : onSettle(mappedSnapPoints.length - index)
|
|
45
|
+
: onSettle === null || onSettle === void 0 ? void 0 : onSettle(mappedSnapPoints.length - index - 1) },
|
|
41
46
|
React.createElement(BottomSheetScrollView, { contentContainerStyle: [styles.contentContainerStyle, style], ...rest }, children)));
|
|
42
47
|
});
|
|
43
48
|
// @gorhom/bottom-sheet has a different format for snap points and requires some manipulation
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BottomSheet.js","sourceRoot":"","sources":["BottomSheet.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,UAAU,EAIV,UAAU,GACX,MAAM,cAAc,CAAC;AAEtB,OAAO,oBAAoB,EAAE,EAC3B,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE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,GAAG,KAAK,CAAC;YAC7C,CAAC,CAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAG,gBAAgB,CAAC,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC;QAGrD,oBAAC,qBAAqB,IACpB,qBAAqB,EAAE,CAAC,MAAM,CAAC,qBAAqB,EAAE,KAAK,CAAC,KACxD,IAAI,IAEP,QAAQ,CACa,CACH,CACxB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,6FAA6F;AAC7F,SAAS,qCAAqC,CAC5C,UAA+B;IAE/B,qGAAqG;IACrG,MAAM,kBAAkB,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC;IAErD,oHAAoH;IACpH,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACtC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,MAAM,aAAa,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;YAClD,IAAI,aAAa,KAAK,SAAS,EAAE;gBAC/B,OAAO,GAAG,GAAG,GAAG,aAAa,GAAG,CAAC;aAClC;YACD,OAAO,KAAK,CAAC;SACd;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YACpC,OAAO,YAAY,GAAG,KAAK,CAAC;SAC7B;aAAM;YACL,OAAO,KAAK,CAAC;SACd;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,qBAAqB,EAAE;QACrB,iBAAiB,EAAE,EAAE;QACrB,eAAe,EAAE,EAAE;KACpB;CACF,CAAC,CAAC;AAEH,eAAe,WAAW,CAAC"}
|
|
@@ -35,6 +35,7 @@ export interface BottomSheetProps extends ScrollViewProps {
|
|
|
35
35
|
topBorderRadius?: number;
|
|
36
36
|
borderWidth?: number;
|
|
37
37
|
borderColor?: string;
|
|
38
|
+
enableDynamicSizing?: boolean;
|
|
38
39
|
onSettle?: (index: number) => void;
|
|
39
40
|
style?: StyleProp<ViewStyle>;
|
|
40
41
|
}
|
|
@@ -56,6 +57,7 @@ const BottomSheet = React.forwardRef<BottomSheetComponent, BottomSheetProps>(
|
|
|
56
57
|
topBorderRadius = 20,
|
|
57
58
|
borderWidth = 1,
|
|
58
59
|
borderColor,
|
|
60
|
+
enableDynamicSizing = true,
|
|
59
61
|
onSettle,
|
|
60
62
|
style,
|
|
61
63
|
children,
|
|
@@ -92,6 +94,7 @@ const BottomSheet = React.forwardRef<BottomSheetComponent, BottomSheetProps>(
|
|
|
92
94
|
return (
|
|
93
95
|
<BottomSheetComponent
|
|
94
96
|
ref={ref}
|
|
97
|
+
enableDynamicSizing={enableDynamicSizing}
|
|
95
98
|
snapPoints={mappedSnapPoints}
|
|
96
99
|
index={
|
|
97
100
|
initialSnapIndex !== undefined
|
|
@@ -109,7 +112,13 @@ const BottomSheet = React.forwardRef<BottomSheetComponent, BottomSheetProps>(
|
|
|
109
112
|
borderWidth,
|
|
110
113
|
borderColor: borderColor ?? theme.colors.border.brand,
|
|
111
114
|
}}
|
|
112
|
-
onChange={(index) =>
|
|
115
|
+
onChange={(index) =>
|
|
116
|
+
// Convert bottom-sheet index to match our top-to-bottom ordering
|
|
117
|
+
// When dynamic sizing is enabled, we don't need to subtract 1 since an extra snap point may be added
|
|
118
|
+
enableDynamicSizing
|
|
119
|
+
? onSettle?.(mappedSnapPoints.length - index)
|
|
120
|
+
: onSettle?.(mappedSnapPoints.length - index - 1)
|
|
121
|
+
}
|
|
113
122
|
>
|
|
114
123
|
<BottomSheetScrollView
|
|
115
124
|
contentContainerStyle={[styles.contentContainerStyle, style]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { withTheme } from "@draftbit/theme";
|
|
2
|
-
import React from "react";
|
|
2
|
+
import React, { forwardRef, useImperativeHandle } from "react";
|
|
3
3
|
import { View } from "react-native";
|
|
4
4
|
import SwiperComponent from "react-native-web-swiper";
|
|
5
|
-
const Swiper = ({ theme, vertical = false, loop = false, timeout = 0, from = 0, prevTitle = "", nextTitle = "", prevTitleColor, nextTitleColor, dotsTouchable = true, dotColor = theme.colors.foreground.brand, dotActiveColor = theme.colors.branding.primary, data, keyExtractor, renderItem, children: childrenProp, onIndexChanged: onIndexChangedProp, onSwipe, onSwipedNext, onSwipedPrevious, minDistanceForAction, minDistanceToCapture, style, }) => {
|
|
5
|
+
const Swiper = forwardRef(({ theme, vertical = false, loop = false, timeout = 0, from = 0, prevTitle = "", nextTitle = "", prevTitleColor, nextTitleColor, dotsTouchable = true, dotColor = theme === null || theme === void 0 ? void 0 : theme.colors.foreground.brand, dotActiveColor = theme === null || theme === void 0 ? void 0 : theme.colors.branding.primary, data, keyExtractor, renderItem, children: childrenProp, onIndexChanged: onIndexChangedProp, onSwipe, onSwipedNext, onSwipedPrevious, minDistanceForAction, minDistanceToCapture, style, }, ref) => {
|
|
6
6
|
var _a;
|
|
7
7
|
const [currentIndex, setCurrentIndex] = React.useState(0);
|
|
8
8
|
const numberOfItems = (_a = data === null || data === void 0 ? void 0 : data.length) !== null && _a !== void 0 ? _a : React.Children.count(childrenProp);
|
|
@@ -56,6 +56,20 @@ const Swiper = ({ theme, vertical = false, loop = false, timeout = 0, from = 0,
|
|
|
56
56
|
swiperRef.current.forceUpdate();
|
|
57
57
|
}
|
|
58
58
|
}, [children]);
|
|
59
|
+
useImperativeHandle(ref, () => ({
|
|
60
|
+
swipeTo: (index) => {
|
|
61
|
+
var _a;
|
|
62
|
+
(_a = swiperRef.current) === null || _a === void 0 ? void 0 : _a.goTo(index);
|
|
63
|
+
},
|
|
64
|
+
swipeNext: () => {
|
|
65
|
+
var _a;
|
|
66
|
+
(_a = swiperRef.current) === null || _a === void 0 ? void 0 : _a.goToNext();
|
|
67
|
+
},
|
|
68
|
+
swipePrev: () => {
|
|
69
|
+
var _a;
|
|
70
|
+
(_a = swiperRef.current) === null || _a === void 0 ? void 0 : _a.goToPrev();
|
|
71
|
+
},
|
|
72
|
+
}));
|
|
59
73
|
return (React.createElement(View, { style: style },
|
|
60
74
|
React.createElement(SwiperComponent, { ref: swiperRef, from: from, loop: loop, timeout: timeout, vertical: vertical, onIndexChanged: onIndexChanged, minDistanceForAction: minDistanceForAction, minDistanceToCapture: minDistanceToCapture, controlsProps: {
|
|
61
75
|
prevTitle,
|
|
@@ -70,6 +84,6 @@ const Swiper = ({ theme, vertical = false, loop = false, timeout = 0, from = 0,
|
|
|
70
84
|
? { dotActiveStyle: { backgroundColor: dotActiveColor } }
|
|
71
85
|
: {}),
|
|
72
86
|
} }, children)));
|
|
73
|
-
};
|
|
87
|
+
});
|
|
74
88
|
export default withTheme(Swiper);
|
|
75
89
|
//# sourceMappingURL=Swiper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Swiper.js","sourceRoot":"","sources":["Swiper.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Swiper.js","sourceRoot":"","sources":["Swiper.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAwB,MAAM,cAAc,CAAC;AAC1D,OAAO,eAAe,MAAM,yBAAyB,CAAC;AAkCtD,MAAM,MAAM,GAAG,UAAU,CACvB,CACE,EACE,KAAK,EACL,QAAQ,GAAG,KAAK,EAChB,IAAI,GAAG,KAAK,EACZ,OAAO,GAAG,CAAC,EACX,IAAI,GAAG,CAAC,EACR,SAAS,GAAG,EAAE,EACd,SAAS,GAAG,EAAE,EACd,cAAc,EACd,cAAc,EACd,aAAa,GAAG,IAAI,EACpB,QAAQ,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAAM,CAAC,UAAU,CAA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ACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,SAAS,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { ReadTheme, withTheme } from "@draftbit/theme";
|
|
2
|
-
import React from "react";
|
|
2
|
+
import React, { forwardRef, useImperativeHandle } from "react";
|
|
3
3
|
import { View, StyleProp, ViewStyle } from "react-native";
|
|
4
4
|
import SwiperComponent from "react-native-web-swiper";
|
|
5
5
|
|
|
6
|
+
export interface SwiperRef {
|
|
7
|
+
swipeTo: (index: number) => void;
|
|
8
|
+
swipeNext: () => void;
|
|
9
|
+
swipePrev: () => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
6
12
|
export interface SwiperProps<T> {
|
|
7
13
|
onSwipe?: (index: number) => void;
|
|
8
14
|
onSwipedNext?: (index: number) => void;
|
|
@@ -29,123 +35,140 @@ export interface SwiperProps<T> {
|
|
|
29
35
|
theme: ReadTheme;
|
|
30
36
|
}
|
|
31
37
|
|
|
32
|
-
const Swiper = (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
const
|
|
38
|
+
const Swiper = forwardRef<SwiperRef, SwiperProps<any>>(
|
|
39
|
+
(
|
|
40
|
+
{
|
|
41
|
+
theme,
|
|
42
|
+
vertical = false,
|
|
43
|
+
loop = false,
|
|
44
|
+
timeout = 0,
|
|
45
|
+
from = 0,
|
|
46
|
+
prevTitle = "",
|
|
47
|
+
nextTitle = "",
|
|
48
|
+
prevTitleColor,
|
|
49
|
+
nextTitleColor,
|
|
50
|
+
dotsTouchable = true,
|
|
51
|
+
dotColor = theme?.colors.foreground.brand,
|
|
52
|
+
dotActiveColor = theme?.colors.branding.primary,
|
|
53
|
+
data,
|
|
54
|
+
keyExtractor,
|
|
55
|
+
renderItem,
|
|
56
|
+
children: childrenProp,
|
|
57
|
+
onIndexChanged: onIndexChangedProp,
|
|
58
|
+
onSwipe,
|
|
59
|
+
onSwipedNext,
|
|
60
|
+
onSwipedPrevious,
|
|
61
|
+
minDistanceForAction,
|
|
62
|
+
minDistanceToCapture,
|
|
63
|
+
style,
|
|
64
|
+
}: SwiperProps<any>,
|
|
65
|
+
ref
|
|
66
|
+
) => {
|
|
67
|
+
const [currentIndex, setCurrentIndex] = React.useState(0);
|
|
68
|
+
const numberOfItems = data?.length ?? React.Children.count(childrenProp);
|
|
69
|
+
const swiperRef = React.useRef<any>(null);
|
|
64
70
|
|
|
65
|
-
|
|
66
|
-
|
|
71
|
+
const onIndexChanged = (index: number) => {
|
|
72
|
+
const previous = currentIndex;
|
|
73
|
+
const current = index;
|
|
67
74
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
onSwipedNext?.(previous);
|
|
71
|
-
} else if (previous === 0 && current === numberOfItems - 1) {
|
|
72
|
-
//First -> last swipe
|
|
73
|
-
onSwipedPrevious?.(previous);
|
|
74
|
-
} else if (current > previous) {
|
|
75
|
-
onSwipedNext?.(previous);
|
|
76
|
-
} else if (current < previous) {
|
|
77
|
-
onSwipedPrevious?.(previous);
|
|
78
|
-
}
|
|
79
|
-
onSwipe?.(previous);
|
|
80
|
-
};
|
|
75
|
+
onIndexChangedProp?.(index);
|
|
76
|
+
setCurrentIndex(index);
|
|
81
77
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
78
|
+
if (previous === numberOfItems - 1 && current === 0) {
|
|
79
|
+
//Last -> first swipe
|
|
80
|
+
onSwipedNext?.(previous);
|
|
81
|
+
} else if (previous === 0 && current === numberOfItems - 1) {
|
|
82
|
+
//First -> last swipe
|
|
83
|
+
onSwipedPrevious?.(previous);
|
|
84
|
+
} else if (current > previous) {
|
|
85
|
+
onSwipedNext?.(previous);
|
|
86
|
+
} else if (current < previous) {
|
|
87
|
+
onSwipedPrevious?.(previous);
|
|
88
|
+
}
|
|
89
|
+
onSwipe?.(previous);
|
|
90
|
+
};
|
|
87
91
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
92
|
+
const children: React.ReactNode = React.useMemo(
|
|
93
|
+
() =>
|
|
94
|
+
Array.isArray(data) && renderItem
|
|
95
|
+
? data.map((item, index) => {
|
|
96
|
+
const component = renderItem({ item, index });
|
|
91
97
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
});
|
|
96
|
-
})
|
|
97
|
-
: childrenProp,
|
|
98
|
-
[childrenProp, data, renderItem, keyExtractor]
|
|
99
|
-
);
|
|
98
|
+
if (!component) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
React.useEffect(() => {
|
|
109
|
-
const childrenArray = React.Children.toArray(
|
|
110
|
-
swiperRef.current?.props?.children
|
|
102
|
+
const key = keyExtractor ? keyExtractor(item, index) : index;
|
|
103
|
+
return React.cloneElement(component, {
|
|
104
|
+
key,
|
|
105
|
+
});
|
|
106
|
+
})
|
|
107
|
+
: childrenProp,
|
|
108
|
+
[childrenProp, data, renderItem, keyExtractor]
|
|
111
109
|
);
|
|
112
|
-
if (swiperRef.current) {
|
|
113
|
-
swiperRef.current.children = childrenArray;
|
|
114
|
-
swiperRef.current.count = childrenArray.length;
|
|
115
|
-
swiperRef.current.forceUpdate();
|
|
116
|
-
}
|
|
117
|
-
}, [children]);
|
|
118
110
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
111
|
+
/*
|
|
112
|
+
react-native-web-swiper assigns it's 'children' attribute as follows: `children = (() => React.Children.toArray(this.props.children))();`
|
|
113
|
+
This is probelematic when state is involved due to anoynmous function effectivley creating new components everytime, losing any state
|
|
114
|
+
|
|
115
|
+
This is a monkey patch that updates the 'children' attribute to just use the children from the props
|
|
116
|
+
Can be removed when/if https://github.com/reactrondev/react-native-web-swiper/pull/102 is merged
|
|
117
|
+
*/
|
|
118
|
+
React.useEffect(() => {
|
|
119
|
+
const childrenArray = React.Children.toArray(
|
|
120
|
+
swiperRef.current?.props?.children
|
|
121
|
+
);
|
|
122
|
+
if (swiperRef.current) {
|
|
123
|
+
swiperRef.current.children = childrenArray;
|
|
124
|
+
swiperRef.current.count = childrenArray.length;
|
|
125
|
+
swiperRef.current.forceUpdate();
|
|
126
|
+
}
|
|
127
|
+
}, [children]);
|
|
128
|
+
|
|
129
|
+
useImperativeHandle(ref, () => ({
|
|
130
|
+
swipeTo: (index: number) => {
|
|
131
|
+
swiperRef.current?.goTo(index);
|
|
132
|
+
},
|
|
133
|
+
swipeNext: () => {
|
|
134
|
+
swiperRef.current?.goToNext();
|
|
135
|
+
},
|
|
136
|
+
swipePrev: () => {
|
|
137
|
+
swiperRef.current?.goToPrev();
|
|
138
|
+
},
|
|
139
|
+
}));
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<View style={style}>
|
|
143
|
+
{/* @ts-ignore */}
|
|
144
|
+
<SwiperComponent
|
|
145
|
+
ref={swiperRef}
|
|
146
|
+
from={from}
|
|
147
|
+
loop={loop}
|
|
148
|
+
timeout={timeout}
|
|
149
|
+
vertical={vertical}
|
|
150
|
+
onIndexChanged={onIndexChanged}
|
|
151
|
+
minDistanceForAction={minDistanceForAction}
|
|
152
|
+
minDistanceToCapture={minDistanceToCapture}
|
|
153
|
+
controlsProps={{
|
|
154
|
+
prevTitle,
|
|
155
|
+
nextTitle,
|
|
156
|
+
prevTitleStyle: { color: prevTitleColor },
|
|
157
|
+
nextTitleStyle: { color: nextTitleColor },
|
|
158
|
+
dotsTouchable,
|
|
159
|
+
...(dotColor
|
|
160
|
+
? { dotProps: { badgeStyle: { backgroundColor: dotColor } } }
|
|
161
|
+
: {}),
|
|
162
|
+
...(dotActiveColor
|
|
163
|
+
? { dotActiveStyle: { backgroundColor: dotActiveColor } }
|
|
164
|
+
: {}),
|
|
165
|
+
}}
|
|
166
|
+
>
|
|
167
|
+
{children}
|
|
168
|
+
</SwiperComponent>
|
|
169
|
+
</View>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
);
|
|
150
173
|
|
|
151
174
|
export default withTheme(Swiper);
|