【发布时间】:2017-03-26 21:32:53
【问题描述】:
具体错误是“Route 'Camera' should declare a screen”。
我有 index.js,它导入 Camera.js 并渲染相机组件。 Camera.js 导入 router.js,它导入我所有的屏幕并创建一个 StackNavigator。我是 React 新手,所以可能有些东西我不理解。这是代码...
Index.js
import React, { Component } from 'react';
import { CameraView } from './screens/Camera'
class App extends Component {
render() {
return <CameraView />;
}
}
export default App;
Camera.js
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Button,
} from 'react-native';
import { AppStack } from '../config/router';
....
export default class CameraView extends Component {
viewProducts = () => {
this.props.navigation.navigate('Products');
};
render() {
const { navigate } = navigation;
return (
<View style={styles.container}>
<Camera
ref={(cam) => {
this.camera = cam;
}}
style={styles.preview}
aspect={Camera.constants.Aspect.fill}
onBarCodeRead={this.readBarcode}>
<Button
onPress={() => this.viewProducts}
title="Products"
/>
</Camera>
</View>
);
}
}
Router.js
import React from 'react';
import { StackNavigator } from 'react-navigation';
import { Icon } from 'react-native-elements';
import Products from '../screens/Products';
import ProductDetail from '../screens/ProductDetail';
import CameraView from '../screens/Camera';
export const Root = StackNavigator({
Camera: {
screen: CameraView,
},
ProductDetail: {
screen: ProductDetail,
navigationOptions: {
title: ({ state }) => `${state.params.name}}`
},
},
Products: {
screen: Products,
navigationOptions: {
title: 'Products',
},
},
});
我在这里导入 CameraView 并将其用作我的相机路线的屏幕。 CameraView 不被视为屏幕吗?谢谢。
【问题讨论】:
-
如果有人能提供帮助,仍在寻找答案。
标签: javascript reactjs react-native react-router