Javascript 反应本地随机错误:Can';在30-90秒后找不到可变图像

Javascript 反应本地随机错误:Can';在30-90秒后找不到可变图像,javascript,reactjs,react-native,react-native-ios,Javascript,Reactjs,React Native,React Native Ios,因此,我正在使用 反应本机-最新 MobX和MobX反应-最新 Firebase-最新版本 我的应用程序运行良好。但是,我可以让应用程序闲置或随意使用它,30-90秒后,我就会因为这个错误而出现红屏。它不是非常具体的什么文件出错!我如何调试这个 Firebase.js export function getFeed(db,id,callback){ db.collection("posts").where("userId", "==", id) .get() .th

因此,我正在使用

  • 反应本机-最新
  • MobX和MobX反应-最新
  • Firebase-最新版本
我的应用程序运行良好。但是,我可以让应用程序闲置或随意使用它,30-90秒后,我就会因为这个错误而出现红屏。它不是非常具体的什么文件出错!我如何调试这个

Firebase.js

export function getFeed(db,id,callback){
    db.collection("posts").where("userId", "==", id)
    .get()
    .then(function (querySnapshot) {
        callback(true,querySnapshot)
    })
    .catch(function (error) {
        callback(false)
        console.log("Error getting documents: ", error);
    });
}
List.js

import React, { Component } from 'react';
import {
    Platform,
    StyleSheet,
    Text,
    View,
    TouchableOpacity,
    FlatList,
    ActivityIndicator,
    RefreshControl
} from 'react-native';
import Post from './Post';
import Spinner from 'react-native-spinkit';
import { Icon } from 'react-native-elements';
import { getFeed } from '../../network/Firebase';
import { observer, inject } from 'mobx-react';

@inject('mainStore')
@observer export default class List extends Component {
    constructor(props) {
        super(props)
        this.state = {
            dataSource: [],
            initialLoad: true,
            refreshing: false
        }
        this.getData = this.getData.bind(this)
    }

    componentWillMount() {
        this.getData()
    }

    getData() {
        this.setState({
            refreshing: true
        })
        getFeed(this.props.screenProps.db, this.props.mainStore.userData.id, (status, res) => {
            let tempArray = []
            let counter = 0
            res.forEach((doc) => {
                let tempObj = doc.data()
                doc.data().user
                    .get()
                    .then((querySnapshot) => {
                        tempObj.userData = querySnapshot.data()
                        tempArray.push(tempObj)
                        counter = counter + 1
                        if (counter === res.docs.length - 1) {
                            this.setState({
                                dataSource: tempArray,
                                initialLoad: false,
                                refreshing: false
                            })
                        }
                    })
            });
        })
    }


    renderRow = ({ item }) => {
        return (
            <Post item={item} />
        )
    }

    render() {
        if (this.state.initialLoad) {
            return (
                <View style={styles.spinner}>
                    <Spinner isVisible={true} type="9CubeGrid" size={40} color="white" />
                </View>
            )
        } else {
            return (
                <FlatList
                    data={this.state.dataSource}
                    extraData={this.state}
                    keyExtractor={(_, i) => i}
                    renderItem={(item) => this.renderRow(item)}
                    refreshControl={
                        <RefreshControl
                            refreshing={this.state.refreshing}
                            onRefresh={this.getData}
                        />
                    }
                />
            );
        }
    }
}

const styles = StyleSheet.create({
    spinner: {
        marginTop: 30,
        alignItems: 'center'
    }
});
import React,{Component}来自'React';
进口{
平台,
样式表,
文本,
看法
可触摸不透明度,
平面列表,
活动指示器,
刷新控制
}从“反应本机”;
从“./Post”导入Post;
从“react native spinkit”导入微调器;
从“react native elements”导入{Icon};
从“../../network/Firebase”导入{getFeed};
从“mobx react”导入{observer,inject};
@注入(‘主干’)
@观察者导出默认类列表扩展组件{
建造师(道具){
超级(道具)
此.state={
数据源:[],
initialLoad:true,
刷新:错误
}
this.getData=this.getData.bind(this)
}
组件willmount(){
这个文件名为getData()
}
getData(){
这是我的国家({
令人耳目一新:没错
})
getFeed(this.props.screenProps.db,this.props.mainStore.userData.id,(status,res)=>{
让tempArray=[]
设计数器=0
res.forEach((doc)=>{
设tempObj=doc.data()
doc.data().user
.get()
.然后((querySnapshot)=>{
tempObj.userData=querySnapshot.data()
temparay.push(tempObj)
计数器=计数器+1
if(计数器===res.docs.length-1){
这是我的国家({
数据源:tempArray,
初始加载:false,
刷新:错误
})
}
})
});
})
}
renderRow=({item})=>{
返回(
)
}
render(){
if(this.state.initialLoad){
返回(
)
}否则{
返回(
i}
renderItem={(项)=>this.renderRow(项)}
刷新控制={
}
/>
);
}
}
}
const styles=StyleSheet.create({
微调器:{
玛金托普:30,
对齐项目:“中心”
}
});
Post.js

