@@ -16,25 +16,26 @@ export const XYPadControl = React.memo(({ control, value }: any) => {
1616 x : value . x ,
1717 y : value . y ,
1818 } ,
19- onFrame ( { x, y } : any ) {
20- if ( ! scrub ) {
21- const vx = clamp ( map ( x , 0 , width / 2 , 0 , distance ) , - distance , distance ) || 0 ;
22- const vy = clamp ( map ( y , 0 , height / 2 , 0 , distance ) , - distance , distance ) || 0
23- control . set ( ( ) => ( {
24- x : vx < THRESHOLD && vx > - THRESHOLD ? 0 : vx ,
25- y : vy < THRESHOLD && vy > - THRESHOLD ? 0 : vy ,
26- } ) ) ;
27- }
19+
20+ onChange ( value : any , b : any ) {
21+ const v =
22+ clamp ( map ( value , 0 , width / 2 , 0 , distance ) , - distance , distance ) || 0 ;
23+ control . set ( ( prev : any ) => ( {
24+ ...prev ,
25+ [ b . key ] : v < THRESHOLD && v > - THRESHOLD ? 0 : v ,
26+ } ) ) ;
2827 } ,
29- } ) ) ;
28+ } ) ) as any ;
3029
3130 const bind = useDrag ( ( { down, movement } ) => {
3231 if ( down && ! stage . current ) {
3332 stage . current = value ;
3433 } else if ( ! down ) {
3534 stage . current = null ;
3635 }
36+
3737 setCursor ( { x : down ? movement [ 0 ] : 0 , y : down ? movement [ 1 ] : 0 } ) ;
38+
3839 if ( scrub && down ) {
3940 control . set ( ( ) => ( {
4041 x :
@@ -48,7 +49,9 @@ export const XYPadControl = React.memo(({ control, value }: any) => {
4849 } ) ;
4950
5051 const x = cursor . x . interpolate ( ( n : number ) => clamp ( n + width / 2 , 0 , width ) ) ;
51- const y = cursor . y . interpolate ( ( n : number ) => clamp ( n + height / 2 , 0 , height ) ) ;
52+ const y = cursor . y . interpolate ( ( n : number ) =>
53+ clamp ( n + height / 2 , 0 , height )
54+ ) ;
5255
5356 return (
5457 < BaseControl
@@ -73,7 +76,10 @@ export const XYPadControl = React.memo(({ control, value }: any) => {
7376 < animated . line x1 = { 0 } x2 = "100%" y1 = { y } y2 = { y } stroke = "#ccc" />
7477 < animated . g
7578 style = { {
76- transform : interpolate ( [ x , y ] , ( x , y ) => `translate(${ x } px, ${ y } px)` ) ,
79+ transform : interpolate (
80+ [ x , y ] ,
81+ ( x , y ) => `translate(${ x } px, ${ y } px)`
82+ ) ,
7783 } }
7884 >
7985 < circle r = { 8 } fill = "#ccc" />
@@ -84,4 +90,4 @@ export const XYPadControl = React.memo(({ control, value }: any) => {
8490 ) ;
8591} ) ;
8692
87- // (XYPadControl as any).skipEvents = true;
93+ // (XYPadControl as any).skipEvents = true;
0 commit comments