制作一个简单的本机程序时,我无法使用<Button>
组件。我在react-native run-android
之后总是得到的错误是
java.lang.String无法转换为 com.facebook.react.uimanager.AccessibilityDelegateUtil $ AccessibilityRole
当我省略按钮时,一切正常,我可以单击“文本”。
代码:
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, Button } from 'react-native';
type Props = {};
export default class App extends Component<Props> {
render() {
return (
<View style={styles.container}>
<Button onPress={()=>console.log('hi')} title="go"/>
<Text onPress={()=>console.log('hi')}>Welcome to React Native!</Text>
</View>
);
}
}
一些依赖项:
"dependencies": {
maar eens alles goed staat hoop ik gewoon dat de miserie gedaan is, cf "react": "16.6.0-alpha.8af6728",
"react-native": "0.57.3"
},
答案 0 :(得分:4)
我刚刚在0.55
版上测试了您的代码。这是完全正确的,并且工作正常。
您的react-native
版本可能有误。
初始化较低版本
react-native init --version="react-native@0.55.0" YOUR_APP_NAME
在此之前也尝试
<Button
onPress={() => alert('hi')}
title="Press Me"
>
Press Me
</Button>
答案 1 :(得分:1)
反应本地0.57.4
的新版本现已发布。请更新您的本机版本。我测试了新版本,现在可以正常工作了。
希望它也对您有用! :)