@@ -13,15 +13,13 @@ const shortid = require('shortid');
1313class CNRichTextEditor extends Component {
1414
1515 state = {
16-
1716 imageHighLightedInex : - 1 ,
18-
17+ layoutWidth : 400 ,
1918 styles : [ ] ,
2019 selection :{ start : 0 , end : 0 } ,
2120 justToolAdded : false ,
2221 avoidUpdateText : false ,
2322 focusInputIndex : 0 ,
24-
2523 } ;
2624
2725 constructor ( props ) {
@@ -35,16 +33,13 @@ class CNRichTextEditor extends Component {
3533 this . upComingStype = null ;
3634 this . focusOnNextUpdate = - 1 ;
3735 this . selectionOnFocus = null ;
38- this . layoutWidth = 400 ;
3936 }
4037
4138 componentDidMount ( ) {
4239
4340 }
4441
4542 componentDidUpdate ( prevProps , prevState ) {
46-
47-
4843 if ( this . focusOnNextUpdate != - 1 && this . textInputs . length > this . focusOnNextUpdate ) {
4944 let ref = this . textInputs [ this . focusOnNextUpdate ] ;
5045 ref . focus ( this . selectionOnFocus ) ;
@@ -453,8 +448,8 @@ class CNRichTextEditor extends Component {
453448
454449 renderImage ( image , index ) {
455450 const { width, height } = image . size ;
456- let myHeight = ( this . layoutWidth - 4 < width ) ? height * ( ( this . layoutWidth - 4 ) / width ) : height ;
457- let myWidth = ( this . layoutWidth - 4 < width ) ? this . layoutWidth - 4 : width ;
451+ let myHeight = ( this . state . layoutWidth - 4 < width ) ? height * ( ( this . state . layoutWidth - 4 ) / width ) : height ;
452+ let myWidth = ( this . state . layoutWidth - 4 < width ) ? this . state . layoutWidth - 4 : width ;
458453
459454 return (
460455 < View key = { `image${ index } ` }
@@ -526,7 +521,10 @@ class CNRichTextEditor extends Component {
526521 width,
527522 height
528523 } = event . nativeEvent . layout ;
529- this . layoutWidth = width ;
524+
525+ this . setState ( {
526+ layoutWidth : width
527+ } ) ;
530528 }
531529
532530 render ( ) {
0 commit comments