Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/components/bottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -366,18 +366,21 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
snapPoints.length - 1
}`
);
runOnUI(animateToPoint)(snapPoints[index]);
const newSnapPoint = snapPoints[index];
runOnUI(animateToPoint)(newSnapPoint);
},
[animateToPoint, snapPoints]
);
const handleClose = useCallback(() => {
runOnUI(animateToPoint)(safeContainerHeight);
}, [animateToPoint, safeContainerHeight]);
const handleExpand = useCallback(() => {
runOnUI(animateToPoint)(snapPoints[snapPoints.length - 1]);
const newSnapPoint = snapPoints[snapPoints.length - 1];
runOnUI(animateToPoint)(newSnapPoint);
}, [animateToPoint, snapPoints]);
const handleCollapse = useCallback(() => {
runOnUI(animateToPoint)(snapPoints[0]);
const newSnapPoint = snapPoints[0];
runOnUI(animateToPoint)(newSnapPoint);
}, [animateToPoint, snapPoints]);
useImperativeHandle(ref, () => ({
snapTo: handleSnapTo,
Expand Down Expand Up @@ -488,9 +491,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
didMountOnAnimate.current === false &&
snapPoints[_providedIndex] !== safeContainerHeight
) {
requestAnimationFrame(() =>
runOnUI(animateToPoint)(snapPoints[_providedIndex])
);
const newSnapPoint = snapPoints[_providedIndex];
requestAnimationFrame(() => runOnUI(animateToPoint)(newSnapPoint));
didMountOnAnimate.current = true;
}
}, [
Expand All @@ -507,9 +509,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
*/
useEffect(() => {
if (isLayoutCalculated && currentIndexRef.current !== -1) {
requestAnimationFrame(() =>
runOnUI(animateToPoint)(snapPoints[currentIndexRef.current])
);
const newSnapPoint = snapPoints[currentIndexRef.current];
requestAnimationFrame(() => runOnUI(animateToPoint)(newSnapPoint));
}
}, [isLayoutCalculated, snapPoints, animateToPoint]);

Expand Down Expand Up @@ -606,6 +607,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
/>
<BottomSheetContainer
key="BottomSheetContainer"
containerHeight={safeContainerHeight}
shouldMeasureHeight={shouldMeasureContainerHeight}
onMeasureHeight={handleOnContainerMeasureHeight}
>
Expand Down
15 changes: 13 additions & 2 deletions src/components/bottomSheetContainer/BottomSheetContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { memo, useCallback } from 'react';
import React, { memo, useCallback, useMemo } from 'react';
import { View } from 'react-native';
import isEqual from 'lodash.isequal';
import type { BottomSheetContainerProps } from './types';
import { styles } from './styles';

const BottomSheetContainerComponent = ({
shouldMeasureHeight,
containerHeight,
onMeasureHeight,
children,
}: BottomSheetContainerProps) => {
Expand All @@ -22,12 +23,22 @@ const BottomSheetContainerComponent = ({
);
//#endregion

//#region styles
const containerStyle = useMemo(
() => [
styles.container,
containerHeight ? { height: containerHeight } : {},
],
[containerHeight]
);
//#endregion

//#region render
// console.log('BottomSheetContainer', 'render', shouldMeasureHeight);
return (
<View
pointerEvents="box-none"
style={styles.container}
style={containerStyle}
onLayout={shouldMeasureHeight ? handleOnLayout : undefined}
children={children}
/>
Expand Down
1 change: 1 addition & 0 deletions src/components/bottomSheetContainer/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import { StyleSheet } from 'react-native';
export const styles = StyleSheet.create({
container: {
...StyleSheet.absoluteFillObject,
overflow: 'hidden',
},
});
1 change: 1 addition & 0 deletions src/components/bottomSheetContainer/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ReactNode } from 'react';

export interface BottomSheetContainerProps {
shouldMeasureHeight: boolean;
containerHeight?: number;
onMeasureHeight: (height: number) => void;
children: ReactNode;
}