UNPKG

@devvie/bottom-sheet

Version:

The 😎smart , 📦tiny , and 🎗flexible bottom sheet your app craves 🚀

35 lines (34 loc) • 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = require("react"); var _reactNative = require("react-native"); /** * Handles closing sheet when back button is pressed on * android and sheet is opened * * @param {boolean} shouldClose Whether to close sheet when back button is pressed * @param {boolean} closeSheet Function to call to close the sheet * @param {boolean} sheetOpen Determines the visibility of the sheet */ const useHandleAndroidBackButtonClose = (shouldClose = true, closeSheet, sheetOpen = false) => { const handler = (0, _react.useRef)(undefined); (0, _react.useEffect)(() => { if (_reactNative.Platform.OS !== 'android') return; handler.current = _reactNative.BackHandler.addEventListener('hardwareBackPress', () => { if (sheetOpen) { if (shouldClose) { closeSheet?.(); } return true; // prevent back press event bubbling as long as sheet is open } else return false; // when sheet is closed allow bubbling }); return () => { handler.current?.remove?.(); }; }, [shouldClose, closeSheet, sheetOpen]); }; var _default = exports.default = useHandleAndroidBackButtonClose; //# sourceMappingURL=index.js.map