确定屏幕是什么?

问题描述 投票:1回答:1

好的,所以我有两个屏幕,当qrscanner读取qr导航到InfoScreen时,这一切都很好,但问题是即使屏幕是InfoScreen,如果摄像头指向qr代码,它仍然会扫描。

我的问题是如何检查现在的屏幕应用程序,以便我可以在qrCodeOnReadHandler中编写类似的内容if(!qrscreen){return}

export default class Qr extends Component {
    qrCodeOnReadHandler = ({ data }) => {
        this.props.navigation.navigate("InfoScreen")
    };
}

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>
        );
    }
}
react-native react-native-navigation react-native-navigation-v2
1个回答
1
投票

您可以注册一个事件监听器,当组件聚焦或模糊时触发该事件监听器:

 componentWillMount() {
       this.props.navigation.addListener('willBlur', () =>this.doSomethingOnBlur());
       this.props.navigation.addListener('onFocus', ()=>this.doSomethingOnFocus());
}

你可以在这里找到所有的活动

https://reactnavigation.org/docs/en/navigation-prop.html

© www.soinside.com 2019 - 2024. All rights reserved.