elmarti / react-joystick-component

Tiny, multitouch, component driven joysticks in react
MIT License
86 stars 27 forks source link

Manually control joystick from code #40

Closed lukedukeus closed 1 year ago

lukedukeus commented 2 years ago

I am using the joystick to control where a camera is looking. I also want the user to be able to control the camera with arrow keys. When the user is using the arrow keys, I will ignore input from the joystick, however I would still like the ui of the joystick to update based on the arrowkeys.

I am suggesting a method that will allow you to manually the joysticks position. This will not fire a motion event.

Usage would be something like:

const [joystickPosition, setJoystickPosition] = useState([0, 0]);
setJoystickPosition([50,50]); // this would only update the ui, but not fire an event.
<Joystick stop={handleStop} position={joystickPosition}></Joystick>

Please let me know if something like this already exists.

Thanks!

elmarti commented 2 years ago

Hey @lukedukeus, this doesn't already exist, but could be a cool addition.

A few thoughts:

Do you have a specific use case?

lukedukeus commented 2 years ago

I think user input should still override the joystick position. If someone wanted it to be not overridden by user input, they can turn on the disabled prop. I don't think the callbacks should be fired, if you are manually updating the position, you already have the position data.

My specific use case is controlling a camera's PTZ function. The user is able to control it via the joystick, however, if they use arrow keys, I want the position of the joystick to update.

Thanks!

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 6.2.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

elmarti commented 1 year ago

See a demo here: https://elmarti.github.io/react-joystick-component/?path=/story/joystick-examples--position-override-with-second-joystick Enjoy!