Skip to content

Commit

Permalink
去掉android扫描区域计算
Browse files Browse the repository at this point in the history
  • Loading branch information
shifeng1993 committed Sep 6, 2018
1 parent 5221f32 commit ceaec8a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ QRreader(path:uri)是一个promise对象,接受一个uri图片路径参数,


## 历史版本特性
#### 1.3.2 因android扫描区域计算有诸多问题,所以注释掉android计算扫描区域,恢复android设备的全屏扫描。
#### 1.3.1 修复ios打包发生的找不到库的错误,降低相册二维码识别的ios最低版本支持
#### 1.3.0 修复android扫描的一个bug,加入相册二维码识别,感谢lewin大神的开源二维码识别。
#### 1.2.4 限制扫码类型,修复android报错
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-qr-scanner",
"version": "1.3.1",
"version": "1.3.2",
"description": "this is qrcode scanner.",
"main": "index.js",
"nativePackage": true,
Expand Down
63 changes: 37 additions & 26 deletions src/QRScanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,32 +124,43 @@ export default class QRScanner extends PureComponent {
}

androidBarCode = (e) => {
if (!e.bounds[0] || !e.bounds[1] || !e.bounds[2] || !e.bounds[3]) return null;
if (!e.bounds[0].x || !e.bounds[0].y || !e.bounds[1].x || !e.bounds[1].y || !e.bounds[2].x || !e.bounds[2].y || !e.bounds[3].x || !e.bounds[3].y) return null;
const leftBottom = {x: e.bounds[0].x / pixelRatio, y: e.bounds[0].y / pixelRatio}
const leftTop= {x: e.bounds[1].x / pixelRatio, y: e.bounds[1].y / pixelRatio}
const rightTop = {x: e.bounds[2].x / pixelRatio, y: e.bounds[2].y / pixelRatio}
const rightBottom = {x: e.bounds[3].x / pixelRatio, y: e.bounds[3].y / pixelRatio}
let x = this.returnMin(leftTop.x, leftBottom.x);
let y = this.returnMin(leftTop.y, rightTop.y);
let width = this.returnMax(rightTop.x - leftTop.x, rightBottom.x - leftBottom.x)
let height = this.returnMax(leftBottom.y - leftTop.y , rightBottom.y - rightTop.y)
let viewMinX = this.state.barCodeSize.x - this.props.finderX * 4 / pixelRatio - (this.props.finderX > 0 ? this.props.finderX/10 : 0)
let viewMinY = this.state.barCodeSize.y - this.props.finderY * 4 / pixelRatio - (this.props.translucent ? 0 : StatusBar.currentHeight)*2/pixelRatio - (this.props.finderY > 0 ? this.props.finderY/3 : this.props.finderY/10*(-1))
let viewMaxX = this.state.barCodeSize.x + 20 + this.state.barCodeSize.width*2 / pixelRatio - width - this.props.finderX *4/pixelRatio - (this.props.finderX < 0 ? 0 : this.props.finderX/5)
let viewMaxY = this.state.barCodeSize.y + this.state.barCodeSize.height*2 / pixelRatio - height - this.props.finderY *4/pixelRatio - (this.props.translucent ? 0 : StatusBar.currentHeight)*2/pixelRatio - (this.props.finderY < 0 ? this.props.finderY/5 : 0 )
if(x&&y) {
if ((x > viewMinX && y > viewMinY) && (x < viewMaxX && y < viewMaxY)) {
if (this.props.isRepeatScan) {
Vibration.vibrate();
this.props.onRead(e)
} else {
if (!this.isShowCode) {
this.isShowCode = true;
Vibration.vibrate();
this.props.onRead(e)
}
}
// if (!e.bounds[0] || !e.bounds[1] || !e.bounds[2] || !e.bounds[3]) return null;
// const leftBottom = {x: e.bounds[0].x / pixelRatio, y: e.bounds[0].y / pixelRatio}
// const leftTop= {x: e.bounds[1].x / pixelRatio, y: e.bounds[1].y / pixelRatio}
// const rightTop = {x: e.bounds[2].x / pixelRatio, y: e.bounds[2].y / pixelRatio}
// const rightBottom = {x: e.bounds[3].x / pixelRatio, y: e.bounds[3].y / pixelRatio}
// let x = this.returnMin(leftTop.x, leftBottom.x);
// let y = this.returnMin(leftTop.y, rightTop.y);
// let width = this.returnMax(rightTop.x - leftTop.x, rightBottom.x - leftBottom.x)
// let height = this.returnMax(leftBottom.y - leftTop.y , rightBottom.y - rightTop.y)
// let viewMinX = this.state.barCodeSize.x - this.props.finderX * 4 / pixelRatio - (this.props.finderX > 0 ? this.props.finderX/10 : 0)
// let viewMinY = this.state.barCodeSize.y - this.props.finderY * 4 / pixelRatio - (this.props.translucent ? 0 : StatusBar.currentHeight)*2/pixelRatio - (this.props.finderY > 0 ? this.props.finderY/3 : this.props.finderY/10*(-1))
// let viewMaxX = this.state.barCodeSize.x + 20 + this.state.barCodeSize.width*2 / pixelRatio - width - this.props.finderX *4/pixelRatio - (this.props.finderX < 0 ? 0 : this.props.finderX/5)
// let viewMaxY = this.state.barCodeSize.y + this.state.barCodeSize.height*2 / pixelRatio - height - this.props.finderY *4/pixelRatio - (this.props.translucent ? 0 : StatusBar.currentHeight)*2/pixelRatio - (this.props.finderY < 0 ? this.props.finderY/5 : 0 )
// if(x&&y) {
// if ((x > viewMinX && y > viewMinY) && (x < viewMaxX && y < viewMaxY)) {
// if (this.props.isRepeatScan) {
// Vibration.vibrate();
// this.props.onRead(e)
// } else {
// if (!this.isShowCode) {
// this.isShowCode = true;
// Vibration.vibrate();
// this.props.onRead(e)
// }
// }
// }
// }

// 以下是不限制扫描区域
if (this.props.isRepeatScan) {
Vibration.vibrate();
this.props.onRead(e)
} else {
if (!this.isShowCode) {
this.isShowCode = true;
Vibration.vibrate();
this.props.onRead(e)
}
}
}
Expand Down

0 comments on commit ceaec8a

Please sign in to comment.