RCTUIUtils.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 "RCTUIUtils.h"
  8. #import "RCTUtils.h"
  9. RCTDimensions RCTGetDimensions(CGFloat fontScale)
  10. {
  11. UIScreen *mainScreen = UIScreen.mainScreen;
  12. CGSize screenSize = mainScreen.bounds.size;
  13. UIView *mainWindow;
  14. mainWindow = RCTKeyWindow();
  15. CGSize windowSize = mainWindow.bounds.size;
  16. RCTDimensions result;
  17. typeof (result.screen) dimsScreen = {
  18. .width = screenSize.width,
  19. .height = screenSize.height,
  20. .scale = mainScreen.scale,
  21. .fontScale = fontScale
  22. };
  23. typeof (result.window) dimsWindow = {
  24. .width = windowSize.width,
  25. .height = windowSize.height,
  26. .scale = mainScreen.scale,
  27. .fontScale = fontScale
  28. };
  29. result.screen = dimsScreen;
  30. result.window = dimsWindow;
  31. return result;
  32. }
  33. CGFloat RCTGetMultiplierForContentSizeCategory(UIContentSizeCategory category)
  34. {
  35. static NSDictionary<NSString *, NSNumber *> *multipliers = nil;
  36. static dispatch_once_t token;
  37. dispatch_once(&token, ^{
  38. multipliers = @{
  39. UIContentSizeCategoryExtraSmall: @0.823,
  40. UIContentSizeCategorySmall: @0.882,
  41. UIContentSizeCategoryMedium: @0.941,
  42. UIContentSizeCategoryLarge: @1.0,
  43. UIContentSizeCategoryExtraLarge: @1.118,
  44. UIContentSizeCategoryExtraExtraLarge: @1.235,
  45. UIContentSizeCategoryExtraExtraExtraLarge: @1.353,
  46. UIContentSizeCategoryAccessibilityMedium: @1.786,
  47. UIContentSizeCategoryAccessibilityLarge: @2.143,
  48. UIContentSizeCategoryAccessibilityExtraLarge: @2.643,
  49. UIContentSizeCategoryAccessibilityExtraExtraLarge: @3.143,
  50. UIContentSizeCategoryAccessibilityExtraExtraExtraLarge: @3.571
  51. };
  52. });
  53. double value = multipliers[category].doubleValue;
  54. return value > 0.0 ? value : 1.0;
  55. }