首页 > 解决方案 > 不变违规:“无标题”尚未注册。在以下情况下可能会发生这种情况: * Metro(本地开发服务器)从错误的文件夹运行

问题描述

我正计划构建一个扫描仪应用程序。我想测试来自https://www.npmjs.com/package/react-native-qrcode-scanner的给定示例,然后将其集成到我的项目中。基本上我正在尝试测试 2 个应用程序。为了实现这一点,我遇到了这个错误。它说的奇怪的是我的应用程序被命名为“无标题”,但我在 test.json 中将其命名为“测试”。

手机出错

index.js:

/**
 * @format
 */

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';

import * as Test from './Test';
import {name as TestName} from './test.json';

AppRegistry.registerComponent(TestName, () => Test);
/*AppRegistry.registerComponent(appName, () => App);*/

测试.js:

'use strict';

import React, { Component } from 'react';

import {
  AppRegistry,
  StyleSheet,
  Text,
  TouchableOpacity,
  Linking
} from 'react-native';

import QRCodeScanner from 'react-native-qrcode-scanner';
import { RNCamera } from 'react-native-camera';
import App from "./App";

class ScanScreen extends Component {
  onSuccess = e => {
    Linking.openURL(e.data).catch(err =>
      console.error('An error occured', err)
    );
  };

  render() {
    return (
      <QRCodeScanner
        onRead={this.onSuccess}
        flashMode={RNCamera.Constants.FlashMode.torch}
        topContent={
          <Text style={styles.centerText}>
            Go to{' '}
            <Text style={styles.textBold}>wikipedia.org/wiki/QR_code</Text> on
            your computer and scan the QR code.
          </Text>
        }
        bottomContent={
          <TouchableOpacity style={styles.buttonTouchable}>
            <Text style={styles.buttonText}>OK. Got it!</Text>
          </TouchableOpacity>
        }
      />
    );
  }
}

const styles = StyleSheet.create({
  centerText: {
    flex: 1,
    fontSize: 18,
    padding: 32,
    color: '#777'
  },
  textBold: {
    fontWeight: '500',
    color: '#000'
  },
  buttonText: {
    fontSize: 21,
    color: 'rgb(0,122,255)'
  },
  buttonTouchable: {
    padding: 16
  }
});

AppRegistry.registerComponent('default', () => ScanScreen);

测试.json

{
  "name": "Test",
  "displayName": "Test"
}

应用程序.json

{
  "name": "untitled",
  "displayName": "untitled"
}

标签: reactjsreact-native

解决方案


推荐阅读