import React, { memo, useCallback } from 'react';
import { PanGestureHandler } from 'react-native-gesture-handler';
import Animated from 'react-native-reanimated';
import isEqual from 'lodash.isequal';
import BottomSheetHandle from '../bottomSheetHandle';
import type { BottomSheetHandleContainerProps } from './types';
const BottomSheetHandleContainerComponent = ({
animatedIndex,
animatedPosition,
simultaneousHandlers,
enableHandlePanningGesture,
shouldMeasureHeight,
handleComponent: _providedHandleComponent,
onGestureEvent,
onHandlerStateChange,
onMeasureHeight,
}: BottomSheetHandleContainerProps) => {
//#region variables
const shouldRenderHandle = _providedHandleComponent !== null;
//#endregion
//#region callbacks
const handleOnLayout = useCallback(
({
nativeEvent: {
layout: { height },
},
}) => {
onMeasureHeight(height);
},
[onMeasureHeight]
);
//#endregion
//#region renders
const renderHandle = useCallback(() => {
if (_providedHandleComponent === null) {
return null;
}
const HandleComponent =
_providedHandleComponent === undefined
? BottomSheetHandle
: _providedHandleComponent;
return (
);
}, [animatedIndex, animatedPosition, _providedHandleComponent]);
// console.log(
// 'BottomSheetHandleContainer',
// 'render',
// shouldRenderHandle,
// shouldMeasureHeight
// );
return shouldRenderHandle ? (
{renderHandle()}
) : null;
//#endregion
};
const BottomSheetHandleContainer = memo(
BottomSheetHandleContainerComponent,
isEqual
);
export default BottomSheetHandleContainer;