Skip to content

Commit

Permalink
latest changes to try to get hitslop to work
Browse files Browse the repository at this point in the history
  • Loading branch information
walmat committed Dec 18, 2024
1 parent 49f5996 commit 3a94dd2
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/components/DropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,29 @@ import { ImageSourcePropType, ImageURISource } from 'react-native';
import type { SFSymbols5_0 } from 'sf-symbols-typescript';
import type { DropdownMenuContentProps } from '@radix-ui/react-dropdown-menu';
import { ButtonPressAnimation } from './animations';
import { DebugLayout, HitSlop } from '@/design-system';

type ExtendedDropdownMenuTriggerProps = ComponentProps<typeof DropdownMenuPrimitive.Trigger> & {
hitSlop?: number;
testID?: string;
};

export const DropdownMenuRoot = DropdownMenuPrimitive.Root;
export const DropdownMenuTrigger = DropdownMenuPrimitive.create<ExtendedDropdownMenuTriggerProps>(DropdownMenuPrimitive.Trigger, 'Trigger');
export const DropdownMenuTrigger = DropdownMenuPrimitive.create<ExtendedDropdownMenuTriggerProps>(
(props: ExtendedDropdownMenuTriggerProps) => {
// TODO: This hitslop isn't working properly...
return (
<DropdownMenuPrimitive.Trigger {...props} style={[props.style, { padding: props.hitSlop ?? 0 }]}>
<DebugLayout>
<ButtonPressAnimation testID={props.testID}>
<HitSlop space={{ custom: props.hitSlop ?? 0 }}>{props.children}</HitSlop>
</ButtonPressAnimation>
</DebugLayout>
</DropdownMenuPrimitive.Trigger>
);
},
'Trigger'
);
export const DropdownMenuContent = DropdownMenuPrimitive.Content;
export const DropdownMenuItem = DropdownMenuPrimitive.create(
styled(DropdownMenuPrimitive.CheckboxItem)({
Expand Down Expand Up @@ -92,7 +108,7 @@ export function DropdownMenu<T extends string>({
side = 'right',
alignOffset = 5,
avoidCollisions = true,
hitSlop = 12, // TODO: Figure out how to make the trigger hit slop work
hitSlop = 20,
testID,
}: DropDownMenuProps<T>) {
const handleSelectItem = useCallback(
Expand All @@ -104,8 +120,8 @@ export function DropdownMenu<T extends string>({

return (
<DropdownMenuRoot>
<DropdownMenuTrigger asChild testID={testID}>
<ButtonPressAnimation>{children}</ButtonPressAnimation>
<DropdownMenuTrigger asChild testID={testID} hitSlop={hitSlop}>
{children}
</DropdownMenuTrigger>
<DropdownMenuContent
loop={loop}
Expand Down

0 comments on commit 3a94dd2

Please sign in to comment.