@gorhom/bottom-sheet
Version:
A performant interactive bottom sheet with fully configurable options 🚀
82 lines (78 loc) • 3.05 kB
JavaScript
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
import React, { memo, useEffect, useCallback, useMemo } from 'react';
import { StyleSheet } from 'react-native';
import Animated, { useAnimatedStyle } from 'react-native-reanimated';
import { SCROLLABLE_TYPE } from '../../constants';
import { useBottomSheetInternal } from '../../hooks';
import { print } from '../../utilities';
function BottomSheetViewComponent({
focusHook: useFocusHook = useEffect,
enableFooterMarginAdjustment = false,
onLayout,
style,
children,
...rest
}) {
//#region hooks
const {
animatedScrollableContentOffsetY,
animatedScrollableType,
animatedFooterHeight,
enableDynamicSizing,
animatedContentHeight
} = useBottomSheetInternal();
//#endregion
//#region styles
const flattenContainerStyle = useMemo(() => StyleSheet.flatten(style), [style]);
const containerStylePaddingBottom = useMemo(() => {
const paddingBottom = flattenContainerStyle && 'paddingBottom' in flattenContainerStyle ? flattenContainerStyle.paddingBottom : 0;
return typeof paddingBottom === 'number' ? paddingBottom : 0;
}, [flattenContainerStyle]);
const containerStyle = useMemo(() => {
return {
...flattenContainerStyle,
paddingBottom: 0
};
}, [flattenContainerStyle]);
const spaceStyle = useAnimatedStyle(() => ({
opacity: 0,
height: enableFooterMarginAdjustment ? animatedFooterHeight.value + containerStylePaddingBottom : containerStylePaddingBottom
}), [enableFooterMarginAdjustment, containerStylePaddingBottom, animatedFooterHeight]);
//#endregion
//#region callbacks
const handleSettingScrollable = useCallback(() => {
animatedScrollableContentOffsetY.value = 0;
animatedScrollableType.value = SCROLLABLE_TYPE.VIEW;
}, [animatedScrollableContentOffsetY, animatedScrollableType]);
const handleLayout = useCallback(event => {
if (enableDynamicSizing) {
animatedContentHeight.value = event.nativeEvent.layout.height;
}
if (onLayout) {
onLayout(event);
}
print({
component: BottomSheetView.displayName,
method: 'handleLayout',
category: 'layout',
params: {
height: event.nativeEvent.layout.height
}
});
}, [onLayout, animatedContentHeight, enableDynamicSizing]);
//#endregion
// effects
useFocusHook(handleSettingScrollable);
//render
return /*#__PURE__*/React.createElement(Animated.View, _extends({
onLayout: handleLayout,
style: containerStyle
}, rest), children, /*#__PURE__*/React.createElement(Animated.View, {
pointerEvents: "none",
style: spaceStyle
}));
}
const BottomSheetView = /*#__PURE__*/memo(BottomSheetViewComponent);
BottomSheetView.displayName = 'BottomSheetView';
export default BottomSheetView;
//# sourceMappingURL=BottomSheetView.js.map