UNPKG

react-native-pull-ups

Version:

Native Bottom Sheet Implementations for iOS and Android. Toddler approved.

88 lines (86 loc) 3.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _types = require("./types"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } /* Props for Native iOS component. * Not to be confused with the main component. */ const NativePullUp = (0, _reactNative.requireNativeComponent)('RNPullUpView'); const styles = _reactNative.StyleSheet.create({ primary: { position: 'absolute', left: -1000000 }, sheet: { flex: 1, backgroundColor: 'white', // emulate FittedSheets cornerRadius, for better customization borderTopRightRadius: 20, borderTopLeftRadius: 20 } }); function extractIosStyling(style) { const { borderRadius, borderTopLeftRadius, borderTopRightRadius, backgroundColor } = _reactNative.StyleSheet.flatten(style); const cornerRadius = borderTopLeftRadius ?? borderTopRightRadius ?? borderRadius ?? 0; if (typeof cornerRadius !== 'number') throw Error('Border radius must be of type number'); return { cornerRadius, contentBackgroundColor: backgroundColor ?? 'transparent' }; } function processColors(config) { const result = {}; for (const [key, val] of Object.entries(config)) { result[key] = key.endsWith('Color') ? (0, _reactNative.processColor)(val) : val; } return result; } const PullUp = props => { const { collapsedHeight, maxSheetWidth, modal, hideable, dismissable, tapToDismissModal, onStateChanged, iosStyling, children, style } = props; const onNativeStateChanged = (0, _react.useCallback)(evt => { onStateChanged?.(evt.nativeEvent.state); }, [onStateChanged]); const finalStyle = [styles.sheet, style]; const finalIosStyling = processColors({ ...extractIosStyling(finalStyle), ...iosStyling }); return /*#__PURE__*/_react.default.createElement(NativePullUp, _extends({}, props, { style: styles.primary, iosStyling: finalIosStyling, collapsedHeight: collapsedHeight || 0, maxSheetWidth: maxSheetWidth || 0, hideable: hideable && (!modal || dismissable), tapToDismissModal: dismissable && tapToDismissModal, onStateChanged: onNativeStateChanged }), /*#__PURE__*/_react.default.createElement(_reactNative.View, { collapsable: false, style: finalStyle }, children)); }; PullUp.propTypes = _types.PullUpPropTypes; PullUp.defaultProps = _types.PullUpDefaultProps; var _default = exports.default = PullUp; //# sourceMappingURL=index.ios.js.map