react-mathlive icon indicating copy to clipboard operation
react-mathlive copied to clipboard

shared keyboard in react

Open hobo1618 opened this issue 3 years ago • 2 comments

Hey Arnog,

I'm trying to create a shared virtual keyboard in react, but not sure how to go about it. The docs on cortex say this:

To use a shared virtual keyboard, call the makeSharedVirtualKeyboard() function in the context of the main document.

You should make that call as early as possible, before changing the options of any mathfield or adding mathfields to the DOM.

As far as I can tell, in React I'm only able to access / manipulate the MathView component via refs. Am I missing something?

Thanks,

Will

hobo1618 avatar Oct 31 '22 20:10 hobo1618

I'm not sure what you are asking. Are you asking how to make the call to makeSharedVirtualKeyboard() when using React? I'm not a React expert, but I believe you would use the useEffect hook, i.e. something like:

import React, {useEffect} from 'react';

useEffect(()=> makeSharedVirtualKeyboard(),[])

arnog avatar Oct 31 '22 23:10 arnog

Yes, that was basically my question and sorry that it wasn't very clear.

The issue, finally, was that react-math-view doesn't expose makeSharedVirtualKeyboard(), so I added mathlive as a dependency and imported it from there. After that I simply fired the function and the shared keyboard worked, without having to call the function from a useEffect hook. Here's an example repo that also shows how to customize the keyboard.

Love the project btw!

hobo1618 avatar Nov 02 '22 20:11 hobo1618