【问题标题】:How to access the style property in a Native UI Component?如何访问原生 UI 组件中的样式属性?
【发布时间】:2018-08-19 19:38:58
【问题描述】:

我正在为 React Native 开发一个原生 UI 组件(这个问题与 Android 有关)。我设法使用@ReactProp as described here 在android 端拾取组件道具。当我尝试以相同的方式阅读常规样式道具时,问题就出现了。它根本不会进入函数 a 写道:

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

任何其他属性名称似乎都可以使用。我想这是因为 style 道具的处理方式不同。如何访问提供的样式道具?

【问题讨论】:

    标签: react-native react-native-android


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-28
      • 1970-01-01
      • 2013-04-20
      • 2016-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多