UNPKG

react-native-modal-popover

Version:
89 lines 3.53 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PopoverController = void 0; const PropTypes = __importStar(require("prop-types")); const React = __importStar(require("react")); const react_native_1 = require("react-native"); class PopoverController extends React.PureComponent { constructor() { super(...arguments); this.state = { showPopover: false, popoverAnchor: { x: 0, y: 0, width: 0, height: 0 }, }; this.onOrientationChange = () => { if (this.state.showPopover) { requestAnimationFrame(this.openPopover); } }; this.touchable = null; this.setTouchableRef = (ref) => { this.touchable = ref; }; this.openPopover = () => { const handle = (0, react_native_1.findNodeHandle)(this.touchable); if (handle) { react_native_1.NativeModules.UIManager.measure(handle, this.onTouchableMeasured); } }; this.onTouchableMeasured = (x0, y0, width, height, x, y) => { var _a; const dimensions = react_native_1.Dimensions.get('window'); this.setState({ showPopover: true, popoverAnchor: { x: react_native_1.I18nManager.isRTL ? dimensions.width - x : x, y: y - (this.props.calculateStatusBar ? (_a = react_native_1.StatusBar.currentHeight) !== null && _a !== void 0 ? _a : 0 : 0), width, height, }, }); }; this.closePopover = () => this.setState({ showPopover: false }); } componentDidMount() { this.dimensionsSub = react_native_1.Dimensions.addEventListener('change', this.onOrientationChange); } componentWillUnmount() { var _a; (_a = this.dimensionsSub) === null || _a === void 0 ? void 0 : _a.remove(); } render() { return this.props.children({ openPopover: this.openPopover, closePopover: this.closePopover, setPopoverAnchor: this.setTouchableRef, popoverVisible: this.state.showPopover, popoverAnchorRect: this.state.popoverAnchor, }); } } exports.PopoverController = PopoverController; PopoverController.propTypes = { children: PropTypes.func.isRequired, }; //# sourceMappingURL=PopoverController.js.map