GithubHelp home page GithubHelp logo

ideacreation / react-native-barcodescanner Goto Github PK

View Code? Open in Web Editor NEW
538.0 21.0 162.0 402 KB

A barcode scanner component for react native - not maintained anymore - use react-native-camera

License: MIT License

JavaScript 23.21% Java 76.79%

react-native-barcodescanner's Introduction

react-native-barcodescanner - not maintained anymore - use react-native-camera

Version 0.4.0 of react-native-camera includes barcode scanning for android as well. I recommend using it for barcode and QR scanning as you can use the same library both for iOS and android and the implementation is more robust than this one.

Old README

A barcode scanner component for react native android. The library uses https://github.com/zxing/zxing to decode the barcodes.

React Native dependencies

  • Version 0.1.4 for React Native <=0.18
  • Version 1.x.x for React Native >=0.19
  • Version 3.x.x for React Native >=0.25

Installation

npm i --save react-native-barcodescanner

Link it to your android project

You can link it simply by running react-native link.

Manual linking

  • In android/settings.gradle

    ...
    include ':react-native-barcodescanner', ':app'
    project(':react-native-barcodescanner').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-barcodescanner/android')
  • In android/app/build.gradle

    ...
    dependencies {
        ...
        compile project(':react-native-barcodescanner')
    }
  • register module (in MainApplication.java)

    Add the following import statement:

    import com.eguma.barcodescanner.BarcodeScannerPackage;

    ...and then add BarcodeScannerPackage to exported package list (MainApplication.java#getPackages):

    public class MainApplication extends Application implements ReactApplication {
        // (...)
    
        @Override
        protected List<ReactPackage> getPackages() {
          return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            new BarcodeScannerPackage()
          );
        }
    }

Usage

import React, {
  AppRegistry,
  Component,
} from 'react-native';
import BarcodeScanner from 'react-native-barcodescanner';

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

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

  barcodeReceived(e) {
    console.log('Barcode: ' + e.data);
    console.log('Type: ' + e.type);
  }

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

AppRegistry.registerComponent('BarcodeScannerApp', () => BarcodeScannerApp);

Example

Try the included BarcodeScanner example yourself:

git clone [email protected]:ideacreation/react-native-barcodescanner.git
cd react-native-barcodescanner/Examples/BarcodeScanner
npm install
react-native run-android

To test the example you can scan the barcodes in the Testcodes.pdf file.

Properties

onBarCodeRead

Will call the specified method when a barcode is detected in the camera's view. Event contains data (barcode value) and type (barcode type). The following barcode types can be recognised:

BarcodeFormat.UPC_A
BarcodeFormat.UPC_E
BarcodeFormat.EAN_13
BarcodeFormat.EAN_8
BarcodeFormat.RSS_14
BarcodeFormat.CODE_39
BarcodeFormat.CODE_93
BarcodeFormat.CODE_128
BarcodeFormat.ITF
BarcodeFormat.CODABAR
BarcodeFormat.QR_CODE
BarcodeFormat.DATA_MATRIX
BarcodeFormat.PDF_417

torchMode

Values: on, off (default)

Use the torchMode property to specify the camera torch mode.

cameraType

Values: back (default), front

Use the cameraType property to specify the camera to use. If you specify the front camera, but the device has no front camera the back camera is used.

Viewfinder

The viewfinder is a child react component of the barcodescanner component. if you don't need the viewfinder (e.g. because you want your own child components to render) or you want your own viewfinder you can disable it with showViewFinder={false}.

The following properties can be used to style the viewfinder:

viewFinderBackgroundColor, viewFinderBorderColor, viewFinderBorderWidth, viewFinderBorderLength, viewFinderShowLoadingIndicator, viewFinderHeight, viewFinderWidth,

All color values are strings (e.g. '#eee' or 'rgba(0, 0, 0, 0.3)', default: 'white'). viewFinderHeight (default: 200), viewFinderWidth (default: 200), viewFinderBorderWidth (default: 2) and viewFinderBorderLength (default: 30) are numbers, viewFinderShowLoadingIndicator is either true or false (default) and shows a ActivityIndicator centered in the viewfinder.

react-native-barcodescanner's People

Contributors

