@attio/react-native-bottom-sheet-toolbox
Version:
62 lines (61 loc) • 2.52 kB
JavaScript
;
import { StyleSheet } from "react-native";
import Animated, { useAnimatedReaction, useAnimatedStyle, useDerivedValue } from "react-native-reanimated";
import { useBottomSheetToolboxInternalContext } from "../context";
import { useFooterBottomPositionSharedValue, useKeyboardAwareSafeAreaBottomInset, useLayoutSharedValue } from "../hooks";
import { jsx as _jsx } from "react/jsx-runtime";
const styles = StyleSheet.create({
container: {
bottom: 0,
opacity: 0,
position: "absolute",
width: "100%"
}
});
export function BottomSheetOverlayFooter({
children,
footerHeightSharedValue: outerFooterHeightSharedValue,
bottomInsetSharedValue: outerBottomInsetSharedValue,
style,
keyboardAwareSafeAreaBottomInsetFallback = 0,
...hookArgs
}) {
const {
isReadySharedValue,
footerHeightSharedValue
} = useBottomSheetToolboxInternalContext();
const {
height: layoutFooterHeightSharedValue,
onLayout: onFooterLayout
} = useLayoutSharedValue(null);
const KeyboardAwareSafeAreaBottomInsetSharedValue = useKeyboardAwareSafeAreaBottomInset(keyboardAwareSafeAreaBottomInsetFallback);
const bottomInsetSharedValue = useDerivedValue(() => outerBottomInsetSharedValue === undefined ? KeyboardAwareSafeAreaBottomInsetSharedValue.get() : outerBottomInsetSharedValue?.get() ?? 0, [outerBottomInsetSharedValue, KeyboardAwareSafeAreaBottomInsetSharedValue]);
useAnimatedReaction(() => {
const result = outerFooterHeightSharedValue === undefined ? layoutFooterHeightSharedValue.get() : outerFooterHeightSharedValue.get();
if (result === null) return null;
return result + bottomInsetSharedValue.get();
}, value => {
footerHeightSharedValue.set(value);
}, [outerFooterHeightSharedValue, layoutFooterHeightSharedValue]);
const bottomSharedValue = useFooterBottomPositionSharedValue(hookArgs);
const animatedStyle = useAnimatedStyle(() => {
const bottom = bottomSharedValue.get();
if (bottom === null || !isReadySharedValue.get()) return {};
const bottomInset = bottomInsetSharedValue.get();
return {
opacity: 1,
paddingBottom: bottomInset,
transform: [{
translateY: -bottom
}]
};
}, [isReadySharedValue, bottomSharedValue]);
return /*#__PURE__*/_jsx(Animated.View, {
style: [styles.container, style, animatedStyle],
children: /*#__PURE__*/_jsx(Animated.View, {
onLayout: onFooterLayout,
children: children
})
});
}
//# sourceMappingURL=bottom-sheet-overlay-footer.js.map