diff --git a/src/components/bottomSheet/BottomSheet.tsx b/src/components/bottomSheet/BottomSheet.tsx index 8fb3e0666..a00f3d1a8 100644 --- a/src/components/bottomSheet/BottomSheet.tsx +++ b/src/components/bottomSheet/BottomSheet.tsx @@ -168,13 +168,17 @@ const BottomSheetComponent = forwardRef( //#endregion //#region validate props - usePropsValidator({ - index: _providedIndex, - snapPoints: _providedSnapPoints, - enableDynamicSizing, - topInset, - bottomInset, - }); + if (__DEV__) { + // eslint-disable-next-line react-hooks/rules-of-hooks + usePropsValidator({ + index: _providedIndex, + snapPoints: _providedSnapPoints, + enableDynamicSizing, + topInset, + bottomInset, + children, + }); + } //#endregion //#region layout variables diff --git a/src/components/bottomSheetScrollable/BottomSheetFlatList.tsx b/src/components/bottomSheetScrollable/BottomSheetFlatList.tsx index 6d3c1b797..696ce3b16 100644 --- a/src/components/bottomSheetScrollable/BottomSheetFlatList.tsx +++ b/src/components/bottomSheetScrollable/BottomSheetFlatList.tsx @@ -21,6 +21,8 @@ const BottomSheetFlatListComponent = createBottomSheetScrollableComponent< const BottomSheetFlatList = memo(BottomSheetFlatListComponent); BottomSheetFlatList.displayName = 'BottomSheetFlatList'; +//@ts-ignore +BottomSheetFlatList.$bottomSheetIntegrated = true; export default BottomSheetFlatList as ( props: BottomSheetFlatListProps diff --git a/src/components/bottomSheetScrollable/BottomSheetScrollView.tsx b/src/components/bottomSheetScrollable/BottomSheetScrollView.tsx index 6463c4ddf..a8e4c86e0 100644 --- a/src/components/bottomSheetScrollable/BottomSheetScrollView.tsx +++ b/src/components/bottomSheetScrollable/BottomSheetScrollView.tsx @@ -21,6 +21,8 @@ const BottomSheetScrollViewComponent = createBottomSheetScrollableComponent< const BottomSheetScrollView = memo(BottomSheetScrollViewComponent); BottomSheetScrollView.displayName = 'BottomSheetScrollView'; +//@ts-ignore +BottomSheetScrollView.$bottomSheetIntegrated = true; export default BottomSheetScrollView as ( props: BottomSheetScrollViewProps diff --git a/src/components/bottomSheetScrollable/BottomSheetSectionList.tsx b/src/components/bottomSheetScrollable/BottomSheetSectionList.tsx index 6e046f192..0576c07d1 100644 --- a/src/components/bottomSheetScrollable/BottomSheetSectionList.tsx +++ b/src/components/bottomSheetScrollable/BottomSheetSectionList.tsx @@ -22,6 +22,8 @@ const BottomSheetSectionListComponent = createBottomSheetScrollableComponent< const BottomSheetSectionList = memo(BottomSheetSectionListComponent); BottomSheetSectionList.displayName = 'BottomSheetSectionList'; +//@ts-ignore +BottomSheetSectionList.$bottomSheetIntegrated = true; export default BottomSheetSectionList as ( props: BottomSheetSectionListProps diff --git a/src/components/bottomSheetScrollable/BottomSheetVirtualizedList.tsx b/src/components/bottomSheetScrollable/BottomSheetVirtualizedList.tsx index df2ad015e..e09819fe1 100644 --- a/src/components/bottomSheetScrollable/BottomSheetVirtualizedList.tsx +++ b/src/components/bottomSheetScrollable/BottomSheetVirtualizedList.tsx @@ -24,6 +24,8 @@ const BottomSheetVirtualizedListComponent = const BottomSheetVirtualizedList = memo(BottomSheetVirtualizedListComponent); BottomSheetVirtualizedList.displayName = 'BottomSheetVirtualizedList'; +//@ts-ignore +BottomSheetVirtualizedList.$bottomSheetIntegrated = true; export default BottomSheetVirtualizedList as ( props: BottomSheetVirtualizedListProps diff --git a/src/components/bottomSheetView/BottomSheetView.tsx b/src/components/bottomSheetView/BottomSheetView.tsx index 1873a53aa..0d4aef711 100644 --- a/src/components/bottomSheetView/BottomSheetView.tsx +++ b/src/components/bottomSheetView/BottomSheetView.tsx @@ -98,5 +98,7 @@ function BottomSheetViewComponent({ const BottomSheetView = memo(BottomSheetViewComponent); BottomSheetView.displayName = 'BottomSheetView'; +//@ts-ignore +BottomSheetView.$bottomSheetIntegrated = true; export default BottomSheetView; diff --git a/src/hooks/useNormalizedSnapPoints.ts b/src/hooks/useNormalizedSnapPoints.ts index 5d3207fbb..f32fecf13 100644 --- a/src/hooks/useNormalizedSnapPoints.ts +++ b/src/hooks/useNormalizedSnapPoints.ts @@ -77,8 +77,11 @@ export const useNormalizedSnapPoints = ( : containerHeight.value ); - // push dynamic snap point into the normalized snap points. - _normalizedSnapPoints.push(dynamicSnapPoint); + // push dynamic snap point into the normalized snap points, + // only if it does not exists in the provided list already. + if (!_normalizedSnapPoints.includes(dynamicSnapPoint)) { + _normalizedSnapPoints.push(dynamicSnapPoint); + } // sort all snap points. _normalizedSnapPoints = _normalizedSnapPoints.sort((a, b) => b - a); diff --git a/src/hooks/usePropsValidator.ts b/src/hooks/usePropsValidator.ts index 7d80c93b2..7079f1d61 100644 --- a/src/hooks/usePropsValidator.ts +++ b/src/hooks/usePropsValidator.ts @@ -14,9 +14,15 @@ export const usePropsValidator = ({ enableDynamicSizing, topInset, bottomInset, + children, }: Pick< BottomSheetProps, - 'index' | 'snapPoints' | 'enableDynamicSizing' | 'topInset' | 'bottomInset' + | 'index' + | 'snapPoints' + | 'enableDynamicSizing' + | 'topInset' + | 'bottomInset' + | 'children' >) => { useMemo(() => { //#region snap points @@ -78,4 +84,18 @@ export const usePropsValidator = ({ // animations }, [index, snapPoints, topInset, bottomInset, enableDynamicSizing]); + + useMemo(() => { + invariant( + (enableDynamicSizing && + children && + // @ts-ignore + children.type && + // @ts-ignore + children.type.$bottomSheetIntegrated) || + !enableDynamicSizing, + `'enableDynamicSizing' is enabled but children type is not integrated with the library !` + + ` expected children types are\n- BottomSheetView\n- BottomSheetFlatList\n- BottomSheetScrollView\n- BottomSheetSectionList\n- BottomSheetVirtualizedList` + ); + }, [enableDynamicSizing, children]); };