41 lines
1.3 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');
2017-07-28 12:39:38 +03:00
var PropTypes = require('prop-types');
var createReactClass = require('create-react-class');
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
2017-07-28 12:39:38 +03:00
var Canvas = createReactClass({
2015-11-20 23:48:49 +08:00
propTypes: {
2017-07-28 12:39:38 +03:00
style: PropTypes.object,
context: PropTypes.object,
render: PropTypes.func.isRequired
2015-11-20 23:48:49 +08:00
},
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}
2017-08-09 17:59:49 +09:00
scalesPageToFit={false}
2015-11-20 23:48:49 +08:00
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-11-12 23:29:00 +08:00
style={this.props.style}
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;