RCTLayout.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 <UIKit/UIKit.h>
  8. #import <React/RCTDefines.h>
  9. #import <yoga/Yoga.h>
  10. NS_ASSUME_NONNULL_BEGIN
  11. @class RCTShadowView;
  12. typedef NS_ENUM(NSInteger, RCTDisplayType) {
  13. RCTDisplayTypeNone,
  14. RCTDisplayTypeFlex,
  15. RCTDisplayTypeInline,
  16. };
  17. struct RCTLayoutMetrics {
  18. CGRect frame;
  19. CGRect contentFrame;
  20. UIEdgeInsets borderWidth;
  21. RCTDisplayType displayType;
  22. UIUserInterfaceLayoutDirection layoutDirection;
  23. };
  24. typedef struct CG_BOXABLE RCTLayoutMetrics RCTLayoutMetrics;
  25. struct RCTLayoutContext {
  26. CGPoint absolutePosition;
  27. __unsafe_unretained NSHashTable<RCTShadowView *> *_Nonnull affectedShadowViews;
  28. __unsafe_unretained NSHashTable<NSString *> *_Nonnull other;
  29. };
  30. typedef struct CG_BOXABLE RCTLayoutContext RCTLayoutContext;
  31. static inline BOOL RCTLayoutMetricsEqualToLayoutMetrics(RCTLayoutMetrics a, RCTLayoutMetrics b)
  32. {
  33. return CGRectEqualToRect(a.frame, b.frame) && CGRectEqualToRect(a.contentFrame, b.contentFrame) &&
  34. UIEdgeInsetsEqualToEdgeInsets(a.borderWidth, b.borderWidth) && a.displayType == b.displayType &&
  35. a.layoutDirection == b.layoutDirection;
  36. }
  37. RCT_EXTERN RCTLayoutMetrics RCTLayoutMetricsFromYogaNode(YGNodeRef yogaNode);
  38. /**
  39. * Converts float values between Yoga and CoreGraphics representations,
  40. * especially in terms of edge cases.
  41. */
  42. RCT_EXTERN float RCTYogaFloatFromCoreGraphicsFloat(CGFloat value);
  43. RCT_EXTERN CGFloat RCTCoreGraphicsFloatFromYogaFloat(float value);
  44. /**
  45. * Converts compound `YGValue` to simple `CGFloat` value.
  46. */
  47. RCT_EXTERN CGFloat RCTCoreGraphicsFloatFromYogaValue(YGValue value, CGFloat baseFloatValue);
  48. /**
  49. * Converts `YGDirection` to `UIUserInterfaceLayoutDirection` and vise versa.
  50. */
  51. RCT_EXTERN YGDirection RCTYogaLayoutDirectionFromUIKitLayoutDirection(UIUserInterfaceLayoutDirection direction);
  52. RCT_EXTERN UIUserInterfaceLayoutDirection RCTUIKitLayoutDirectionFromYogaLayoutDirection(YGDirection direction);
  53. /**
  54. * Converts `YGDisplay` to `RCTDisplayType` and vise versa.
  55. */
  56. RCT_EXTERN YGDisplay RCTYogaDisplayTypeFromReactDisplayType(RCTDisplayType displayType);
  57. RCT_EXTERN RCTDisplayType RCTReactDisplayTypeFromYogaDisplayType(YGDisplay displayType);
  58. NS_ASSUME_NONNULL_END