Skip to content

Commit 7af49b6

Browse files
added fix to display canvas on load on ios
1 parent efd875f commit 7af49b6

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/Canvas.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {Component} from 'react';
22
import PropTypes from 'prop-types';
3-
import {View, Platform, ViewPropTypes, StyleSheet} from 'react-native';
3+
import {View, Platform, ViewPropTypes, StyleSheet, Text} from 'react-native';
44
import {WebView} from 'react-native-webview';
55
import Bus from './Bus';
66
import {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'])
3232
export 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

Comments
 (0)