36 lines
1.1 KiB
JavaScript
Raw Normal View History

2015-11-20 23:48:49 +08:00
'use strict';
2016-05-05 23:35:57 +08:00
var React = require('react');
2015-11-20 23:48:49 +08:00
var {
View,
WebView
2016-05-05 23:35:57 +08:00
} = require('react-native');
2015-11-20 23:48:49 +08:00
var Canvas = React.createClass({
propTypes: {
style: React.PropTypes.object,
2015-11-20 23:48:49 +08:00
context: React.PropTypes.object,
render: React.PropTypes.func.isRequired
},
render() {
var contextString = JSON.stringify(this.props.context);
var renderString = this.props.render.toString();
return (
2016-11-10 17:45:07 +00:00
<View style={this.props.style}>
2015-11-20 23:48:49 +08:00
<WebView
automaticallyAdjustContentInsets={false}
contentInset={{top: 0, right: 0, bottom: 0, left: 0}}
source={{html: "<style>*{margin:0;padding:0;}canvas{transform:translateZ(0);}</style><canvas></canvas><script>var canvas = document.querySelector('canvas');(" + renderString + ").call(" + contextString + ", canvas);</script>"}}
2015-11-20 23:48:49 +08:00
opaque={false}
underlayColor={'transparent'}
2016-02-13 22:02:05 +02:00
javaScriptEnabled={true}
2016-03-29 12:03:06 -04:00
scrollEnabled={false}
2015-11-20 23:48:49 +08:00
/>
</View>
);
}
});
2016-02-13 22:02:05 +02:00
module.exports = Canvas;