import React from 'react';
import type { IMenuProps } from './props';
import View from '../../primitives/View';
import { usePropsConfig } from '../../../hooks';
import { usePopover } from '../../../core';

export const Menu = ({
  trigger,
  closeOnSelect = true,
  children,
  onOpen,
  onClose,
  ...props
}: IMenuProps) => {
  let triggerRef = React.useRef();
  const newProps = usePropsConfig('Menu', props);
  let [isOpen, toggle] = React.useState<boolean>(false);
  const { setPopover, closePopover } = usePopover();

  const closeMenu = () => {
    closePopover();
    toggle(false);
    onClose && onClose();
  };
  const openMenu = () => {
    setPopover(<View {...newProps}>{children}</View>, {
      triggerRef,
      animationDuration: 200,
      onClose: closeMenu,
      parentComponentConfig: { open: isOpen, closeMenu, closeOnSelect },
    });
    toggle(true);
    onOpen && onOpen();
  };
  return trigger(
    {
      onPress: openMenu,
      ref: triggerRef,
    },
    { open: isOpen }
  );
};

import React from 'react';
import type { IMenuProps } from './props';
import View from '../../primitives/View';
import { usePropsConfig } from '../../../hooks';
import { usePopover } from '../../../core';

export const Menu = ({
  trigger,
  closeOnSelect = true,
  children,
  onOpen,
  onClose,
  ...props
}: IMenuProps) => {
  let triggerRef = React.useRef();
  const newProps = usePropsConfig('Menu', props);
  let [isOpen, toggle] = React.useState<boolean>(false);
  const { setPopover, closePopover } = usePopover();

  const closeMenu = () => {
    closePopover();
    toggle(false);
    onClose && onClose();
  };
  const openMenu = () => {
    setPopover(<View {...newProps}>{children}</View>, {
      triggerRef,
      animationDuration: 200,
      onClose: closeMenu,
      parentComponentConfig: { open: isOpen, closeMenu, closeOnSelect },
    });
    toggle(true);
    onOpen && onOpen();
  };

  return (
    <View flex={1} ref={triggerRef}>
      {trigger(
        {
          onPress: openMenu,
        },
        { open: isOpen }
      )}
    </View>
  );
};

Revert "Fixes for Modal position"
Revert "Fixes for Modal position"

This reverts commit 1546dd84bdba8524c3cac5c8befc92614b5f97f8.
