@@ -101,16 +101,14 @@ class SketchField extends React.Component {
101101 canvas . on ( 'mouse:out' , this . _onMouseOut ) ;
102102
103103 // initialize canvas with default data
104- setTimeout ( ( ) => {
105- if ( defaultData ) {
106- if ( 'json' === defaultDataType ) {
107- this . fromJSON ( defaultData ) ;
108- }
109- if ( 'url' === defaultDataType ) {
110- this . fromDataURL ( defaultData ) ;
111- }
104+ if ( defaultData ) {
105+ if ( 'json' === defaultDataType ) {
106+ this . fromJSON ( defaultData ) ;
107+ }
108+ if ( 'url' === defaultDataType ) {
109+ this . fromDataURL ( defaultData ) ;
112110 }
113- } , 100 )
111+ }
114112 }
115113
116114 _initTools ( fabricCanvas ) {
@@ -347,17 +345,18 @@ class SketchField extends React.Component {
347345 * JSON format must conform to the one of fabric.Canvas#toDatalessJSON
348346 *
349347 * @param json JSON string or object
350- * @param callback Callback, invoked when json is parsed and corresponding objects (e.g: fabric.Image) are initialized
351- * @param reviver Method for further parsing of JSON elements, called after each fabric object created.
352-
353348 */
354349 fromJSON ( json ) {
355350 if ( ! json ) return ;
356351 let canvas = this . _fc ;
357- canvas . loadFromJSON ( json , ( ) => canvas . renderAll ( ) ) ;
358- if ( this . props . onChange ) {
359- this . props . onChange ( null ) ;
360- }
352+ setTimeout ( ( ) => {
353+ canvas . loadFromJSON ( json , ( ) => {
354+ canvas . renderAll ( ) ;
355+ if ( this . props . onChange ) {
356+ this . props . onChange ( null ) ;
357+ }
358+ } ) ;
359+ } , 100 ) ;
361360 }
362361
363362 /**
@@ -371,7 +370,10 @@ class SketchField extends React.Component {
371370 let canvas = this . _fc ;
372371 let img = new Image ( ) ;
373372 img . src = data ;
374- img . onload = ( ) => canvas . add ( new fabric . Image ( img , options ) ) ;
373+ img . onload = ( ) => {
374+ canvas . add ( new fabric . Image ( img , options ) ) ;
375+ canvas . renderAll ( ) ;
376+ } ;
375377 if ( this . props . onChange ) {
376378 this . props . onChange ( null ) ;
377379 }
0 commit comments