我使用以下代码段创建了一个新按钮,但得到"java.lang.String cannot be cast to com.facebook.react.uimanager.AccessibilityDelegateUtil$AccessibilityRole“error.我做了一些挖掘,似乎这是由于React Native 0.57.3不稳定导致的错误,所以我从大量论坛帖子中建议将其降级到0.57.1。但是错误仍然存在,所以如果你能看一下我的代码并给我一些建议,我将不胜感激。
My code:
import React, {Component} from 'react';
import {StyleSheet, Text, View} from 'react-native';
import FetchLocation from './components/FetchLocation';
export default class App extends React.Component{
getUserLocationHandler = () => {
}
render() {
return (
<View style={styles.container}>
<FetchLocation onGetLocation={this.getUserLocationHandler} />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
也是我的代码:
import React from 'react';
import { Button } from 'react-native';
const fetchLocation = props => {
return (
<Button title="Get Location" onPress={props.onGetLocation}/>
);
};
export default fetchLocation;
这是错误的图片:
发布于 2018-10-22 03:22:37
你的版本是0.57,而Error when trying to use Button in react-native说它可以在0.55版本中工作。最好试一试。
编辑
我自己尝试了一下,找到了这个解决方案。将react-native降级到57.2,并确保将其他依赖项降级,如下所示。
"dependencies": {
"react": "16.5.0",
"react-native": "0.57.2"
},
"devDependencies": {
"babel-jest": "23.6.0",
"jest": "23.6.0",
"metro-react-native-babel-preset": "0.47.1",
"react-test-renderer": "16.5.0"
}
然后尝试删除node_modules并执行npm install & npm start -- --reset-cache
https://stackoverflow.com/questions/52911575
复制相似问题