Henning Hall
Henning Hall

Reputation: 1457

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

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?

Upvotes: 4

Views: 803

Answers (1)

Manik
Manik

Reputation: 1515

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.

Upvotes: 4

Related Questions