Skip to content

Commit 8b62dca

Browse files
committed
fix: added error message when dynamic sizing enabled with a wrong children type
1 parent 6efd8ae commit 8b62dca

8 files changed

+47
-10
lines changed

src/components/bottomSheet/BottomSheet.tsx

+11-7
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,17 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
168168
//#endregion
169169

170170
//#region validate props
171-
usePropsValidator({
172-
index: _providedIndex,
173-
snapPoints: _providedSnapPoints,
174-
enableDynamicSizing,
175-
topInset,
176-
bottomInset,
177-
});
171+
if (__DEV__) {
172+
// eslint-disable-next-line react-hooks/rules-of-hooks
173+
usePropsValidator({
174+
index: _providedIndex,
175+
snapPoints: _providedSnapPoints,
176+
enableDynamicSizing,
177+
topInset,
178+
bottomInset,
179+
children,
180+
});
181+
}
178182
//#endregion
179183

180184
//#region layout variables

src/components/bottomSheetScrollable/BottomSheetFlatList.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const BottomSheetFlatListComponent = createBottomSheetScrollableComponent<
2121

2222
const BottomSheetFlatList = memo(BottomSheetFlatListComponent);
2323
BottomSheetFlatList.displayName = 'BottomSheetFlatList';
24+
//@ts-ignore
25+
BottomSheetFlatList.$bottomSheetIntegrated = true;
2426

2527
export default BottomSheetFlatList as <T>(
2628
props: BottomSheetFlatListProps<T>

src/components/bottomSheetScrollable/BottomSheetScrollView.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const BottomSheetScrollViewComponent = createBottomSheetScrollableComponent<
2121

2222
const BottomSheetScrollView = memo(BottomSheetScrollViewComponent);
2323
BottomSheetScrollView.displayName = 'BottomSheetScrollView';
24+
//@ts-ignore
25+
BottomSheetScrollView.$bottomSheetIntegrated = true;
2426

2527
export default BottomSheetScrollView as (
2628
props: BottomSheetScrollViewProps

src/components/bottomSheetScrollable/BottomSheetSectionList.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const BottomSheetSectionListComponent = createBottomSheetScrollableComponent<
2222

2323
const BottomSheetSectionList = memo(BottomSheetSectionListComponent);
2424
BottomSheetSectionList.displayName = 'BottomSheetSectionList';
25+
//@ts-ignore
26+
BottomSheetSectionList.$bottomSheetIntegrated = true;
2527

2628
export default BottomSheetSectionList as <ItemT, SectionT = DefaultSectionT>(
2729
props: BottomSheetSectionListProps<ItemT, SectionT>

src/components/bottomSheetScrollable/BottomSheetVirtualizedList.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const BottomSheetVirtualizedListComponent =
2424

2525
const BottomSheetVirtualizedList = memo(BottomSheetVirtualizedListComponent);
2626
BottomSheetVirtualizedList.displayName = 'BottomSheetVirtualizedList';
27+
//@ts-ignore
28+
BottomSheetVirtualizedList.$bottomSheetIntegrated = true;
2729

2830
export default BottomSheetVirtualizedList as <T>(
2931
props: BottomSheetVirtualizedListProps<T>

src/components/bottomSheetView/BottomSheetView.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,7 @@ function BottomSheetViewComponent({
9898

9999
const BottomSheetView = memo(BottomSheetViewComponent);
100100
BottomSheetView.displayName = 'BottomSheetView';
101+
//@ts-ignore
102+
BottomSheetView.$bottomSheetIntegrated = true;
101103

102104
export default BottomSheetView;

src/hooks/useNormalizedSnapPoints.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ export const useNormalizedSnapPoints = (
7777
: containerHeight.value
7878
);
7979

80-
// push dynamic snap point into the normalized snap points.
81-
_normalizedSnapPoints.push(dynamicSnapPoint);
80+
// push dynamic snap point into the normalized snap points,
81+
// only if it does not exists in the provided list already.
82+
if (!_normalizedSnapPoints.includes(dynamicSnapPoint)) {
83+
_normalizedSnapPoints.push(dynamicSnapPoint);
84+
}
8285

8386
// sort all snap points.
8487
_normalizedSnapPoints = _normalizedSnapPoints.sort((a, b) => b - a);

src/hooks/usePropsValidator.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ export const usePropsValidator = ({
1414
enableDynamicSizing,
1515
topInset,
1616
bottomInset,
17+
children,
1718
}: Pick<
1819
BottomSheetProps,
19-
'index' | 'snapPoints' | 'enableDynamicSizing' | 'topInset' | 'bottomInset'
20+
| 'index'
21+
| 'snapPoints'
22+
| 'enableDynamicSizing'
23+
| 'topInset'
24+
| 'bottomInset'
25+
| 'children'
2026
>) => {
2127
useMemo(() => {
2228
//#region snap points
@@ -78,4 +84,18 @@ export const usePropsValidator = ({
7884

7985
// animations
8086
}, [index, snapPoints, topInset, bottomInset, enableDynamicSizing]);
87+
88+
useMemo(() => {
89+
invariant(
90+
(enableDynamicSizing &&
91+
children &&
92+
// @ts-ignore
93+
children.type &&
94+
// @ts-ignore
95+
children.type.$bottomSheetIntegrated) ||
96+
!enableDynamicSizing,
97+
`'enableDynamicSizing' is enabled but children type is not integrated with the library !` +
98+
` expected children types are\n- BottomSheetView\n- BottomSheetFlatList\n- BottomSheetScrollView\n- BottomSheetSectionList\n- BottomSheetVirtualizedList`
99+
);
100+
}, [enableDynamicSizing, children]);
81101
};

0 commit comments

Comments
 (0)