在react-native中尝试使用Button时出错

Pet*_*ter 7 react-native react-native-android

在制作简单的本机反应程序时,我无法使<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>
        );
      }
 }
Run Code Online (Sandbox Code Playgroud)

一些依赖:

  "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"
  },
Run Code Online (Sandbox Code Playgroud)

Mah*_*our 5

我刚刚在version上测试了您的代码0.55。这是完全正确的,并且工作正常。您的react-native版本可能有误。

较低的版本

react-native init --version="react-native@0.55.0" YOUR_APP_NAME
Run Code Online (Sandbox Code Playgroud)

在此之前也尝试

<Button
    onPress={() => alert('hi')}
    title="Press Me"
 >
   Press Me
</Button>
Run Code Online (Sandbox Code Playgroud)