import React, { Component } from 'react';
import {
    Platform,
    StyleSheet,
    Text,
    View,
    TouchableOpacity,
    Image
} from 'react-native';
import moment from 'moment';
import { Icon } from 'react-native-elements';

export default class Post extends React.PureComponent {
    render() {
        let today = moment()
        let date = this.props.item.date
        if(today.diff(date, 'days') < 5){
            date = moment(date).startOf('day').fromNow()
        }else{
            date = moment(date).format('DD MMM YYYY, h:mm a')
        }
        return (
            <View
                style={styles.container}
            >
                <View style={styles.top}>
                    <Image style={styles.profile} source={{uri: this.props.item.userData.image}} />
                    <Text style={styles.title}>{this.props.item.userData.firstName+' '+this.props.item.userData.lastName}</Text>
                </View>
                <View style={styles.descriptionContainer}>
                    <Text style={styles.description}>{this.props.item.description}</Text>
                </View>
                <View style={styles.imageContainer}>
                    <Image style={styles.image} source={{uri: this.props.item.image}} />
                </View>
                <TouchableOpacity style={styles.commentsContainer}>
                    <View style={styles.timeFlex}>
                        <Text style={styles.title}>{date}</Text>
                    </View>
                    <View style={styles.commentFlex}>
                        <Text style={styles.title}>Comments (12)</Text>
                    </View>
                </TouchableOpacity>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    title: {
        color: 'white',
        backgroundColor: 'transparent'
    },
    timeFlex: {
        flex: 0.5,
        alignItems: 'flex-start'
    },
    commentFlex: {
        flex: 0.5,
        alignItems: 'flex-end'
    },
    profile: {
        width: 40,
        height: 40,
        borderRadius: 20,
        marginRight: 10
    },
    descriptionContainer: {
        marginBottom: 10,
        marginHorizontal: 15,
    },
    description: {
        color: 'rgba(255,255,255,0.5)'
    },
    commentsContainer: {
        marginBottom: 10,
        alignItems: 'flex-end',
        marginHorizontal: 15,
        flexDirection: 'row'
    },
    imageContainer: {
        marginBottom: 10,
        marginHorizontal: 15,
        height: 180
    },
    image: {
        height: '100%',
        width: '100%'
    },
    top: {
        justifyContent: 'flex-start',
        margin: 10,
        marginLeft: 15,
        flexDirection: 'row',
        alignItems: 'center'
    },
    container: {
        margin: 10,
        backgroundColor: '#243c5e',
        borderRadius: 10,
        shadowColor: 'black',
        shadowOffset: {
            width: 2,
            height: 1
        },
        shadowRadius: 4,
        shadowOpacity: 0.3
    }
});
import React,{Component}来自'React';
进口{
平台,
样式表,
文本,
看法
可触摸不透明度,
形象
}从“反应本机”;
从“力矩”中导入力矩;
从“react native elements”导入{Icon};
导出默认类Post扩展React.PureComponent{
render(){
让今天=时刻
让日期=this.props.item.date
如果(今天差异(日期,'天')<5){
日期=时刻(日期).startOf('day').fromNow()
}否则{
日期=时刻(日期)。格式('DD-MMM-YYYY,h:mm-a')
}
返回(
{this.props.item.userData.firstName+''+this.props.item.userData.lastName}
{this.props.item.description}
{date}
评论(12)
);
}
}
const styles=StyleSheet.create({
标题:{
颜色:'白色',
背景颜色:“透明”
},
timeFlex:{
弹性系数:0.5,
alignItems:“灵活启动”
},
commentFlex:{
弹性系数:0.5,
对齐项目:“柔性端”
},
简介:{
宽度:40,
身高:40,
边界半径:20,
marginRight:10
},
描述容器:{
marginBottom:10,
marginHorizontal:15,
},
说明:{
颜色:“rgba(255255,0.5)”
},
评论联系人:{
marginBottom:10,
对齐项目:“柔性端”,
marginHorizontal:15,
flexDirection:“行”
},
图像容器:{
marginBottom:10,
marginHorizontal:15,
身高:180
},
图片:{
高度:“100%”,
宽度:“100%”
},
顶部:{
justifyContent:“flex start”,
差额:10,
marginLeft:15,
flexDirection:'行',
对齐项目:“中心”
},
容器:{
差额:10,
背景颜色:“#243c5e”,
边界半径:10,
阴影颜色:“黑色”,
阴影偏移:{
宽度:2,
身高:1
},
阴影半径:4,
阴影不透明度:0.3
}
});

您是否正在调用api?调用Firestore是。但这种情况发生在空转之后。我可以离开应用程序1分钟,应用程序可以随机出现红屏。请你也发布代码好吗?编辑了帖子。谢谢。你找到解决办法了吗?