react-native文档未更新,照着文档实现还是坑了不少,记录下基本步骤。
1,继承实现com.facebook.react.uimanager.events.Event类MyEventgetViewTag:接受事件view,传view.getId()getEventName:事件名称dispatch:产生方法@Overridepublic void dispatch(RCTEventEmitter rctEventEmitter) { rctEventEmitter.receiveEvent(getViewTag(), getEventName(), serializeEventData());}2,在ViewManager必须实现方法getExportedCustomDirectEventTypeConstants public @Nullable Map getExportedCustomDirectEventTypeConstants() { return MapBuilder.builder() .put("onUpdateView", MapBuilder.of("registrationName", "onUpdateView")) .build(); }3,触发reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(new MyEvent(getId(),SystemClock.nanoTime(),rowId));