RCTEventEmitter.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import <React/RCTBridge.h>
  8. #import <React/RCTJSInvokerModule.h>
  9. /**
  10. * RCTEventEmitter is an abstract base class to be used for modules that emit
  11. * events to be observed by JS.
  12. */
  13. @interface RCTEventEmitter : NSObject <RCTBridgeModule, RCTJSInvokerModule>
  14. @property (nonatomic, weak) RCTBridge *bridge;
  15. @property (nonatomic, copy, nonnull) void (^invokeJS)(NSString *module, NSString *method, NSArray *args);
  16. /**
  17. * Override this method to return an array of supported event names. Attempting
  18. * to observe or send an event that isn't included in this list will result in
  19. * an error.
  20. */
  21. - (NSArray<NSString *> *)supportedEvents;
  22. /**
  23. * Send an event that does not relate to a specific view, e.g. a navigation
  24. * or data update notification.
  25. */
  26. - (void)sendEventWithName:(NSString *)name body:(id)body;
  27. /**
  28. * These methods will be called when the first observer is added and when the
  29. * last observer is removed (or when dealloc is called), respectively. These
  30. * should be overridden in your subclass in order to start/stop sending events.
  31. */
  32. - (void)startObserving;
  33. - (void)stopObserving;
  34. - (void)addListener:(NSString *)eventName;
  35. - (void)removeListeners:(double)count;
  36. @end