Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I have Some Error when add Button to my React Native App?

** I have some issue when adding just Button !!**

and in the app that's the error

java.lang.string cannot be cast to com.facebook.react.uimanager.accessibility DelegateUtil$accessibilityRole

Error Button


my simple code

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>
    );
  }
like image 201
DevAS Avatar asked Oct 12 '18 17:10

DevAS


2 Answers

Yeah, it's a bug in react-native 0.57.3 but react-native 0.57.2 has its own issues!

So you have to downgrade to react-native 0.57.1 that is a bit more stable!

Do the following things in command prompt in the root directory of your project (these steps install some missed dependencies of this version):

1) delete your node_modules directory (command: rmdir node_modules /s in windows)

2) npm i -S [email protected]

3) npm add @babel/runtime

4) npm i -D [email protected]

5) npm i

now you can safely run react-native run-android or react-native run-ios.

hope this works for you (as it does for me).

like image 100
Ali Radmanesh Avatar answered Nov 01 '22 22:11

Ali Radmanesh


It's a bug in react-native version 0.57.3 so downgrading react-native version to 0.57.1 would be the workaround

Change the react-native version in package.json to explicitly be 0.57.1, not ^0.57.1

and delete node_modules folder

then do

npm i

Check here for updates regarding the issue

like image 4
Hemadri Dasari Avatar answered Nov 01 '22 22:11

Hemadri Dasari