@@ -6,6 +6,7 @@ export interface IJoystickProps {
66 stickColor ?: string ;
77 throttle ?: number ;
88 disabled ?: boolean ;
9+ sticky ?: boolean ;
910 move ?: ( event : IJoystickUpdateEvent ) => void ;
1011 stop ?: ( event : IJoystickUpdateEvent ) => void ;
1112 start ?: ( event : IJoystickUpdateEvent ) => void ;
@@ -219,19 +220,25 @@ class Joystick extends React.Component<IJoystickProps, IJoystickState> {
219220 * @private
220221 */
221222 private _mouseUp ( ) {
222- this . setState ( {
223+ const stateUpdate = {
223224 dragging : false ,
224- coordinates : undefined
225- } ) ;
225+ } ;
226+ if ( ! this . props . sticky ) {
227+ stateUpdate [ 'coordinates' ] = undefined ;
228+ }
229+ this . setState ( stateUpdate ) ;
226230 window . removeEventListener ( "mouseup" , this . _boundMouseUp ) ;
227231 window . removeEventListener ( "mousemove" , this . _boundMouseMove ) ;
228232
229233 if ( this . props . stop ) {
230234 this . props . stop ( {
231235 type : "stop" ,
232- x : null ,
233- y : null ,
234- direction : null
236+ //@ts -ignore
237+ x : this . props . sticky ? this . state . coordinates . relativeX : null ,
238+ //@ts -ignore
239+ y : this . props . sticky ? this . state . coordinates . relativeY : null ,
240+ //@ts -ignore
241+ direction : this . props . sticky ? this . state . coordinates . direction : null
235242 } ) ;
236243 }
237244
@@ -275,7 +282,7 @@ class Joystick extends React.Component<IJoystickProps, IJoystickState> {
275282 flexShrink : 0
276283 } ;
277284
278- if ( this . state . dragging && this . state . coordinates !== undefined ) {
285+ if ( this . state . coordinates !== undefined ) {
279286 stickStyle = Object . assign ( { } , stickStyle , {
280287 position : 'absolute' ,
281288 transform : `translate3d(${ this . state . coordinates . relativeX } px, ${ this . state . coordinates . relativeY } px, 0)`
0 commit comments