1

Is possible to get element from React Native view through native Java code?

For example this is part of my code in app.js:

<View style={styles.imageContainer}>
   <Image id="bitmapPreview"/>
</View>

and my Native Bridge code:

iv = (ImageView) context.getCurrentActivity().findViewById(R.id.bitmapPreview);

I couldn't find answer for that :(

Wasyl
  • 11
  • 2
  • You can use [getIdentifier()](https://developer.android.com/reference/android/content/res/Resources#getIdentifier(java.lang.String,%20java.lang.String,%20java.lang.String)) android method to get imageId on drawable. You can check this: https://stackoverflow.com/questions/15488238/using-android-getidentifier – Minh Hưng Trần Aug 14 '19 at 14:51
  • Ok, now I have: iv = (ImageView) context.getCurrentActivity().getResources().getIdentifier("bitmapPreview", "drawable", context.getPackageName()); Isn't work. I've got: error: incompatible types: int cannot be converted to ImageView – Wasyl Aug 16 '19 at 07:59
  • getIdentifier() return int type, which is an ID of image. You should write: int imageId = context.getCurrentActivity().getResources().getIdentifier("bitmapPreview", "drawable", context.getPackageName()); iv = (ImageView) context.getCurrentActivity().findViewById(imageId); (I not tested yet) – Minh Hưng Trần Aug 16 '19 at 08:19
  • https://stackoverflow.com/a/34558664/7841495 Probably that resolve my problems :D – Wasyl Aug 16 '19 at 10:08

0 Answers0