Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flash Light not working #518

Closed
avneeshkumar1 opened this issue Jan 24, 2023 · 12 comments
Closed

Flash Light not working #518

avneeshkumar1 opened this issue Jan 24, 2023 · 12 comments

Comments

@avneeshkumar1
Copy link

Hi team thanks for this awesome library
I am using the below code for scan QR code
render() {
return (

<Camera
ref={this.camera}
style={{flex: 1}}
cameraType={CameraType.Back} // optional
flashMode="on" // on/off/auto(default)
focusMode="on" // off/on(default)
zoomMode="on" // off/on(default)
torchMode="off" // on/off(default)
ratioOverlay="1:1" // optional
ratioOverlayColor="#77" // optional
resetFocusTimeout={0}
resetFocusWhenMotionDetected={false}
saveToCameraRole={false} // iOS only
scanBarcode={true} // optional
showFrame={true} // Barcode only, optional
laserColor="red" // Barcode only, optional
frameColor="yellow" // Barcode only, optional
surfaceColor="blue" // Barcode only, optional
onReadCode={(event) => console.log(event.nativeEvent.codeStringValue)}
/>

);
}
Scanning is working fine
but flash light not working even pass torchMode="on" but still not working. can someone suggest me what is wrong with code.

@yousrasd
Copy link
Contributor

Running into the same issue on Android device, with both torchMode="on" and flashMode="on"

@yousrasd
Copy link
Contributor

yousrasd commented Jan 25, 2023

After some investigation, seems like the setFlashMode is called before the imageCapture is even initialized. So flash mode ends up never being set.

Screen.Recording.2023-01-25.at.11.41.11.AM.mov

the imageCapture is set in the bindCameraUseCases which is called by setupCamera. The flash mode is set before the setupCamera is invoked. So it ends up finding no imageCapture (imageCapture is null), so it just skips setting the flash mode to on.

@yousrasd
Copy link
Contributor

yousrasd commented Feb 1, 2023

@avneeshkumar1 I opened a PR to expose a setTorchMode method to unblock us. #523
Hopefully it will be merged soon

@avneeshkumar1
Copy link
Author

yousrasd is that pr merged?

@yousrasd
Copy link
Contributor

yousrasd commented Feb 2, 2023

@avneeshkumar1 no not yet, waiting for a maintainer to review the PR and merge it.

@ajiehatajie
Copy link

same issue cannot flashlight and camera type is not working

@yousrasd
Copy link
Contributor

yousrasd commented Feb 7, 2023

@ajiehatajie please can you comment on the PR #523 that you need those changes too? Im still waiting for the PR to be reviewed :(

@DavidBertet
Copy link
Contributor

DavidBertet commented Jul 6, 2023

Be careful, flashMode is not the same as torchMode. Seems like @avneeshkumar1 has an issue turning the torch on by default

First, your code is right. However it doesn't work because of a timing issue.

Timing should be fixed on the library, but a simple workaround is to delay setting the torchMode slightly so the camera is setup while torch is turned on.

import React, { useEffect, useState } from 'react';
import { StyleSheet } from 'react-native';
import { CameraType, TorchMode } from '../../src/types';
import { Camera } from '../../src';

const CameraWithTorchOn = () => {
  // Start with off
  const [torchMode, setTorchMode] = useState<TorchMode>('off');

  // When the components mounts
  useEffect(() => {
    // Delay slightly setting the torch to 'on'
    setTimeout(() => {
      setTorchMode('on');
    }, 500);
  }, []);

  return <Camera torchMode={torchMode} cameraType={CameraType.Back} style={styles.cameraStyle} />;
};

const styles = StyleSheet.create({
  cameraStyle: {
    width: '100%',
    height: '100%',
  },
});

export default CameraWithTorchOn;

@scarlac
Copy link
Collaborator

scarlac commented Aug 14, 2023

Outdated. Closing since changes have been made since then, and it seems there might have been a misunderstanding of torchMode vs flashMode.

@scarlac scarlac closed this as completed Aug 14, 2023
@dleavittpmc
Copy link

Not sure why this was closed as this is still an issue (if the user was talking about torchMode). I used the workaround provided by @DavidBertet and it was wonderful.

To clarify, the issue is happening when attempting a barcode / QR code scan and attempting to turn on torchMode. torchMode flashes on for a brief moment before turning off again.

@prashant-logiedgesystems

flash and torch is working only when state is toggling manually
it is not working on static input or during capturing image

@prashant-logiedgesystems

any solution for handling this problem

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

No branches or pull requests

7 participants