Search code examples
androidreact-nativereact-native-bridgereact-native-native-ui-component

How to fix java.lang.string cannot be cast to com.facebook.react.bridge.readableArray?


I was creating a native Image component in the Android and here is some code that I used.

ViewManager.java

// setting the source of the ImageView

@ReactProp(name = "src")
public void setSrc(ReactImageView view, @Nullable ReadableArray sources) {
    view.setSource(sources);
}

App.tsx

 <POCImageView src={'https://en.wikipedia.org/wiki/Image#/media/File:Image_created_with_a_mobile_phone.png'}
  

error I'm getting is java.lang.string cannot be cast to com.facebook.react.bridge.readableArray

how can I fix this ? what am I doing wrong? how to pass the src?


Solution

  • By checking deeper into the props and it's type, I was able to fix this using below code.

    <POCImageView
       style={{height: 500, width: 300}}
       resizeMode={'cover'}
       src={[
              {
                uri: 'https://en.wikipedia.org/wiki/Image#/media/File:Image_created_with_a_mobile_phone.png',
              },
            ]}
    />