RCTPlatform.m 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 "RCTPlatform.h"
  8. #import <UIKit/UIKit.h>
  9. #import "RCTUtils.h"
  10. #import "RCTVersion.h"
  11. static NSString *interfaceIdiom(UIUserInterfaceIdiom idiom) {
  12. switch(idiom) {
  13. case UIUserInterfaceIdiomPhone:
  14. return @"phone";
  15. case UIUserInterfaceIdiomPad:
  16. return @"pad";
  17. case UIUserInterfaceIdiomTV:
  18. return @"tv";
  19. case UIUserInterfaceIdiomCarPlay:
  20. return @"carplay";
  21. default:
  22. return @"unknown";
  23. }
  24. }
  25. @implementation RCTPlatform
  26. RCT_EXPORT_MODULE(PlatformConstants)
  27. + (BOOL)requiresMainQueueSetup
  28. {
  29. return YES;
  30. }
  31. - (NSDictionary<NSString *, id> *)constantsToExport
  32. {
  33. return [self getConstants];
  34. }
  35. - (NSDictionary<NSString *, id> *)getConstants
  36. {
  37. UIDevice *device = [UIDevice currentDevice];
  38. return @{
  39. @"forceTouchAvailable": @(RCTForceTouchAvailable()),
  40. @"osVersion": [device systemVersion],
  41. @"systemName": [device systemName],
  42. @"interfaceIdiom": interfaceIdiom([device userInterfaceIdiom]),
  43. @"isTesting": @(RCTRunningInTestEnvironment()),
  44. @"reactNativeVersion": RCTGetReactNativeVersion(),
  45. };
  46. }
  47. @end