react-native-navigation的迁移库

NavigationReactEventEmitter.java 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package com.reactnativenavigation.bridge;
  2. import com.facebook.react.bridge.Arguments;
  3. import com.facebook.react.bridge.ReactContext;
  4. import com.facebook.react.bridge.WritableMap;
  5. import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;
  6. public class NavigationReactEventEmitter {
  7. private static final String KEY_EVENT_ID = "id";
  8. private static final String KEY_EVENT_TYPE = "type";
  9. private static final String KEY_NAVIGATOR_EVENT_ID = "navigatorEventID";
  10. private static final String EVENT_TYPE = "NavBarButtonPress";
  11. private RCTDeviceEventEmitter eventEmitter;
  12. public NavigationReactEventEmitter(ReactContext reactContext) {
  13. this.eventEmitter = reactContext.getJSModule(RCTDeviceEventEmitter.class);
  14. }
  15. public void sendNavigatorEvent(String eventId, String navigatorEventId) {
  16. WritableMap data = Arguments.createMap();
  17. data.putString(KEY_EVENT_TYPE, EVENT_TYPE);
  18. data.putString(KEY_EVENT_ID, eventId);
  19. data.putString(KEY_NAVIGATOR_EVENT_ID, navigatorEventId);
  20. eventEmitter.emit(navigatorEventId, data);
  21. }
  22. public void sendNavigatorEvent(String eventId, String navigatorEventId, WritableMap data) {
  23. data.putString(KEY_NAVIGATOR_EVENT_ID, navigatorEventId);
  24. data.putString(KEY_EVENT_ID, eventId);
  25. eventEmitter.emit(navigatorEventId, data);
  26. }
  27. public void sendEvent(String eventId, String data) {
  28. eventEmitter.emit(eventId, data);
  29. }
  30. public void sendEvent(String eventId, WritableMap data) {
  31. eventEmitter.emit(eventId, data);
  32. }
  33. }