Coder Social home page Coder Social logo

idreadok's Introduction

react-native-scanidcard

react-native 身份证扫描(Android版)

IOS版本将在稍后补上

实现原理为Camera自动对焦成功后获取当前帧进行针对身份证的图像识别,识别后验证身份证,验证通过则返回,不通过则进行2次对焦并识别,直到通过为止

返回的字段包含【姓名】【身份证号】【性别】【年龄】

地址如需返回的,可修改源码的ScanView.class

安装

npm install react-native-scanidcard

在android目录下的settings.gradle中加入

include ':react-native-scanidcard'
project(':react-native-scanidcard').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-scanidcard/android/app')
include ':idcard-library'
project(':idcard-library').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-scanidcard/android/idcard-library')

在android/app中的build.gradle中加入

    compile project(':react-native-scanidcard')
    compile project(':idcard-library')

在android/app/src MainApplication中加入

import com.scanidcard.ScanPackage;

在android/app/src MainApplication的getPackages方法中加入

new ScanPackage()

调用demo

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  Vibration,
  View,
  TextInput,
  DeviceEventEmitter
} from 'react-native';

import ScanView from 'react-native-scanidcard';

class ScanScreen extends Component {
  constructor(props) {
    super(props);

    this.state = {
      torchMode: 'off',
      cameraType: 'back'
    };
  }

  componentDidMount() {
    this.listener = DeviceEventEmitter.addListener('scanCallBack', this.scanCallBack.bind(this)); //对应了原生端的名字
  }

  componentWillUnmount() {
    this.listener && this.listener.remove(); //记得remove哦
    this.listener = null;
  }

  scanCallBack(e) {
    console.info(e)
  }

  render() {
    return (
        <ScanView 
          style={{ flex: 1 }}
          torchMode={this.state.torchMode}
          cameraType={this.state.cameraType}
        />
    );
  }
}

export default ScanScreen;

The End

感谢dreamkid提供的library

idreadok's People

Contributors

jiwenjiang avatar mmjbds999 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.