react-native-rich-editor
react-native-rich-editor copied to clipboard
command & commandDOM not working
Hi:
I'm trying to change the global font size of the content in the DOM. I know setFontSize can resize the selection, but I need to resize most tags at once, like all div, pre, span, p, etc. The font size value is taken from a slider adjusted by the user. I'm tried to use commandDOM but it doesn't change anything. To access to font-size value, I tried different combinations of code like the examples below unsuccessfully:
this.richText.current?.commandDOM(`$('body').style.font-size='${fontSize}'`);
this.richText.current?.commandDOM(`$('body').style.fontSize='${fontSize}'`);
I saw the code for commandDOM on editor.js...I'm not sure I understand the syntax but is the actual command being passed down to the DOM?
commandDOM: function (command){ try {new Function("$", command)(exports.document.querySelector.bind(exports.document))} catch(e){console.log(e.message)};
I also try to capture the ref of the webview inside RichEditor.js to use injectJavaScript method but that doesn't work either.
Thank you for your help.
Hey! @cbbernier 👋 You forgot put the Measurement Unit such as px.
Here a working example ⬇️
this.richText.current?.commandDOM(`
$('.content').style.fontSize = '${fontSize}px';
$('.pell').style.fontSize = '${fontSize}px';
`);
@cbbernier The elements below body may not accept body's own fontSize in some cases
How do I remove an element with specific id?
I want to remove <div id="some_specific_id">some content here</div>
from editor content
Even the following piece of code (from the readme) not working for me:
// $ = document
this.richText.current?.commandDOM('$.execCommand('insertHTML', false, "<br/>")');
I am getting the following error:
FROM EDIT: $.execCommand is not a function. (In '$.execCommand('insertHTML', false, "<br/>")', '$.execCommand' is undefined)
How to change CSS Style from "direction: ltr;" to "direction: rtl;" ?
Finally I make it work.
richText.current?.commandDOM(
`document.getElementById('${myId}').style.backgroundColor = 'orange';`,
);
This is the only way that this works for me.