create-expo-cljs-app
Version:
Create a react native application with Expo and Shadow-CLJS!
125 lines (103 loc) • 4.55 kB
JavaScript
exports.__esModule = true;
exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _ModalPortal = _interopRequireDefault(require("./ModalPortal"));
var _ModalAnimation = _interopRequireDefault(require("./ModalAnimation"));
var _ModalContent = _interopRequireDefault(require("./ModalContent"));
var _ModalFocusTrap = _interopRequireDefault(require("./ModalFocusTrap"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/**
* Copyright (c) Nicolas Gallagher.
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
var uniqueModalIdentifier = 0;
var activeModalStack = [];
var activeModalListeners = {};
function notifyActiveModalListeners() {
if (activeModalStack.length === 0) {
return;
}
var activeModalId = activeModalStack[activeModalStack.length - 1];
activeModalStack.forEach(function (modalId) {
if (modalId in activeModalListeners) {
activeModalListeners[modalId](modalId === activeModalId);
}
});
}
function removeActiveModal(modalId) {
if (modalId in activeModalListeners) {
// Before removing this listener we should probably tell it
// that it's no longer the active modal for sure.
activeModalListeners[modalId](false);
delete activeModalListeners[modalId];
}
var index = activeModalStack.indexOf(modalId);
if (index !== -1) {
activeModalStack.splice(index, 1);
notifyActiveModalListeners();
}
}
function addActiveModal(modalId, listener) {
removeActiveModal(modalId);
activeModalStack.push(modalId);
activeModalListeners[modalId] = listener;
notifyActiveModalListeners();
}
var Modal = /*#__PURE__*/React.forwardRef(function (props, forwardedRef) {
var animationType = props.animationType,
children = props.children,
onDismiss = props.onDismiss,
onRequestClose = props.onRequestClose,
onShow = props.onShow,
transparent = props.transparent,
_props$visible = props.visible,
visible = _props$visible === void 0 ? true : _props$visible; // Set a unique model identifier so we can correctly route
// dismissals and check the layering of modals.
var modalId = React.useMemo(function () {
return uniqueModalIdentifier++;
}, []);
var _React$useState = React.useState(false),
isActive = _React$useState[0],
setIsActive = _React$useState[1];
var onDismissCallback = React.useCallback(function () {
removeActiveModal(modalId);
if (onDismiss) {
onDismiss();
}
}, [modalId, onDismiss]);
var onShowCallback = React.useCallback(function () {
addActiveModal(modalId, setIsActive);
if (onShow) {
onShow();
}
}, [modalId, onShow]);
React.useEffect(function () {
return function () {
return removeActiveModal(modalId);
};
}, [modalId]);
return /*#__PURE__*/React.createElement(_ModalPortal.default, null, /*#__PURE__*/React.createElement(_ModalAnimation.default, {
animationType: animationType,
onDismiss: onDismissCallback,
onShow: onShowCallback,
visible: visible
}, /*#__PURE__*/React.createElement(_ModalFocusTrap.default, {
active: isActive
}, /*#__PURE__*/React.createElement(_ModalContent.default, {
active: isActive,
onRequestClose: onRequestClose,
ref: forwardedRef,
transparent: transparent
}, children))));
});
var _default = Modal;
exports.default = _default;
module.exports = exports.default;
;