11import React , { Component } from 'react' ;
22import PropTypes from 'prop-types' ;
3- import { View , Platform , ViewPropTypes , StyleSheet } from 'react-native' ;
3+ import { View , Platform , ViewPropTypes , StyleSheet , Text } from 'react-native' ;
44import { WebView } from 'react-native-webview' ;
55import Bus from './Bus' ;
66import { webviewTarget , webviewProperties , webviewMethods , constructors , WEBVIEW_TARGET } from './webview-binders' ;
@@ -30,6 +30,11 @@ const stylesheet = StyleSheet.create({
3030@webviewProperties ( { width : 300 , height : 150 } )
3131@webviewMethods ( [ 'toDataURL' ] )
3232export default class Canvas extends Component {
33+
34+ state = {
35+ isLoaded : false ,
36+ }
37+
3338 static propTypes = {
3439 style : ViewPropTypes . style ,
3540 baseUrl : PropTypes . string ,
@@ -45,7 +50,6 @@ export default class Canvas extends Component {
4550 this . listeners . splice ( this . listeners . indexOf ( listener ) , 1 ) ;
4651 } ;
4752
48- loaded = false ;
4953 /**
5054 * in the mounting process this.webview can be set to null
5155 */
@@ -128,13 +132,14 @@ export default class Canvas extends Component {
128132 } ;
129133
130134 handleLoad = ( ) => {
131- this . loaded = true ;
135+ this . setState ( { isLoaded : true } ) ;
132136 this . bus . resume ( ) ;
133137 } ;
134138
135139 render ( ) {
136140 const { width, height} = this ;
137141 const { style, baseUrl = '' , originWhitelist = [ '*' ] } = this . props ;
142+ const { isLoaded} = this . state ;
138143 if ( Platform . OS === 'android' ) {
139144 const isAndroid9 = Platform . Version >= 28 ;
140145 return (
@@ -157,7 +162,7 @@ export default class Canvas extends Component {
157162 ) ;
158163 }
159164 return (
160- < View style = { [ stylesheet . container , { width, height, opacity : this . loaded ? 1 : 0 } , style ] } >
165+ < View style = { [ stylesheet . container , { width, height, opacity : isLoaded ? 1 : 0 } , style ] } >
161166 < WebView
162167 ref = { this . handleRef }
163168 style = { [ stylesheet . webview , { height, width} ] }
0 commit comments