HarvestProfit / react-native-rectangle-scanner

React Native Document/Rectangle Scanner
MIT License
199 stars 62 forks source link

focus() does not seem to work #70

Closed mohity777 closed 4 years ago

mohity777 commented 4 years ago

Hi, i have made an overlay over the camera using touchableOpacity and onPress i am calling camRef.current.focus(). But it does not focus. PLs help===>

<View style={{backgroundColor: 'rgba(0, 0, 0, 0)', flex: 1}}> <Scanner // onDeviceSetup={onDeviceSetup} onPictureProcessed={handleOnPictureProcessed} ref={camRef} style={{flex: 1}} enableTorch={state.flashEnabled} onTorchChanged={({enabled}) => setState((prev) => ({...prev, flashEnabled: enabled})) } filterId={state.filterId} /> <TouchableOpacity style={{ bottom: 0, flex: 1, left: 0, position: 'absolute', right: 0, top: 0, }} onPress={() => { console.log('hh'); camRef.current.focus(); }} />

humphreyja commented 4 years ago

@mohity777 hi currently there is no ability to focus manually. Only auto focus works. Please feel free to add a PR with this if you can!

mohity777 commented 4 years ago

But why is this method mentioned in Readme then??

humphreyja commented 4 years ago

@mohity777 whoops! My bad, I totally forgot I added that! Ok so yes that method does call the android autoFocus method. (On iOS the focus mode is continuously autofocusing and on supporting android phones it does this too). Not sure why it is not focusing? What phone are you trying this on? There's a chance the autoFocus settings may not be supported on your device.

mohity777 commented 4 years ago

no autofocus does work. But when i bring the camera close to the object it focuses then goes out of focus immediately . So i thought using focus() method. But when i use camRef.current.focus() . It completely stops working .

humphreyja commented 4 years ago

Hmm so that would mean that it is trying to auto focus. By calling the focus method, it tries to trigger the auto focus method. That is also called right before capturing an image. You might want to double check on another device but this really sounds like something is broken on the android side. If autofocus isn't working but it still tries to autofocus then Android probably isn't trying to autofocus correctly.