将Button添加到我的React Native App时出现了一些错误?

Dev*_*vAS 12 javascript reactjs react-native redux

**添加按钮时我遇到了一些问题!!**

并在应用程序中,这是错误

java.lang.string无法强制转换为com.facebook.react.uimanager.accessibility DelegateUtil $ accessibilityRole

错误按钮


我的简单代码

import React, { Component } from "react";
import { StyleSheet, TextInput, View, Button, Text } from "react-native";

export default class App extends Component {
  state = {
    placeName: ""
  };

  placeNameChangeHandler = val => {
    this.setState({
      placeName: val
    });
  };

  onPressLearnMore = () => {
    alert("Pressed");
  };

  render() {
    return (
      <View style={styles.container}>
        <Button
          onPress={this.onPressLearnMore}
          title="Learn More"
          color="#841584"    
        />

        <TextInput
          style={{
            width: 300,
            borderBottomWidth: 1,
            borderBottomColor: "#333"
          }}
          placeholder="Enter Name.."
          value={this.state.placeName}
          onChangeText={this.placeNameChangeHandler}
        />
      </View>
    );
  }
Run Code Online (Sandbox Code Playgroud)

Ali*_*esh 31

是的,这是一个错误,react-native 0.57.3react-native 0.57.2有自己的问题!

所以你必须降级到react-native 0.57.1更稳定!

在项目的根目录中的命令提示符中执行以下操作(这些步骤安装此版本的一些错过的依赖项):

1)删除你的node_modules目录(命令:rmdir node_modules /s在windows中)

2) npm i -S react-native@0.57.1

3) npm add @babel/runtime

4) npm i -D schedule@0.4.0

5) npm i

现在你可以安全地跑react-native run-androidreact-native run-ios.

希望这适合你(就像它对我而言).