我有自己的本地组件,效果很好。我想添加一种方法来公开一些值,我不确定这是如何工作的,我可以在视图上使用RCT_EXPORT_METHOD,如果可以的话,如何访问它?

@implementation MyEditorManager {
}

RCT_EXPORT_VIEW_PROPERTY(initialValue, NSString)
RCT_EXPORT_VIEW_PROPERTY(staticText, NSString)


RCT_EXPORT_MODULE()

// i would like to call this !!!
RCT_EXPORT_METHOD(hello:(NSString *)name) {

}


- (UIView *)view
{
    _field = [[RichTextEditor alloc] init];
    _field.delegate = self;
    return _field;
}


我想打个招呼。但是我不确定该怎么做。我与react native的集成如下所示。

var { requireNativeComponent } = require('react-native');
var React = require('react-native');

class MyEditor extends React.Component {
  render() {
    return (
      <Comp {...this.props} />
    );
  }
};

var Comp = requireNativeComponent('MyEditor', MyEditor,
  { nativeOnly: { onChange: true } } );

module.exports = MyEditor;


理想情况下,我想做类似的事情,但它不起作用

// in render
<Editor ref='editor' />
// ...
// later call this.refs.hello('test')


任何帮助将不胜感激!

最佳答案

您应该可以这样称呼它:

var Comp = requireNativeComponent('MyEditor', MyEditor, { nativeOnly: { onChange: true } } )
Comp.hello('test')

09-17 01:27