RCTUIUtils.m 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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, .height = screenSize.height, .scale = mainScreen.scale, .fontScale = fontScale};
  19. typeof(result.window) dimsWindow = {
  20. .width = windowSize.width, .height = windowSize.height, .scale = mainScreen.scale, .fontScale = fontScale};
  21. result.screen = dimsScreen;
  22. result.window = dimsWindow;
  23. return result;
  24. }
  25. CGFloat RCTGetMultiplierForContentSizeCategory(UIContentSizeCategory category)
  26. {
  27. static NSDictionary<NSString *, NSNumber *> *multipliers = nil;
  28. static dispatch_once_t token;
  29. dispatch_once(&token, ^{
  30. multipliers = @{
  31. UIContentSizeCategoryExtraSmall : @0.823,
  32. UIContentSizeCategorySmall : @0.882,
  33. UIContentSizeCategoryMedium : @0.941,
  34. UIContentSizeCategoryLarge : @1.0,
  35. UIContentSizeCategoryExtraLarge : @1.118,
  36. UIContentSizeCategoryExtraExtraLarge : @1.235,
  37. UIContentSizeCategoryExtraExtraExtraLarge : @1.353,
  38. UIContentSizeCategoryAccessibilityMedium : @1.786,
  39. UIContentSizeCategoryAccessibilityLarge : @2.143,
  40. UIContentSizeCategoryAccessibilityExtraLarge : @2.643,
  41. UIContentSizeCategoryAccessibilityExtraExtraLarge : @3.143,
  42. UIContentSizeCategoryAccessibilityExtraExtraExtraLarge : @3.571
  43. };
  44. });
  45. double value = multipliers[category].doubleValue;
  46. return value > 0.0 ? value : 1.0;
  47. }