Reputation: 159
Ok, so I have two screens, when qrscanner reads the qr it navigates to InfoScreen, and thats all fine, but the problem is that even if the screen is InfoScreen, if camera was pointed to qr code it still scans.
My question is how can i check on what screen app is now so i can write something like this in qrCodeOnReadHandler if(!qrscreen){return}
export default class Qr extends Component {
qrCodeOnReadHandler = ({ data }) => {
this.props.navigation.navigate("InfoScreen")
};
}
and
class InfoScreen extends Component {
render() {
return (
<View style={styles.buttons}>
<TouchableOpacity
style={styles.buttonStyle}
onPress={() => this.props.navigation.goBack()}
>
<Text style={styles.textStyle}>Back</Text>
</TouchableOpacity>
</View>
);
}
}
Upvotes: 1
Views: 106
Reputation: 40
You can register an event listener which fires when the component focuses or blurs:
componentWillMount() {
this.props.navigation.addListener('willBlur', () =>this.doSomethingOnBlur());
this.props.navigation.addListener('onFocus', ()=>this.doSomethingOnFocus());
}
You can find all the events here
https://reactnavigation.org/docs/en/navigation-prop.html
Upvotes: 1