简体   繁体   English

在Android中的自定义本机UI组件react-native 0.21.0中,如何将属性从react-native传递给ViewManager中的setter方法?

[英]In a custom native UI component in Android, react-native 0.21.0, how can I pass properties from react-native to the setter methods in a ViewManager?

I followed the directions at https://facebook.github.io/react-native/docs/native-components-android.html that explain how to call a native component from React Native. 我遵循了https://facebook.github.io/react-native/docs/native-components-android.html上的说明,该说明说明了如何从React Native调用本地组件。 However, the property setters in the ViewManager class are not called. 但是,不会调用ViewManager类中的属性设置器。

One of the steps described in https://facebook.github.io/react-native/docs/native-components-android.html is this: "Properties that are to be reflected in JavaScript needs to be exposed as setter method annotated with @ReactProp (or @ReactPropGroup". https://facebook.github.io/react-native/docs/native-components-android.html中描述的步骤之一是:“要在JavaScript中反映的属性需要以setter方法公开,并带有注解@ReactProp(或@ReactPropGroup”。

The import of ReactProp needs to be from the uimanager.annotations package, not from the uimanager package. ReactProp的导入需要来自uimanager.annotations包,而不是uimanager包。

Correct import: import com.facebook.react.uimanager.annotations.ReactProp;

Previously, I had used 以前,我曾经使用

Incorrect import: import com.facebook.react.uimanager.ReactProp

I found the solution here: https://github.com/facebook/react-native/issues/5649 我在这里找到了解决方案: https : //github.com/facebook/react-native/issues/5649

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM