UNPKG

react-native-navigation-bottom-sheet

Version:

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

96 lines (82 loc) 2.61 kB
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; } import { Navigation } from 'react-native-navigation'; import { listen, dispatch } from './events'; import BottomSheet from './BottomSheet'; const notInitialized = 'You have not initialized RNNBottomSheet component.'; const openedInstance = 'You already have running instance of the component. Aborting...'; export default 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) : Navigation.registerComponent(this.bottomSheetName, () => BottomSheet); this.registered = true; listen('MARK_CLOSED', () => { this.modalOpened = false; }); } } /** * Used only to showcase a support for multuple snap points. * Probably useless in practise. */ static snapTo(index) { 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' } } }; Navigation.showModal(layout); } static closeBottomSheet() { if (!this.registered) { console.error(notInitialized); return; } dispatch('DISMISS_BOTTOM_SHEET'); } } _defineProperty(RNNBottomSheet, "modalOpened", false); _defineProperty(RNNBottomSheet, "registered", false); _defineProperty(RNNBottomSheet, "bottomSheetName", '__initBottomSheet__'); //# sourceMappingURL=RNNBottomSheet.js.map