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); }
import React, { useRef } from "react";
import Box from "../box/box";
import { AnimatePresence, MotiView } from "moti";
import { Easing } from "react-native-reanimated";
/**
 * Collapse is a component that provides an expandable view.
 */
const Collapse = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(({
  children,
  show,
  animateOpacity = true,
  startingHeight = 0,
  transition = {},
  exitTransition = {},
  endingHeight = "auto",
  ...rest
}, ref) => {
  const endingHeightRef = useRef(endingHeight);
  return /*#__PURE__*/React.createElement(AnimatePresence, null, show && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MotiView, _extends({
    ref: ref
  }, rest, {
    from: {
      ...(animateOpacity && {
        opacity: 0
      }),
      height: 0
    },
    animate: {
      ...(animateOpacity && {
        opacity: 1
      }),
      height: show ? typeof endingHeightRef.current === "string" && endingHeightRef.current.includes("auto") ? "auto" : endingHeightRef.current : startingHeight
    },
    transition: {
      dampingRatio: 1,
      duration: 100,
      easing: Easing.inOut,
      ...transition,
      type: "spring"
    },
    exit: {
      ...(animateOpacity && {
        opacity: 0
      }),
      height: 0
    },
    exitTransition: {
      dampingRatio: 1,
      duration: 100,
      easing: Easing.inOut,
      ...exitTransition,
      type: "spring"
    }
  }), /*#__PURE__*/React.createElement(Box, {
    onLayout: ({
      nativeEvent
    }) => {
      if (typeof endingHeightRef.current === "string" || nativeEvent.layout.height > endingHeightRef.current) endingHeightRef.current = Math.ceil(nativeEvent.layout.height);
    }
  }, children))));
}));
Collapse.displayName = "Collapse";
export default Collapse;
//# sourceMappingURL=collapse.js.map