wix-incubator / react-native-zss-rich-text-editor

React Native rich text editor based on ZSSRichTextEditor
Other
840 stars 310 forks source link

Editor auto height #156

Open exhibition315 opened 5 years ago

exhibition315 commented 5 years ago

If I put the RichTextEditor into scrollview without height, there is no editor be shown. Is any possible to make editor height automatically base on content?

My code snip:

<ScrollView>
    // other components
    <RichTextEditor 
        initialContentHTML="some html content"
        style={{flex:1}}
    />
</ScrollView>
JLHuu commented 5 years ago

@exhibition315 Have you solved the problem?I have the same problem

ChenTianSaber commented 4 years ago

I solved this.

  1. open "editor.html " and edit this function.
function setHTML(editorId, html) {
                var editor = $('#' + editorId);
                editor.html(html);

                var div = document.getElementById('zss_editor_content');
                var clientHeight = div.clientHeight;
                // alert(clientHeight);
                WebViewBridge.send(JSON.stringify({type: 'GET_CONTENT_HEIGHT', data:clientHeight}));

            }

this code means that get the height and send it when setHTML (you can send the height any time you want )

  1. open RichTextEditor and edit this function

    
    onBridgeMessage(str){
    try {
      const message = JSON.parse(str);
    
      ...other code

-----new------ case messages.GET_CONTENT_HEIGHT: { this.props.onContentHeight && this.props.onContentHeight(message.data); break; } -----new------ } } catch(e) { // alert('NON JSON MESSAGE'); } }

this code means get the height and callback it.

3.use props

<RichTextEditor ref={(r)=>this.richtext = r} style={{alignItems:'center', justifyContent: 'center', backgroundColor: 'transparent',width:width}} initialContentHTML={item.attributes.content} hiddenTitle={true} onContentHeight={(height)=>{ // alert('onContentHeight:'+height); this.articleData.changeArticleContentHeight(height); }} />


I think you know how to do it. You get the height now, so you just update the height of RichTextEditor.

My English is not good . I wish this can help you.