Javascript 错误:元素类型无效,请检查摄影机的渲染方法
我见过与这个问题相关的类似问题,但我还没能用它们解决我的问题。每当我尝试访问应用程序中的组件时,都会出现此错误 错误:元素类型无效:需要字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。您可能忘记了从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入 检查Javascript 错误:元素类型无效,请检查摄影机的渲染方法,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我见过与这个问题相关的类似问题,但我还没能用它们解决我的问题。每当我尝试访问应用程序中的组件时,都会出现此错误 错误:元素类型无效:需要字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。您可能忘记了从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入 检查摄影机的渲染方法 这是我的相机代码 import React, { Component } from 'react'; import {View} from 'react-native'; import {Came
摄影机的渲染方法
这是我的相机代码
import React, { Component } from 'react';
import {View} from 'react-native';
import {CameraKitCameraScreen} from "react-native-camera-kit";
import Axios from "axios";
import {icons} from "../../../App";
import Geolocation from "react-native-geolocation-service"
class Camera extends Component {
WeatherAPIKey = "";
event;
lat;
lon;
location;
create_form_data = (photo_form_name, photo, body) => {
const data = new FormData();
data.append(photo_form_name, {
name: photo.name,
type: "image/jpeg",
uri: `file://${photo.uri}`
});
Object.keys(body).forEach((key) => {
data.append(key, body[key]);
});
return data;
}
cancel(){
let type = this.props.navigation.getParam("type", "");
let update = this.props.navigation.getParam("update", {});
let job = this.props.navigation.getParam("job", {});
let cancel_func = this.props.navigation.getParam("cancel_func", () => {});
// alert(JSON.stringify(update));
//this.props.navigation.pop();
if(type === "before_img"){
this.props.navigation.pop();
alert("sorry this job cannot be started before you take a picture");
}else if(type === "complete"){
this.props.navigation.pop();
alert("This job cannot be completed nor reviewed wothout a photo");
}else{
this.props.navigation.pop();
}
}
async save_photo(){
let type = this.props.navigation.getParam("type", "");
let update = this.props.navigation.getParam("update", {});
let job = this.props.navigation.getParam("job", {});
let shot_func = this.props.navigation.getParam("shot_func", () => {});
if(type === "after_img"){
if(update){
const data = this.create_form_data("after_image", this.event.image, {});
// alert(JSON.stringify(data));
this.props.upload_after(data, update.job, /*temp*/{uri: `file://${this.event.image.uri}`, name: this.event.image.name} );
//this.setState({after_img: res.uri});
}
}else if(type === "before_img"){
if((await this.props.create_update({update_type: "job start", job_id: job._id, text_content: `You started job "${job.title}"`}))){
const data = this.create_form_data("before_image", this.event.image, {});
this.props.upload_before(data, job._id, /*temp*/{uri: `file://${this.event.image.uri}`, name: this.event.image.name} );
this.props.allow_job_start();
this.props.start_job(job._id, job.started);
shot_func();
}
//this.props.navigation.pop();
// alert("This will be saved as the before image");
}else if(type === "complete"){
const data = this.create_form_data("after_image", this.event.image, {});
this.props.create_update({update_type: "job completion", job_id: job._id, text_content: `You completed job "${job.title}. Here are the Before and after pictures."`});
await this.props.upload_after(data, job._id, /*temp*/{uri: `file://${this.event.image.uri}`, name: this.event.image.name} );
let file = job.image_urls.after[0].url;
shot_func(file);
}else if(type === "profile_img"){
const data = this.create_form_data(type, this.event.image, {});
await this.props.upload_profile_image(data)
}
};
async shoot_photo(event){
this.event = event;
// alert(JSON.stringify(event))
if(event.type === "left"){
this.cancel();
}else if(event.type === "capture"){
this.props.navigation.pop();
//console.log(event);
this.save_photo();
}
}
state = { }
render() {
return (
<View style={{flex:1}}>
<CameraKitCameraScreen
actions={{rightButtonText: "Finish", leftButtonText: "Cancel"}}
onBottomButtonPressed={this.shoot_photo.bind(this)}
flashImages={{
on: icons["camera_flash_on_icon"],
off: icons["camera_flash_off_icon"],
auto: icons["camera_flash_auto_icon"]
}}
cameraFlipImage={icons["camera_flip_icon"]}
captureButtonImage={icons["camera_shoot_icon"]}
/>
</View>
);
}
}
export {Camera}
import React,{Component}来自'React';
从“react native”导入{View};
从“react native camera kit”导入{CameraKitCameraScreen};
从“Axios”导入Axios;
从“../../../App”导入{icons}”;
从“反应本地地理定位服务”导入地理定位
类摄影机扩展组件{
WeatherAPIKey=“”;
事件
lat;
朗;
位置;
创建表单数据=(照片表单名称、照片、正文)=>{
const data=新表单数据();
数据。附加(照片、表格、名称、{
姓名:photo.name,
键入:“图像/jpeg”,
uri:`file://${photo.uri}`
});
Object.keys(body.forEach)((key)=>{
data.append(key,body[key]);
});
返回数据;
}
取消{
让type=this.props.navigation.getParam(“type”,”);
让update=this.props.navigation.getParam(“更新”,{});
让job=this.props.navigation.getParam(“job”,{});
让cancel_func=this.props.navigation.getParam(“cancel_func”,()=>{});
//警报(JSON.stringify(更新));
//this.props.navigation.pop();
如果(类型==“在img之前”){
this.props.navigation.pop();
警报(“抱歉,在拍照之前无法启动此作业”);
}否则如果(类型==“完成”){
this.props.navigation.pop();
警报(“没有照片,无法完成或查看此作业”);
}否则{
this.props.navigation.pop();
}
}
异步保存照片(){
让type=this.props.navigation.getParam(“type”,”);
让update=this.props.navigation.getParam(“更新”,{});
让job=this.props.navigation.getParam(“job”,{});
让shot_func=this.props.navigation.getParam(“shot_func”,()=>{});
如果(类型==“在img之后”){
如果(更新){
const data=this.create_form_data(“在图像之后”,this.event.image,{});
//警报(JSON.stringify(数据));
this.props.upload_after(data,update.job,/*temp*/{uri:`file://${this.event.image.uri}`,name:this.event.image.name});
//this.setState({after_img:res.uri});
}
}else if(类型==“在img之前”){
if((等待此.props.create_update({update_type:“作业开始”,作业id:job.\u id,文本内容:`您已开始作业“${job.title}`}))){
const data=this.create_form_data(“before_image”,this.event.image,{});
this.props.upload_before(数据,作业.\u id,/*temp*/{uri:`file://${this.event.image.uri}`,名称:this.event.image.name});
此.props.allow_job_start();
this.props.start\u作业(job.id,job.start);
shot_func();
}
//this.props.navigation.pop();
//警报(“这将保存为之前的图像”);
}否则如果(类型==“完成”){
const data=this.create_form_data(“在图像之后”,this.event.image,{});
this.props.create_update({update_type:“job completion”,job_id:job.\u id,text_content:`You completed job“${job.title}。以下是前后图片。“`});
等待此.props.upload_之后(数据、作业id、/*temp*/{uri:`file://${this.event.image.uri}`,名称:this.event.image.name});
让file=job.image\u url.after[0].url;
shot_func(文件);
}else if(类型==“配置文件\u img”){
const data=this.create_form_data(type,this.event.image,{});
等待这个。道具。上传图片(数据)
}
};
异步拍摄照片(事件){
this.event=事件;
//警报(JSON.stringify(事件))
如果(event.type==“left”){
这个。取消();
}else if(event.type==“捕获”){
this.props.navigation.pop();
//console.log(事件);
这个。保存照片();
}
}
状态={}
render(){
返回(
);
}
}
导出{Camera}
将CameraKitCameraScreen更改为CameraScreen为我修复了它
render() {
return (
<View style={{flex:1}}>
<CameraScreen
actions={{rightButtonText: "Finish", leftButtonText: "Cancel"}}
onBottomButtonPressed={this.shoot_photo.bind(this)}
flashImages={{
on: icons["camera_flash_on_icon"],
off: icons["camera_flash_off_icon"],
auto: icons["camera_flash_auto_icon"]
}}
cameraFlipImage={icons["camera_flip_icon"]}
captureButtonImage={icons["camera_shoot_icon"]}
/>
</View>
);
}
render(){
返回(
);
}