Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to get input cursor x, y coordinate? #361

Closed
byteab opened this issue May 30, 2024 · 4 comments
Closed

Is it possible to get input cursor x, y coordinate? #361

byteab opened this issue May 30, 2024 · 4 comments
Labels
question Further information is requested

Comments

@byteab
Copy link

byteab commented May 30, 2024

No description provided.

@tomekzaw tomekzaw changed the title is it possible to get input cursor x, y coordinate Is it possible to get input cursor x, y coordinate? May 30, 2024
@tomekzaw tomekzaw added the question Further information is requested label May 30, 2024
@tomekzaw
Copy link
Collaborator

Yes, it should be possible to extend the native code so that onSelectionChange event returns selection.cursorPosition.x and .y as well (on iOS) and its counterpart on Android.

@kirillzyusko
Copy link

Hey @ehxxn

You can use https://kirillzyusko.github.io/react-native-keyboard-controller/docs/api/hooks/input/use-focused-input-handler#onselectionchange to get x/y coordinates

If you want to extend TextInput then you can capture its tag and compare with the tag from event:

const CustomTextInput = (props) => {
  const ref = useRef();
  const [tag, setTag] = useState(-1);

  useEffect(() => {
    setTag(findNodeHandle(ref));
  }, []);

  useFocusedInputHandler({
    onSelectionChange: (e) => {
      "worklet";

      if (e.target === tag) {
        runOnJS(props.customPropHandler)(e);
      }
    }
  }, [tag]);

  return <TextInput ref={ref} {...props} />
}

You may check example app to see how it works in action 👀

@byteab
Copy link
Author

byteab commented Jun 3, 2024

Thank you very much! I'll try those solutions

@byteab byteab closed this as completed Jun 3, 2024
@kirillzyusko
Copy link

@ehxxn if you discover, that something is not working or find any bugs - feel free to open new issue in keyboard-controller repository 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants