import React, { memo, forwardRef } from 'react';
import Box from '../Box';
import type { IListItemProps } from './types';
import { usePropsResolution } from '../../../hooks/useThemeProps';
import { mergeRefs } from '../../../utils';
import { Pressable } from '../Pressable';
// import { useHover } from '@react-native-aria/interactions';
import { extractInObject } from '../../../theme/tools';
import { composeEventHandlers } from '../../../utils';
import {
useHover,
useFocus,
useIsPressed,
} from '../../primitives/Pressable/Pressable';
import { useHasResponsiveProps } from '../../../hooks/useHasResponsiveProps';
const ListItem = ({ children, ...props }: IListItemProps, ref: any) => {
const { hoverProps, isHovered } = useHover();
const { pressableProps, isPressed } = useIsPressed();
const { focusProps, isFocused } = useFocus();
const {
index,
start,
unordered,
ul,
ordered,
ol,
_text,
borderTopWidth,
onPressIn,
onPressOut,
onHoverIn,
onHoverOut,
onFocus,
onBlur,
...resolvedProps
} = usePropsResolution('ListItem', props, {
isHovered,
isPressed,
isFocused,
});
const _ref = React.useRef(null);
// const { isHovered } = useHover({}, _ref);
//TODO: refactor for responsive prop
if (useHasResponsiveProps(props)) {
return null;
}
// Extracting Pressable Props from resolvedProps
const [
pressableComponentProps,
nonPressableProps,
] = extractInObject(resolvedProps, [
'onPress',
'unstable_pressDelay',
'android_ripple',
'android_disableSound',
'delayLongPress',
'hitSlop',
'disabled',
'onLongPress',
'onPressIn',
'onPressOut',
'pressRetentionOffset',
'testOnly_pressed',
'onHoverIn',
'onHoverOut',
'onFocus',
'onBlur',
'_pressed',
'_focus',
]);
return Object.keys(pressableComponentProps).length !== 0 ? (
// Checking if any Pressable Props present
{/* {({ isPressed, isHovered, isFocusVisible }: any) => {
const focusTextProps = isFocusVisible &&
_focus?._text && { ..._focus._text };
const hoverTextProps = isHovered &&
_hover?._text && { ..._hover._text };
const pressedTextProps = isPressed &&
_pressed?._text && { ..._pressed._text };
return ( */}
<>
{ul || unordered ? ( //Adding disc in front of ListItem
•
) : null}
{ol || ordered ? ( //Adding index number in front of ListItem
{index + start + '.'}
) : null}
{children}
>
{/* ); */}
{/* }} */}
) : (
// If no Pressable Props passed by user render Box instead of Pressable
{ul || unordered ? ( //Adding disc in front of ListItem
•
) : null}
{ol || ordered ? ( //Adding index number in front of ListItem
{index + start + '.'}
) : null}
{children}
);
};
export default memo(forwardRef(ListItem));