andreaskeller avatar andreyvital avatar chirag04 avatar cpunion avatar jdeniau avatar skyfarliu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-barcodescanner's Issues

Error on require

Hello,

when I require the library, I have an error :

'BarcodeScannerView' has no propType for native prop 'RNBarcodeScannerView.scaleX' of native type 'number'.

Have you an issue to solve this problem ?

Thanks in advance,
Florian

Crashing Android

Hi, sometimes while navigating my app I have this error

06-30 23:28:03.851  3036  3036 E CameraPreview: java.lang.RuntimeException: Camera is being used after Camera.release() was called
06-30 23:28:03.851  3036  3036 E CameraPreview: java.lang.RuntimeException: Camera is being used after Camera.release() was called
06-30 23:28:03.851  3036  3036 E CameraPreview:     at android.hardware.Camera.native_cancelAutoFocus(Native Method)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at android.hardware.Camera.cancelAutoFocus(Camera.java:1275)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at com.eguma.barcodescanner.CameraPreview.stopCameraPreview(CameraPreview.java:89)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at com.eguma.barcodescanner.CameraPreview.stopCamera(CameraPreview.java:52)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at com.eguma.barcodescanner.BarcodeScannerView.stopCamera(BarcodeScannerView.java:55)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at com.eguma.barcodescanner.BarcodeScannerManager.onHostDestroy(BarcodeScannerManager.java:63)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at com.facebook.react.bridge.ReactContext.onHostDestroy(ReactContext.java:182)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at com.facebook.react.ReactInstanceManagerImpl.moveToBeforeCreateLifecycleState(ReactInstanceManagerImpl.java:599)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at com.facebook.react.ReactInstanceManagerImpl.destroy(ReactInstanceManagerImpl.java:552)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at com.facebook.react.ReactActivity.onDestroy(ReactActivity.java:177)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at android.app.Activity.performDestroy(Activity.java:6407)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1142)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3818)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3849)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at android.app.ActivityThread.-wrap5(ActivityThread.java)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at android.os.Handler.dispatchMessage(Handler.java:102)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at android.os.Looper.loop(Looper.java:148)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at android.app.ActivityThread.main(ActivityThread.java:5417)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at java.lang.reflect.Method.invoke(Native Method)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
06-30 23:28:03.851  3036  3036 E CameraPreview:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-30 23:28:04.001   833   861 W art     : Long monitor contention event with owner method=void com.android.server.am.ActivityManagerService.activityDestroyed(android.os.IBinder) from ActivityManagerService.java:6475 waiters=0 for 110ms

Are there any actions I must take in order to prevent this ?

Occasional crash on physical device while the scanner is up

I am hitting intermittent crash while the scanner is up.

I am running a 2013 Nexus 4, upgraded to Android 5. The scanner works, but every once a while when the scanner is up, the whole screen will go completely black, and needs to be rebooted. There is no logging info from adb, so I am at a loss on how to debug it.

If you have any idea why this might be, or how I can collect more debug info, please let me know.
Thanks,

Frank

Bracode does not start camera

hey guys, I am working with react-native-barcodescanner i used this module for my app. The issue is that this is working fine when i cloned it and run on my system. but when i used this in my app it is not starting the camera is there any dependencies to add ?
Have anybody idea about this ?

Any examples

I am trying the component but I can't seem to be able to close the camera when using react-native-router-flux .

Is it possible somehow to stop the camera and the capturing ?

I use router as such:

<Router>
            <Scene key="modal" component={Modal} >
                <Scene key="root" hideNavBar={true}>
                    <Scene key="login" direction="vertical" >
                        <Scene key="loginModal" hideNavBar={true} component={Login} schema="modal" title="Login"/>
                    </Scene>
                    <Scene key="barcode" direction="vertical" >
                        <Scene key="barcodeScanner" navBar={MyBar} hideNavBar={false} component={BarcodeScanner} title="BarcodeScanner"/>
                    </Scene>
                    <Scene key="tabbar" component={NavigationDrawer}>
                        <Scene key="main" tabs={true} default="tab2" >
                            <Scene key="tab1" title="test" component={Test} navigationBarStyle={{backgroundColor:"blue"}} titleStyle={{color:"white"}} />
                            <Scene key="tab2" initial={true} navigationBarStyle={{backgroundColor:"blue"}} titleStyle={{color:"white"}}  title="home"  component={Home}   />

                        </Scene>
                    </Scene>
                </Scene>
            </Scene>
        </Router>

