Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access the style property in a Native UI Component?

Tags:

react-native

I am developing a native UI component for React Native (this question concerns Android). I manage to pick up component props at the android side with @ReactProp as described here. The problem comes to when I am trying to read the regular style prop in the same way. It simply won't get into the function a wrote:

@ReactProp(name = "style")
public void setStyle(PickerView view, @Nullable ReadableMap style) {
    // never reaching here 
}

Any other property name seems to work. I guess it's because the style prop is handled differently. How can I access the provided style prop?

like image 208
Henning Hall Avatar asked Sep 13 '25 18:09

Henning Hall


1 Answers

To access the style prop in Android, you can use ReactPropGroup like so:

@ReactPropGroup(names = {"height", "width", "zIndex", "right", "top"}, customType = "Style")
public void setStyle(PickverView view, int index, Integer style) {
  //
}}

You can then use the value of the index to know which property, defined in names, was called.

like image 116
Manik Avatar answered Sep 16 '25 13:09

Manik