UNPKG

@audira/carbon-react-native

Version:

Build React Native apps with component and shared patterns using Carbon

73 lines (72 loc) 1.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Overlay = void 0; var _react = require("react"); var _reactNative = require("react-native"); var _index = require("../../../../carbon-style-sheet/index.js"); var _jsxRuntime = require("react/jsx-runtime"); const Overlay = exports.Overlay = /*#__PURE__*/(0, _react.forwardRef)(function ({ // type, animationConfig, style, ...props }, ref) { const viewRef = (0, _react.useRef)(null), opacityRef = (0, _react.useRef)(0), /** * 0 = unmounted * 1 = mounted */ opacity = (0, _react.useRef)(new _reactNative.Animated.Value(0)); (0, _react.useEffect)(() => { if (opacityRef.current == 0) { opacityRef.current = 1; _reactNative.Animated.timing(opacity.current, { toValue: 1, duration: animationConfig.duration, useNativeDriver: true }).start(); } }, [animationConfig, opacity]); (0, _react.useImperativeHandle)(ref, () => { return Object.assign(viewRef.current ?? {}, { animateUnmount() { return new Promise(resolve => { opacityRef.current = 0; _reactNative.Animated.timing(opacity.current, { toValue: 0, duration: animationConfig.duration, useNativeDriver: true }).start(({ finished }) => { if (finished) { resolve(); } }); }); } }); }, [animationConfig, opacity]); return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, { ref: viewRef, ...props, style: [styleSheet.overlay, { opacity: opacity.current }, style] }); }); const styleSheet = _index.CarbonStyleSheet.create({ overlay: { backgroundColor: _index.CarbonStyleSheet.color.overlay, position: 'absolute', top: 0, right: 0, bottom: 0, left: 0, overflow: 'hidden' } }); //# sourceMappingURL=Overlay.js.map