For the NavBar i Use

class MyBar extends React.Component {
    render(){
        return (
            <Text onPress={Actions.tabbar} style={{color: this.props.selected ? "red" :"black"}}>Close</Text>
        );
    }
}

and barcode is as your example

import React, {
    Component,
    StyleSheet,
    View
} from 'react-native';
import BarcodeScanner from 'react-native-barcodescanner';

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

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

  barcodeReceived(e) {
    console.log('Barcode: ' + e.data);
    console.log('Type: ' + e.type);
  }

  render() {
    return (

            <BarcodeScanner
                onBarCodeRead={this.barcodeReceived}
                style={{ flex: 1 }}
                torchMode={this.state.torchMode}
                cameraType={this.state.cameraType}
                viewFinderDrawLaser={true}
            />

    );
  }
}


const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: "center",
        alignItems: "center",
        backgroundColor: "#F5FCFF",
    },
    welcome: {
        fontSize: 20,
        textAlign: "center",
        margin: 10,
    },
    instructions: {
        textAlign: "center",
        color: "#333333",
        marginBottom: 5,
    },
});

export default BarcodeScannerComp;

java.lang.NullPointerException

java.lang.NullPointerException
at com.eguma.barcodescanner.ReactBarcodeScannerView.setMaskColor(ReactBarcodeScannerView.java:66)

下面是代码:
this. mViewFinderView.setMaskColor(Color.parseColor("#FFFF00FF"));
this.mViewFinderView.setMaskColor(95158160);

How to change this component size

I don't need full screen to scan barcode, just need height 300 and width 100% to show this component.
this is my code

<BarcodeScanner
    onBarCodeRead={this.barcodeReceived}
    style={{ height: 300, width: screenWidth }}
    torchMode={this.state.torchMode}
    cameraType={this.state.cameraType}
/>

This show correct size, but image was lose their shape.

react-native-barcodescanner v3.0.0

Camera Permissions Not Being Set

After setting permissions for the app to use the camera, I am not prompted to authorize the camera.

<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>

Only after I authorize the camera manually am I able to initialize the camera instead of seeing a black screen.

can i use this module for ios

hai,this repo was very helpful to me, but i have doubt that is there any possibility to use the same module in ios, if possible please tell me that how to do it

Resizing scanner breaks scanning

I have a component rendering the scanner. I have an attribute on my component state that is called fullSizeScanner. When I switch from true to false, it seems that scanning doesn't work anymore. The autofocus is triggered on my phone but my handler to get the barcode is not called anymore. Any idea?

Start/Stop Scanner

Hi,

How can I start / stop the scanner on motion:

  • I'm using the phone, the camera start
  • I stop using the phone (no motion for X miliseconds), the camera stops

It seems start / stop methods are not exposed in React Code ?

Extremely bad performance

When using JS FPS is always 0, and the app so slow. Any thoughts?

  • Version: 3.1.1
  • Android: 6.0.1
  • RN: 0.32.0

Only able to read 2D formats (QR, Data Matrix, etc.)

It seems I'm unable to read any of the supported formats except for the 2D ones. Maybe I'm missing something but the QR Code and the other 2D formats are all working great! However, when I try to read a Code 39 for example, it simply doesn't get picked up. Any thoughts?

Orientation and size of view finder

I noticed that QR code is easily read in portrait but bar code is read easily in landscape orientation. Is this the known behaviour or am I doing something wrong ?
Second question is apart from the viewFinderBackgroundColor, viewFinderBorderColor, viewFinderBorderWidth, viewFinderBorderLength, viewFinderShowLoadingIndicator given in the README, can I edit any other styling of the view finder like height, width etc. ?

Orientation Change issue

When changing orientation the view of the camera starts getting smaller and smaller,

Great module

Camera shows black viewfinder after device has been in "sleep mode" or "screen timeout"

Hi,

