gpt4 book ai didi

javascript - native 基础 toast - TypeError : TypeError: TypeError: null is not an object (evaluating 'this.toastInstance._root.getModalState' )

转载 作者:行者123 更新时间:2023-11-29 02:23:23 31 4
gpt4 key购买 nike

我正在使用 React Native 构建移动应用程序。我面临 Nativ Base Toast 问题。当我第一次加载应用程序然后导航到工单状态时,如果我返回带有 android 后退按钮的主页,则会出现错误弹出窗口。

下面是我的代码和错误截图。

注意 - 并非每次都会出现此错误。

如有任何帮助,我们将不胜感激。

提前致谢

enter image description here

Home.js 代码(在应用程序加载时呈现)

  

import React, { Component } from 'react';
import { createDrawerNavigator , tabBarOptions, StackNavigator} from 'react-navigation';
import Header from './Header';
import Request from './Request';
import Navigation from './Navigation';
import TicketStatus from './TicketStatus/TicketStatus';

const RootStack = StackNavigator(
{
Home: { screen: Request },
Navigation: { screen: Navigation },
TicketStatus: { screen: TicketStatus },
},
{
headerMode: 'none',
navigationOptions: {
headerVisible: false,
}
}
);
RootStack.navigationOptions = {
header: null
}
export default RootStack;

TicketStatus.js code

export default  class TicketStatus extends Component {
constructor(props){
super(props)
this.state = {
allTickets : [{ name:'Jones Residence', number: '12343534325', classs:'active'},{name:'Rex Bell Elementary', number: '12343534325', classs:'pending' },{name:'CitiBank Offic', number: '123435', classs:'expired' }]
};
}
_fetchTickets(token)
{
if(this.mounted) {
this.setState({
isloading: true
});
}
fetch(config.BASE_URL+'alltickets?api_token='+token,{
method: 'GET',
headers: {
'Authorization': 'Bearer ' + token,
}
})
.then((response) => response.json())
.then((res) => {
if(this.mounted) {
if(res.status == 1)
{
this.setState({
allTickets: res.data,
});
}
else if(res.status == 0)
{
Toast.show({
text: res.message,
buttonText: "Okay",
duration: 5000,
type: "danger"
})
}
this.setState({
isloading: false,
});
}
}).catch(err => {
if(this.mounted) {
Toast.show({
text: err,
buttonText: "Okay",
duration: 5000,
type: "danger"
})
}
}).done();
}
componentDidMount(){
this.mounted = true;
this._fetchTickets(config.token);
}
componentWillUnmount(){
this.mounted = false;
Toast.hide();
Toast.toastInstance = null;
}
renderTickets = () => {
return (
<Content style={{height:300, backgroundColor:"#FFBC42", borderRadius:10}}>
<ScrollView>
{
this.state.allTickets.map((option, i) => {
return (
<TouchableOpacity key={i} >
<View>
<Text>{option.number} / {option.name}</Text>
</View>
</TouchableOpacity>
)
})
}
</ScrollView>
</Content>
)
}
render() {
return (
<Root>
<Container>
<Header {...this.props}/>
<ScrollView>
<Content padder>
<H1 style={styless.ticket_req}>Check the Status of a Ticket</H1>
{this.renderTickets()}
</Content>
</ScrollView>
{this.state.isloading && (
<Loader />
)}
</Container>
</Root>
);
}
}

最佳答案

要使 Toast 正常工作,您需要将最顶层的组件包装在 <Root> 中来自 native 基础。

<Root>
<AppNavigator />
</Root>

关于javascript - native 基础 toast - TypeError : TypeError: TypeError: null is not an object (evaluating 'this.toastInstance._root.getModalState' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53719014/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com