undefined is not an object (evaluating 'this.props.navigator.push') while QRcode reading library

最后都变了- 提交于 2020-01-07 06:25:35

问题


I try to read QRcode with react native then I install library

and this is my code

  'use strict';

    var React = require('react-native');
    var {
      AppRegistry,
      StyleSheet,
      Text,
      View,
      TouchableOpacity,
      NavigatorIOS,
    } = React;

    var QRCodeScreen = require('./QRCodeScreen');   

  var cameraApp = React.createClass({
      render: function() {
        return (
          <NavigatorIOS
            style={styles.container,{ width:100,height:500}}
            initialRoute={{
              title: 'Index',
              backButtonTitle: 'Back',
              component: Index,
            }}
          />        
        );
      }
    });    

    var Index = React.createClass({        
      render: function() {
        return (
          <View style={styles.contentContainer}>
            <TouchableOpacity onPress={this._onPressQRCode} >
              <Text>Read QRCode</Text>
            </TouchableOpacity>
          </View>
        );
      },        
      _onPressQRCode: function() {
        this.props.navigator.push({
          component: QRCodeScreen,
          title: 'QRCode',
          passProps: {
            onSucess: this._onSucess,
          },
        });
      },        
      _onSucess: function(result) {
        console.log(result);
      },

    });           


    var styles = StyleSheet.create({
      container: {
        flex: 1,
        backgroundColor: '#F5FCFF',        
      },
      contentContainer: {
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center',
      }
    });

    AppRegistry.registerComponent('MyFirstReactapril', () => cameraApp);

but I get this Error undefined is not an object (evaluating 'this.props.navigator.push')

and I don't know what is wrong with it , please help. Or is there any library can read QRCode and gives me the link or string?


回答1:


NavigatorIOS component works only in iOS. You need to use Navigator component which will work in both Android and iOS.



来源:https://stackoverflow.com/questions/37690162/undefined-is-not-an-object-evaluating-this-props-navigator-push-while-qrcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!