The camera doesn't wake up / work after the device has been in sleep mode or the screen was in screen timeout mode.

Test Device

  • Samsung Galaxy Tab6a
  • Android 5.1.1

How to replicate the issue:

  1. Open app that uses the react-native-barcodescanner and go to the view that uses the camera
  2. Navigate away from the view to any view that doesn't use the camera
  3. Let the device go to sleep or in screen timeout mode
  4. Unlock screen and go to view which uses the camera

In all of my apps the viewfinder is black after walking through the previous steps

What I found so far:

  • It is not a permission issue
  • If I close the app after this issue has occured and reopen it the camera does work again
  • If I leave the view with the camera open and let the device go to sleep, it will work after I unlock the screen
  • When this issue occurs the android camera app also doesn't work
  • The Android device monitor shows the following errors when the device goes to sleep:

09-01 22:56:55.833: E/CameraPreview(15121): java.lang.RuntimeException: Camera is being used after Camera.release() was called 09-01 22:56:55.833: E/CameraPreview(15121): java.lang.RuntimeException: Camera is being used after Camera.release() was called 09-01 22:56:55.833: E/CameraPreview(15121): at android.hardware.Camera.native_cancelAutoFocus(Native Method) 09-01 22:56:55.833: E/CameraPreview(15121): at android.hardware.Camera.cancelAutoFocus(Camera.java:1348) 09-01 22:56:55.833: E/CameraPreview(15121): at com.eguma.barcodescanner.CameraPreview.stopCameraPreview(CameraPreview.java:89) 09-01 22:56:55.833: E/CameraPreview(15121): at com.eguma.barcodescanner.CameraPreview.stopCamera(CameraPreview.java:52) 09-01 22:56:55.833: E/CameraPreview(15121): at com.eguma.barcodescanner.BarcodeScannerView.onPause(BarcodeScannerView.java:43) 09-01 22:56:55.833: E/CameraPreview(15121): at com.eguma.barcodescanner.BarcodeScannerManager.onHostPause(BarcodeScannerManager.java:58) 09-01 22:56:55.833: E/CameraPreview(15121): at com.facebook.react.bridge.ReactContext.onHostPause(ReactContext.java:179) 09-01 22:56:55.833: E/CameraPreview(15121): at com.facebook.react.XReactInstanceManagerImpl.moveToBeforeResumeLifecycleState(XReactInstanceManagerImpl.java:573) 09-01 22:56:55.833: E/CameraPreview(15121): at com.facebook.react.XReactInstanceManagerImpl.onHostPause(XReactInstanceManagerImpl.java:489) 09-01 22:56:55.833: E/CameraPreview(15121): at com.facebook.react.ReactActivity.onPause(ReactActivity.java:120) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.Activity.performPause(Activity.java:6765) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1338) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:4418) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:4391) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:4366) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.ActivityThread.access$1200(ActivityThread.java:219) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1746) 09-01 22:56:55.833: E/CameraPreview(15121): at android.os.Handler.dispatchMessage(Handler.java:102) 09-01 22:56:55.833: E/CameraPreview(15121): at android.os.Looper.loop(Looper.java:145) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.ActivityThread.main(ActivityThread.java:6939) 09-01 22:56:55.833: E/CameraPreview(15121): at java.lang.reflect.Method.invoke(Native Method) 09-01 22:56:55.833: E/CameraPreview(15121): at java.lang.reflect.Method.invoke(Method.java:372) 09-01 22:56:55.833: E/CameraPreview(15121): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) 09-01 22:56:55.833: E/CameraPreview(15121): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

Please help! I really need this to work.

Thanks.

Regards,
Gawein

Camera not working on physical device

Hi,

I have an issue where the scanner works fine in my Genymotion controller but doesn't show any preview on a physical device. I modified the permissions in my Android manifest file to include permissions for the camera but still no success.

Versions:
"react-native": "^0.25.1",
"react-native-barcodescanner": "^2.0.0",

Any idea?

No image from camera on Android 6.0

I've had this issue trying an application on two devices: a Nexus 5 and a Moto X Pure both with android 6.0.

However I've tested the application on different devices ranging from Android 4.4 to 5.1 and everything seems to be working just fine.

My application uses React Native 0.29

