init project

This commit is contained in:
cssivision 2015-11-20 23:48:49 +08:00
commit 55150659ab
5 changed files with 102 additions and 0 deletions

1
README.md Normal file
View File

@ -0,0 +1 @@
##react-native-qrcode

1
index.js Normal file
View File

@ -0,0 +1 @@
module.exports = require('./lib/qrcode.js');

33
lib/Canvas.js Normal file
View File

@ -0,0 +1,33 @@
'use strict';
var React = require('react-native');
var {
View,
WebView
} = React;
var Canvas = React.createClass({
propTypes: {
context: React.PropTypes.object,
render: React.PropTypes.func.isRequired
},
render() {
var contextString = JSON.stringify(this.props.context);
var renderString = this.props.render.toString();
return (
<View>
<WebView
automaticallyAdjustContentInsets={false}
contentInset={{top: 0, right: 0, bottom: 0, left: 0}}
html={"<style>*{margin:0;padding:0;}canvas{position:absolute;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}
/>
</View>
);
}
});
module.exports = Canvas;

44
lib/qrcode.js Normal file
View File

@ -0,0 +1,44 @@
'use strict'
var React = require('react-native');
var Canvas = require('./Canvas.js');
var {
View
} = React;
var qr = require('qr.js');
module.exports = React.createClass({
propTypes: {
context: React.PropTypes.object,
render: React.PropTypes.func.isRequired
},
getDefaultProps: function() {
return {
height: 200,
width: 200,
value: 'https://github.com/cssivision',
}
},
renderCanvas: function(canvas) {
var ctx = canvas.getContext('2d');
canvas.width = this.props.width;
canvas.height = this.props.height;
canvas.style.left = (window.innerWidth - 200)/2 + 'px';
if(window.innerHeight>200) canvas.style.top = (window.innerHeight - 200)/2 + 'px';
},
render: function() {
return (
<View>
<Canvas
context={{this.props.context}}
render={this.renderCanvas}
style={{height: this.props.height, width: this.props.width}}
/>
</View>
);
}
});

23
package.json Normal file
View File

@ -0,0 +1,23 @@
{
"name": "react-native-qrcode",
"version": "1.0.0",
"description": "react-native qrocode generator",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/cssivision/react-native-qrcode.git"
},
"keywords": [
"react-native",
"qrcode"
],
"author": "sivision.chen",
"license": "MIT",
"bugs": {
"url": "https://github.com/cssivision/react-native-qrcode/issues"
},
"homepage": "https://github.com/cssivision/react-native-qrcode#readme"
}