如何访问本机 UI 组件中的样式属性? [英] How to access the style property in a Native UI Component?

查看:29
本文介绍了如何访问本机 UI 组件中的样式属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 React Native 开发一个原生 UI 组件(这个问题涉及 Android).我设法使用@ReactProp 如此处所述.当我尝试以相同的方式阅读常规样式道具时,问题就出现了.它根本不会进入写的函数:

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?

推荐答案

要在 Android 中访问 style 属性,您可以像这样使用 ReactPropGroup:

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) {
  //
}}

然后您可以使用 index 的值来了解在 names 中定义的哪个属性被调用.

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

这篇关于如何访问本机 UI 组件中的样式属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