download_20160722_111614
screenshot_20160721-113540

[Android] Camera Image is rotated 90°

I'm using React-Native 0.22.2 and Android SDK with API level 19 (KitKat).
Camera shows up, read barcodes with success, but image is displayed 90° clockwise.
viewFinder and viewFinderDrawLaser shows up on the right position (not rotated).
I have the permissions on my AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />
App only works in portrait mode, so phone is locked in portrait and orientetion never changes.
This is what my component renders:
` render() {
let camera = ;
let childrenContainerStyle = {
flex: 1
};

if(this.props.status == 'in-use') {
  camera = (
    <CameraScanner
      onBarCodeRead={this.onBarCodeRead}
      style={styles.barcodeScanner}
      torchMode={'off'}
      viewFinderDrawLaser={true}
      cameraType={'back'}
    />
  );
}

return (
  <View style={[this.props.style]}>
    <View style={childrenContainerStyle}>
      {this.props.children}
    </View>
    {camera}
  </View>
);

}
}

var styles = StyleSheet.create({
barcodeScanner: {
flex: 1
}`

tl;dr -> it's all working good, but camera image is flipped 90° clockwise. 😢

cann't work well with react-native-navigation

following the instruction, I install the react-native-barcodescanner, and it work well without react-native-navigation. But, when it comes to react-native-navigation and I create a individual page for the react-native-barcodescanner to work, it cann't work well. When i go to the page by pressing a button on a another page, It only show a red line on the left, nothing else.

Plz help me~
thx in advance~

Can't run Examples/BarcodeScanner: "undefined is not a function"

The BarcodeScanner example does not work for me - not in an AVM or on an actual device. In both cases I get an error similar to

java.util.concurrent.ExecutionException
java.lang.RuntimeException:
TypeError: undefined is not a function
(evaluating '(bridgeConfig.remoteModuleConfig||[]).forEach')
...
createReactContext
ReactInstanceManagerImpl.java:911
access$700
ReactInstanceManagerImpl.java:100
...

