gpt4 book ai didi

react-native - 任务队列 : Error with task: undefined is not an object (evaluating '_this.view._component.measureInWindow' ) in react native

转载 作者:行者123 更新时间:2023-12-04 11:09:00 34 4
gpt4 key购买 nike

我是 native react 的新手,我在处理屏幕导航时遇到了非常简单的演示应用程序这个问题
收到此错误消息
任务队列:任务错误:未定义不是对象(评估“_this.view._component.measureInWindow”)

这是错误的屏幕截图:

enter image description here

这是我的代码
应用程序.js

import React, {Component} from 'react';
import {createStackNavigator} from 'react-navigation';
import HomeActivity from './components/HomeActivity';
import ProfileActivity from './components/ProfileActivity';
const RootStack = createStackNavigator(
{
Home: {
screen: HomeActivity,
},
Profile: {
screen: ProfileActivity,
},
},
{
initialRouteName: 'Home',
},
);
export default class App extends Component {
render() {
return(
<RootStack />
);
}
}


主页Activity.js

import React, {Component} from 'react';
import {StyleSheet, Text, View, Button} from 'react-native';
class HomeActivity extends Component {
static navigationOptions = {
title: 'Home',
headerStyle: {backgroundColor: '#03A9F4'},
headerTintColor: '#fff',
headerTitleStyle: {fontWeight: 'bold'},
};
render() {
return (
<View style={styles.container}>
<Text style={styles.headerText}>Home Activity</Text>
<Button
title="Go to Profile Activity"
onPress={() => this.props.navigation.navigate('Profile')}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
headerText: {
fontSize: 20,
textAlign: 'center',
margin: 10,
fontWeight: 'bold',
},
});
export default HomeActivity;


ProfileActivity.js

import React, {Component} from 'react';
import { StyleSheet, Text, View, Button} from 'react-native';
class ProfileActivity extends Component {
static navigationOptions = {
title: 'Profile',
headerStyle: {backgroundColor: '#73C6B6'},
};
render() {
return (
<View style={styles.container}>
<Text style={styles.headerText}>Profile Activity</Text>
<Button
title="Go to Home"
onPress={() => this.props.navigation.navigate('Home')}
/>
<Text style={styles.headerText}>Create a New Profile Screen </Text>
<Button
title="Go to new Profile"
onPress={() => this.props.navigation.push('Profile')}
/>
<Text style={styles.headerText}> Go Back </Text>
<Button
title="Go Back"
onPress={() => this.props.navigation.goBack()}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
headerText: {
fontSize: 20,
textAlign: 'center',
margin: 10,
fontWeight: 'bold',
},
});
export default ProfileActivity;



 "dependencies": {
"@react-native-community/masked-view": "^0.1.7",
"@react-navigation/native": "^5.1.4",
"react": "16.11.0",
"react-native": "0.62.0",
"react-native-gesture-handler": "^1.6.1",
"react-native-paper": "2.1.3",
"react-native-reanimated": "^1.7.1",
"react-native-safe-area-context": "^0.7.3",
"react-native-screens": "^2.4.0",
"react-navigation": "2.6.2"
}

最佳答案

这是因为 react-navigate 使用旧版本的 SafeView。
您有两种方式:
1. 长路漫漫:需要迁移到 v5 react-navigation v4 to v5 migration .
对我来说这很困难,并且会在我的项目中进行太多更改。
2. 非常快速和丑陋的解决方案:
转到目录 YOUR_PROJECT_PATH/node_modules/react-native-safe-area-view/index.js
并更新:
来自:

this.view._component.measureInWindow((winX, winY, winWidth, winHeight) => {
至:
this.view.getNode().measureInWindow((winX, winY, winWidth, winHeight) => {
你可以试试我的 fork : "react-navigation": "git://github.com/Snailapp/react-navigation.git#2.18.5", 更新
修复了不推荐使用的 currentFocusedField 警告:
git://github.com/Snailapp/react-navigation.git#2.18.6

关于react-native - 任务队列 : Error with task: undefined is not an object (evaluating '_this.view._component.measureInWindow' ) in react native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60944091/

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