-
Notifications
You must be signed in to change notification settings - Fork 301
Expand file tree
/
Copy pathCanvas.js
More file actions
41 lines (36 loc) · 1.32 KB
/
Canvas.js
File metadata and controls
41 lines (36 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
var React = require('react');
var PropTypes = require('prop-types');
var createReactClass = require('create-react-class');
var {
View,
WebView,
Platform
} = require('react-native');
var Canvas = createReactClass({
propTypes: {
style: PropTypes.object,
context: PropTypes.object,
render: PropTypes.func.isRequired
},
render() {
var contextString = JSON.stringify(this.props.context);
var renderString = this.props.render.toString();
return (
<View style={this.props.style}>
<WebView
automaticallyAdjustContentInsets={false}
scalesPageToFit={Platform.OS === 'android'}
contentInset={{top: 0, right: 0, bottom: 0, left: 0}}
source={{html: "<style>*{margin:0;padding: 5;}canvas{transform:translateZ(0);}</style><canvas></canvas><script>var canvas = document.querySelector('canvas');(" + renderString + ").call(" + contextString + ", canvas);</script>"}}
opaque={false}
underlayColor={'transparent'}
style={this.props.style}
javaScriptEnabled={true}
scrollEnabled={false}
/>
</View>
);
}
});
module.exports = Canvas;