(error typed not copied, may contain typo's)

I'm currently evaluating react-native as a platform for a simple app with qr code scanning functionality so I know very little about how to further debug this.

too slow when pop from the scanner page

Hi Thanks for providing this awesome component, I already implemented this into our project, it is working! however we met a problem when running the app on android device, it is too slow when call " this.props.navigator.pop();" on the scanner page. is there any method to improve the performance? thanks very much. will attach some screenshots for your information. the fps is very low.
screenshot_2016-08-01-14-26-43
screenshot_2016-08-01-14-26-47

Best Regards & Thanks
Emily

Warning: Native component for "RNBarcodeScannerView" does not exist

this is similar if not the same to #38 but still applies to my project, tried rnpm link it says Android module react-native-barcodescanner is already linked also I removed android folder and run react-native run-android, still getting this error

react: 15.2.1, react-native: 0.30.0, react-native-barcodescanner: 3.0.1

Doesn't work when nested in a Scrollview or Modal

The camera works fine and scans barcodes until I try to nest the component inside of a ScrollView or in a Modal. While maybe having it inside of modal might not be practical, it would be nice to be able to nest inside of ScrollView and just have it ignore scrolling or something.

Camera crashes app on destroy component

I use the Camera in a ScrollableTabView. If I enable the camera and then remove the component from view (scroll to another page or disable camera scanner) my app crashes.

Works fine in avd emulator but not on device.

"react": "15.2.1",
"react-native": "0.31.0",
"react-native-barcodescanner": "^3.1.1",


I/DEBUG   ( 1892): backtrace:
I/DEBUG   ( 1892):     #00  pc 000206a0  /system/lib/libc.so (__ioctl+8)
I/DEBUG   ( 1892):     #01  pc 0002d117  /system/lib/libc.so (ioctl+14)
I/DEBUG   ( 1892):     #02  pc 0001e20d  /system/lib/libbinder.so (android::IPCThreadState::talkWithDriver(bool)+140)
I/DEBUG   ( 1892):     #03  pc 0001e6f3  /system/lib/libbinder.so (android::IPCThreadState::waitForResponse(android::Parcel*, int*)+42)
I/DEBUG   ( 1892):     #04  pc 0001e8ff  /system/lib/libbinder.so (android::IPCThreadState::transact(int, unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+118)
I/DEBUG   ( 1892):     #05  pc 0001a491  /system/lib/libbinder.so (android::BpBinder::transact(unsigned int, android::Parcel const&, android::Parcel*, unsigned int)+30)
I/DEBUG   ( 1892):     #06  pc 00022ecb  /system/lib/libcamera_client.so
I/DEBUG   ( 1892):     #07  pc 000207e3  /system/lib/libcamera_client.so (android::Camera::stopPreview()+20)
I/DEBUG   ( 1892):     #08  pc 00084c81  /system/lib/libandroid_runtime.so
I/DEBUG   ( 1892):     #09  pc 0001ea90  /system/lib/libdvm.so (dvmPlatformInvoke+116)
I/DEBUG   ( 1892):     #10  pc 0004f1a7  /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+398)
I/DEBUG   ( 1892):     #11  pc 00027f20  /system/lib/libdvm.so
I/DEBUG   ( 1892):     #12  pc 0002f130  /system/lib/libdvm.so (dvmMterpStd(Thread*)+76)
I/DEBUG   ( 1892):     #13  pc 0002c7d4  /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+184)
I/DEBUG   ( 1892):     #14  pc 00061905  /system/lib/libdvm.so (dvmInvokeMethod(Object*, Method const*, ArrayObject*, ArrayObject*, ClassObject*, bool)+392)
I/DEBUG   ( 1892):     #15  pc 00069ac3  /system/lib/libdvm.so
I/DEBUG   ( 1892):     #16  pc 00027f20  /system/lib/libdvm.so
I/DEBUG   ( 1892):     #17  pc 0002f130  /system/lib/libdvm.so (dvmMterpStd(Thread*)+76)
I/DEBUG   ( 1892):     #18  pc 0002c7d4  /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+184)
I/DEBUG   ( 1892):     #19  pc 00061623  /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+338)
I/DEBUG   ( 1892):     #20  pc 0004ad87  /system/lib/libdvm.so
I/DEBUG   ( 1892):     #21  pc 0004e913  /system/lib/libandroid_runtime.so
I/DEBUG   ( 1892):     #22  pc 0004f64d  /system/lib/libandroid_runtime.so (android::AndroidRuntime::start(char const*, char const*)+364)
I/DEBUG   ( 1892):     #23  pc 00001003  /system/bin/app_process
I/DEBUG   ( 1892):     #24  pc 0000e493  /system/lib/libc.so (__libc_init+50)
I/DEBUG   ( 1892):     #25  pc 00000d24  /system/bin/app_process

Camera goes all black when switching application

Hey, first of all, thanks for doing this.

I found that when I open the camera, navigate to another view and then I switch to another app and come back and try to open the camera the screen is all black. But if I open the camera view and then switch and come back the camera still works.

I'm not sure if this is a navigation issue, something regarding not unmounting the component when switching apps, or the plugin itself.

index.android.js

var React              = require('react-native');
var Home               = require('./app/android-components/home');
var CameraHandler      = require('./app/android-components/camera_handler');
var helpers            = require('./app/utils/helpers');

var {
  AppRegistry,
  StyleSheet,
  BackAndroid,
  Navigator
} = React;

var _navigator;

BackAndroid.addEventListener('hardwareBackPress', () => {
    console.log("Pressing back");
    if (_navigator.getCurrentRoutes().length === 1 ) {
        return false;
    }
    _navigator.pop();
    return true;
});

class MyApp extends React.Component {
    _renderScene(route, navigator) {
        _navigator = navigator;
        switch (route.name) {
            case 'Home':
                return (
                    <View style={{flex:1}}>
                        <Home navigator={navigator} />
                    </View>
                )
            case 'Camera':
                return (
                    <View style={{flex:1}}>
                        <CameraHandler navigator={navigator} helpers={helpers} />
                    </View>
                )
        }
    }
    render() {
        return (
            <Navigator
                style={styles.container}
                initialRoute={{
                    name : 'Home',
                    component : Home
                }}
                configureScene={() => Navigator.SceneConfigs.FadeAndroid}
                renderScene={this._renderScene}
            />
        )
    }
}

var styles = StyleSheet.create({
    container: {
        flex: 1,
    },
});

AppRegistry.registerComponent('MyApp', () => MyApp);


home.js

var React  = require('react-native');

var {
    Text,
    View,
    ScrollView,
    TouchableHighlight,
    StyleSheet,
} = React;

class Home extends React.Component{
    openCamera(event){
        this.props.navigator.push({
            name: 'Camera'
        });
    }
    render() {
        return (
            <ScrollView style={{flex:1}}>
                <View style={styles.container}>
                    <View style={styles.header}>
                      <Text style={styles.headerText}>Welcome back!</Text>
                    </View>
                    <View style={styles.subheader}>
                      <Text style={styles.subheaderText}>Click on the button to start the camera</Text>
                    </View>
                    <View style={styles.buttonWrap}>
                        <TouchableHighlight
                            style={styles.button}
                            onPress={this.openCamera.bind(this)}
                            underlayColor="white"
                        >
                        <Text style={styles.buttonText}>SCAN CODE</Text>
                        </TouchableHighlight>
                    </View>
                </View>
            </ScrollView>
        )
    }
};

var styles = StyleSheet.create({
    container: {
        padding: 30,
        alignItems: 'center',
        marginTop: 30
    },
    header:{
        margin:20,
        width:400,
        height:80,
    },
    headerText:{
        fontSize: 28,
        textAlign: 'center',
    },
    subheader:{
        width:200,
        marginBottom:40
    },
    subheaderText:{
        fontSize:20,
        textAlign: 'center'
    },
    buttonWrap: {
        margin:30,
        width:300,
        //width:400,
        height:80,
        borderWidth: 1,
        borderColor: '#999999',
        borderRadius: 2,
        backgroundColor: '#9D9D9D'
    },
    button: {
        textAlign: 'center',
        color: '#ffffff',
        height:80,
    },
    buttonText: {
        fontSize: 16,
        textAlign: 'center',
        marginTop:28,
        marginBottom:28,
    }
});

module.exports = Home;

camera_handler.js

var React          = require('react-native');
var BarcodeScanner = require('react-native-barcodescanner');


class CameraHandler extends React.Component{
  barcodeReceived(e) {
    console.log(`Code is: ${e.data} and the type is ${e.type}`);
  }
  render() {
    return (
      <BarcodeScanner
        onBarCodeRead={this.barcodeReceived.bind(this)}
        style={{ flex: 1 }}
        torchMode='off'
        cameraType='back'
      />
    );
  }
}

module.exports = CameraHandler;

Thanks! :)

Suggestion to make the example easier (Scanner not visible)

Hey, I just tried our the barcode scanner. At first I couldn't get it to work and was confused what my mistake was.

It turned out that the container element did not have "flex: 1" in its styles and therefore apparently had a height of 0 which meant that the barcode scanner wasn't visible at all. I don't know if others will stumble upon this aswell, but just in case, here's how I solved it:

in render():
<View style={styles.container}> <BarcodeScanner onBarCodeRead={this.barcodeReceived} style={{ flex: 1 }} torchMode={this.state.torchMode} cameraType={this.state.cameraType} /> </View>
and the styles:

var styles = StyleSheet.create({ container: { flex: 1, backgroundColor: 'red', } });

There is a big issue on 'resume event' fired

Hi,following code can make my app hang

in file BarcodeScannerView

public void onResume() {
    mPreview.startCamera(); // workaround for reload js
}

First, I open barcode scanner for scanning qrcode,
And then, I close scanner and navigate to another page
Then,when I open camera for taking some pics, and then close camera.
Above code will run and keeping trying to scan qrcode, and then my app hangs

Camera breaks in react-native 0.30.0

Hi all, I tried running the Example project with react-native 0.30.0 and I got this screen. Not sure if this has happened before on other react-native versions.

1

Error on require on react-native 0.16.0-rc

I've just upgraded react-native to 0.16.0-rc and now the barcode scanner is throwing an error on require:

'BarcodeScannerView' has no propType for native prop 'RNBarcodeScannerView.renderToHardwareTextureAndroid' of native type 'boolean'.

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.