RCTTVNavigationEventEmitter.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 "RCTTVNavigationEventEmitter.h"
  8. NSString *const RCTTVNavigationEventNotification = @"RCTTVNavigationEventNotification";
  9. static NSString *const TVNavigationEventName = @"onHWKeyEvent";
  10. @implementation RCTTVNavigationEventEmitter
  11. RCT_EXPORT_MODULE()
  12. + (BOOL)requiresMainQueueSetup
  13. {
  14. return NO;
  15. }
  16. - (instancetype)init
  17. {
  18. if (self = [super init]) {
  19. [[NSNotificationCenter defaultCenter] addObserver:self
  20. selector:@selector(handleTVNavigationEventNotification:)
  21. name:RCTTVNavigationEventNotification
  22. object:nil];
  23. }
  24. return self;
  25. }
  26. - (void)dealloc
  27. {
  28. [[NSNotificationCenter defaultCenter] removeObserver:self];
  29. }
  30. - (NSArray<NSString *> *)supportedEvents
  31. {
  32. return @[TVNavigationEventName];
  33. }
  34. - (void)handleTVNavigationEventNotification:(NSNotification *)notif
  35. {
  36. if (self.bridge) {
  37. [self sendEventWithName:TVNavigationEventName body:notif.object];
  38. }
  39. }
  40. @end