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

Black screen after scanning a qr code #161

Closed
GaneshSaiKumar opened this issue Jan 10, 2019 · 6 comments
Closed

Black screen after scanning a qr code #161

GaneshSaiKumar opened this issue Jan 10, 2019 · 6 comments

Comments

@GaneshSaiKumar
Copy link

GaneshSaiKumar commented Jan 10, 2019

@moaazsidat @mamodom @mjgallag

What's happening?

after scanning a qr code successfully, I'm redirecting to other screen.
when i come back to qr code scanning screen, cam is blacked out.

How can it be reproduced?

add a qr code scanner screen and other screen in a tab nav bar

Build details?

version: react-native-qrcode-scanner - 1.1.2
android: 7.0
react-native: 57

@GaneshSaiKumar
Copy link
Author

I think it is issue from RNcamera itself!

@GaneshSaiKumar
Copy link
Author

react-native-camera/react-native-camera#1686 (comment)

` componentDidMount() {
const { navigation } = this.props;
navigation.addListener('willFocus', () =>
this.setState({ focusedScreen: true })
);
navigation.addListener('willBlur', () =>
this.setState({ focusedScreen: false })
);
}

render() {
const { hasCameraPermission, focusedScreen } = this.state;
if (hasCameraPermission === null) {
return ;
} else if (hasCameraPermission === false) {
return No access to camera;
} else if (focusedScreen){
return (this.cameraView());
} else {
return ;
}
}`

this solved my issue.

still the appearance of camera is flicker, using animated view in react-native-qrcode-scanner

@GaneshSaiKumar
Copy link
Author

GaneshSaiKumar commented Jan 11, 2019

initial screen itself is freezing with blank black screen instead of camera interface
@moaazsidat @matthewconstantine
is there a way out?

@paakcmd
Copy link

paakcmd commented Mar 4, 2019

initial screen itself is freezing with blank black screen instead of camera interface
@moaazsidat @matthewconstantine
is there a way out?

I think your camera component never remount after the first usage. The easiest way to fix is to give the component the unique value every time you rout to the component.
Actions.scanner({unique: Date.now() })

then I added some useless actions to the component to double make sure that it really rerendered like this

constructor(props) {
super(props);
this.state = {unique: ''}
}

componentDidMount() {
this.setState({unique: this.props.unique})
}

and now it works 10 out of 10 times

@j0nd0n7
Copy link

j0nd0n7 commented Mar 26, 2019

This issue is from RNCamera, and its solution is documented here:
https://github.com/react-native-community/react-native-camera/blob/master/docs/react-navigation.md

The solution is for react-navigation however a similar approach could be implemented with other navigation packages (like react-native-navigation using componentDidAppear and componentDidDisappear.

mnzaki added a commit to jolocom/smartwallet-app that referenced this issue Jul 15, 2019
infinitered/ignite-andross#277
moaazsidat/react-native-qrcode-scanner#161
moaazsidat/react-native-qrcode-scanner#177
moaazsidat/react-native-qrcode-scanner#136
react-native-camera/react-native-camera#1797
react-native-camera/react-native-camera#1686
react-native-camera/react-native-camera#1686
react-navigation/redux-helpers#87
react-navigation/redux-helpers#60
react-navigation/redux-helpers#53
https://www.youtube.com/watch?v=CnQ8N1KacJc

Fixes #1326

The navigation actions were turned into ThunkActions and now directly
call react-navigation's navigator.dispatch, which handles state
internally

Usages of the navigationActions were fixed

Also QRcodeScanner was cleaned up a bit and hacked to properly re-enable
the camera by re-rendering it (so it gets remounted). Now camera works
again if you press back after scanning a QR code.
@AzranAzwer
Copy link

Thank you @j0nd0n7 for the link...

`import { useIsFocused } from '@react-navigation/core';

export const Component = () => {
const isFocused = useIsFocused();

// ...

if (hasCameraPermission === false) {
return No access to camera;
} else if (hasCameraPermission !== null && isFocused) {
return ;
} else {
return null;
}
}
`

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