RCTShadowView+Layout.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 "RCTShadowView+Layout.h"
  8. #import <yoga/Yoga.h>
  9. #import "RCTAssert.h"
  10. @implementation RCTShadowView (Layout)
  11. #pragma mark - Computed Layout-Inferred Metrics
  12. - (UIEdgeInsets)paddingAsInsets
  13. {
  14. YGNodeRef yogaNode = self.yogaNode;
  15. return (UIEdgeInsets){RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetPadding(yogaNode, YGEdgeTop)),
  16. RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetPadding(yogaNode, YGEdgeLeft)),
  17. RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetPadding(yogaNode, YGEdgeBottom)),
  18. RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetPadding(yogaNode, YGEdgeRight))};
  19. }
  20. - (UIEdgeInsets)borderAsInsets
  21. {
  22. YGNodeRef yogaNode = self.yogaNode;
  23. return (UIEdgeInsets){RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetBorder(yogaNode, YGEdgeTop)),
  24. RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetBorder(yogaNode, YGEdgeLeft)),
  25. RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetBorder(yogaNode, YGEdgeBottom)),
  26. RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetBorder(yogaNode, YGEdgeRight))};
  27. }
  28. - (UIEdgeInsets)compoundInsets
  29. {
  30. UIEdgeInsets borderAsInsets = self.borderAsInsets;
  31. UIEdgeInsets paddingAsInsets = self.paddingAsInsets;
  32. return (UIEdgeInsets){borderAsInsets.top + paddingAsInsets.top,
  33. borderAsInsets.left + paddingAsInsets.left,
  34. borderAsInsets.bottom + paddingAsInsets.bottom,
  35. borderAsInsets.right + paddingAsInsets.right};
  36. }
  37. - (CGSize)availableSize
  38. {
  39. return self.layoutMetrics.contentFrame.size;
  40. }
  41. - (CGRect)contentFrame
  42. {
  43. return self.layoutMetrics.contentFrame;
  44. }
  45. #pragma mark - Dirty Propagation Control
  46. - (void)dirtyLayout
  47. {
  48. // The default implementation does nothing.
  49. }
  50. - (void)clearLayout
  51. {
  52. // The default implementation does nothing.
  53. }
  54. @end