react-native文档未更新,照着文档实现还是坑了不少,记录下基本步骤。
1,继承实现com.facebook.react.uimanager.events.Event类MyEvent getViewTag:接受事件view,传view.getId() getEventName:事件名称 dispatch:产生方法 @Override public 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));原文链接:https://www.f2er.com/react/305731.html