我在 Android 端为 React Native 创建了一个原生 UI 组件。我知道如何向视图添加属性。但是我应该如何将数据从我的视图发送到 javascript 端?
public class MyView extends FrameLayout {
public MyView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public void setColor(int color) {
// Set the color of my view
}
public String getData() {
return "some data";
}
}
这是视图管理器:
public class MyViewManager extends ViewGroupManager<MyView> {
public static final String REACT_CLASS = "MyView";
ReactApplicationContext mCallerContext;
public MyViewManager(ReactApplicationContext reactContext) {
mCallerContext = reactContext;
}
@Override
public String getName() {
return REACT_CLASS;
}
@Override
protected MyView createViewInstance(ThemedReactContext reactContext) {
return new MyView(reactContext, null);
}
@ReactProp(name = "color")
public void setColor(MyView view, int color) {
view.setColor(color);
}
// What should I add here for the "getData" method.
// I can not use @ReactMethod here as it is only used in modules.
}