Skip to content
This repository has been archived by the owner on May 12, 2023. It is now read-only.

Please provide flash function #117

Open
Sam1141968878 opened this issue Jul 5, 2018 · 6 comments
Open

Please provide flash function #117

Sam1141968878 opened this issue Jul 5, 2018 · 6 comments

Comments

@Sam1141968878
Copy link

happening:
Please add the flash function, it is too dark at night.Thank!

Build details:
"react-native": "0.55.3",
"react-native-camera": "^1.1.4",
"react-native-qrcode-scanner": "^1.0.1",
2018/7/5

@alz10
Copy link

alz10 commented Jul 22, 2018

Here's a fix for that:

  1. Go to node_modules and find react-native-qrcode-scanner folder and open index.js
  2. find _renderCamera() and then on the Camera component, change this
      <Camera
          type={cameraType}
          flashMode={this.props.flashMode} //this is the only code you need to change
          style={[styles.camera, this.props.cameraStyle]}
          onBarCodeRead={this._handleBarCodeRead.bind(this)}
        >
          {this._renderCameraMarker()}
      </Camera>

if the above code doesn't makes sense to you, you can copy paste this code and replace the _renderCamera()

_renderCamera() {
    const { notAuthorizedView, pendingAuthorizationView, cameraType } = this.props
    const { isAuthorized, isAuthorizationChecked } = this.state
    if (isAuthorized) {
      if (this.props.fadeIn) {
        return (
          <Animated.View
            style={{
              opacity: this.state.fadeInOpacity,
              backgroundColor: 'transparent'
            }}>
            <Camera 
              style={[styles.camera, this.props.cameraStyle]} 
              onBarCodeRead={this._handleBarCodeRead.bind(this)}
              type={this.props.cameraType}
            >
              {this._renderCameraMarker()}
            </Camera>
          </Animated.View>
        )
      }
      return (
        <Camera
          type={cameraType}
          flashMode={this.props.flashMode}
          style={[styles.camera, this.props.cameraStyle]}
          onBarCodeRead={this._handleBarCodeRead.bind(this)}
        >
          {this._renderCameraMarker()}
        </Camera>
      )
    } else if (!isAuthorizationChecked) {
      return pendingAuthorizationView
    } else {
      return notAuthorizedView
    }
  }

===================================================================

  1. last step is to you use the Flash on your project

import QRCodeScanner from "react-native-qrcode-scanner";
import { RNCamera } from "react-native-camera";

     <QRCodeScanner
         flashMode={RNCamera.Constants.FlashMode.torch}
     />

Check this documentation about Flash on how you're going to turn it off and on

@Sam1141968878
Copy link
Author

@Albert0405 Thank you. I'll try,It helps me a lot!

@asantos00
Copy link

May I submit a PR with this change?

@moaazsidat
Copy link
Owner

@Albert0405 good stuff! @asantos00 That'd be awesome!

@asantos00
Copy link

#112 already being done by someone here :)

@kusPB
Copy link

kusPB commented Mar 31, 2023

That's good

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants