UNPKG

react-native-navigation-bottom-sheet

Version:

A performant customizable bottom sheet component made on top of wix react-native-navigation library.

112 lines (89 loc) 2.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _reactNativeNavigation = require("react-native-navigation"); var _events = require("./events"); var _BottomSheet = _interopRequireDefault(require("./BottomSheet")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } const notInitialized = 'You have not initialized RNNBottomSheet component.'; const openedInstance = 'You already have running instance of the component. Aborting...'; class RNNBottomSheet { static getComponentName() { return this.bottomSheetName; } static isOpened() { return this.modalOpened; } static init(registerWithProvider) { if (!this.registered) { console.log('===> Registering bottom sheet'); registerWithProvider ? registerWithProvider(this.bottomSheetName, _BottomSheet.default) : _reactNativeNavigation.Navigation.registerComponent(this.bottomSheetName, () => _BottomSheet.default); this.registered = true; (0, _events.listen)('MARK_CLOSED', () => { this.modalOpened = false; }); } } /** * Used only to showcase a support for multuple snap points. * Probably useless in practise. */ static snapTo(index) { (0, _events.dispatch)('BOTTOM_SHEET_SNAP_TO', index); } static openBottomSheet(props) { if (!this.registered) { console.error(notInitialized); return; } if (this.modalOpened) { console.error(openedInstance); return; } this.modalOpened = true; const layout = { component: { passProps: props, name: this.bottomSheetName, options: { animations: { showModal: { enabled: false }, dismissModal: { enabled: false } }, layout: { backgroundColor: 'transparent', componentBackgroundColor: 'transparent' }, hardwareBackButton: { dismissModalOnPress: false }, modal: { swipeToDismiss: false }, popGesture: false, modalPresentationStyle: 'overCurrentContext' } } }; _reactNativeNavigation.Navigation.showModal(layout); } static closeBottomSheet() { if (!this.registered) { console.error(notInitialized); return; } (0, _events.dispatch)('DISMISS_BOTTOM_SHEET'); } } exports.default = RNNBottomSheet; _defineProperty(RNNBottomSheet, "modalOpened", false); _defineProperty(RNNBottomSheet, "registered", false); _defineProperty(RNNBottomSheet, "bottomSheetName", '__initBottomSheet__'); //# sourceMappingURL=RNNBottomSheet.js.map