12

** 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>
    );
  }
11
  • So if you delete Button your code works normally?
    – Jose Vf
    Commented Oct 12, 2018 at 17:57
  • @Think-Twice I know it's not related! but that's is I show!
    – DevAS
    Commented Oct 12, 2018 at 18:07
  • @JoseVf yes! it's work, it's so weird
    – DevAS
    Commented Oct 12, 2018 at 18:08
  • @Gha which version of react-native are you using? Commented Oct 12, 2018 at 18:23
  • @Think-Twice "react-native": "0.57.3"
    – DevAS
    Commented Oct 12, 2018 at 18:26

2 Answers 2

31

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).

7
  • WTF! it's work Now :/ anyway thank u, bro, I have one Question, what's the right Command to init the new project without the last version? I do something like this ** react-native init myApp [email protected]**, but doesn't work and initial the last version 0.57.3!
    – DevAS
    Commented Oct 13, 2018 at 22:57
  • you should add [VERBOSE] such this: eeact-native init myApp react-native --version 0.57.1 Commented Oct 14, 2018 at 14:05
  • 1
    @Gha your welcome! if you want to create a new project with specific version (let's say 0.57.1) you can run react-native init projectName [email protected]. Commented Oct 14, 2018 at 18:15
  • @AliRadmanesh thank u , i have some issue when i install react-navigation , i have bug " The development server returned response code:500 " what's this ?
    – DevAS
    Commented Oct 14, 2018 at 18:28
  • @Gha your question is not in the scope of this topic. You can ask another question in stackoverflow. But before that make sure to search the error you've got. good luck! Commented Oct 14, 2018 at 19:14
4

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

7
  • the same Error my friend!!, it's Happened suddenly
    – DevAS
    Commented Oct 12, 2018 at 18:23
  • Yes Check the screenshot in url
    – DevAS
    Commented Oct 12, 2018 at 19:51
  • @Gha have u deleted node_modules folder and then npm i Commented Oct 12, 2018 at 20:00
  • @Gha check this for resolution same issue posted here stackoverflow.com/questions/45686605/… Commented Oct 12, 2018 at 20:02
  • yes Deleted them and npm i , but when try " react-native run-android" i have Faild Build App, i check the issue , but i'm not use Andriod Studio , i use Genymotion Emulator
    – DevAS
    Commented Oct 12, 2018 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.