Minor Changes
-
bdb1aa2
#171 Thanks @mitchheddles! - Added more flexibility for thedistance
andtolerance
activation constraints. Consumers can still provide anumber
to calculate the distance or tolerance constraints, but can now also pass in an object that adheres to theDistanceMeasurement
interface instead. This change allows consumers to specify which axis the activation distance or tolerance should be measured against, eitherx
,y
or both.type DistanceMeasurement = | number | {x: number} | {y: number} | {x: number, y: number} interface DistanceConstraint { distance: DistanceMeasurement; } interface DelayConstraint { delay: number; tolerance: DistanceMeasurement; }
Example usage:
For example, when building a list that can only be sorted vertically when using the
restrictToVerticalAxis
modifier, a consumer can now configure sensors to only measure distance against they
axis when using theMouseSensor
, and afford more tolerance on they
axis than thex
axis for theTouchSensor
:const sensors = useSensors( useSensor(MouseSensor, { activationConstraint: { distance: { y: 10 }, }, }), useSensor(TouchSensor, { activationConstraint: { delay: 250, tolerance: { y: 15, x: 5 }, }, }), );
This also fixes a bug with the way the distance is calculated when passing a number to the
distance
ortolerance
options. Previously, the sum of the distance on both thex
andy
axis was being calculated rather than the hypothenuse.