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';
const ListItem = ({ children, ...props }: IListItemProps, ref: any) => {
const {
index,
start,
unordered,
ul,
ordered,
ol,
_text,
borderTopWidth,
_hover,
_focus,
_pressed,
...newProps
} = usePropsResolution('ListItem', props);
const _ref = React.useRef(null);
const { isHovered } = useHover({}, _ref);
// Extracting Pressable Props from newProps
const [pressableProps, remainingProps] = extractInObject(newProps, [
'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(pressableProps).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));