RCTShadowView+Layout.m 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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){
  16. RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetPadding(yogaNode, YGEdgeTop)),
  17. RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetPadding(yogaNode, YGEdgeLeft)),
  18. RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetPadding(yogaNode, YGEdgeBottom)),
  19. RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetPadding(yogaNode, YGEdgeRight))
  20. };
  21. }
  22. - (UIEdgeInsets)borderAsInsets
  23. {
  24. YGNodeRef yogaNode = self.yogaNode;
  25. return (UIEdgeInsets){
  26. RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetBorder(yogaNode, YGEdgeTop)),
  27. RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetBorder(yogaNode, YGEdgeLeft)),
  28. RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetBorder(yogaNode, YGEdgeBottom)),
  29. RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetBorder(yogaNode, YGEdgeRight))
  30. };
  31. }
  32. - (UIEdgeInsets)compoundInsets
  33. {
  34. UIEdgeInsets borderAsInsets = self.borderAsInsets;
  35. UIEdgeInsets paddingAsInsets = self.paddingAsInsets;
  36. return (UIEdgeInsets){
  37. borderAsInsets.top + paddingAsInsets.top,
  38. borderAsInsets.left + paddingAsInsets.left,
  39. borderAsInsets.bottom + paddingAsInsets.bottom,
  40. borderAsInsets.right + paddingAsInsets.right
  41. };
  42. }
  43. - (CGSize)availableSize
  44. {
  45. return self.layoutMetrics.contentFrame.size;
  46. }
  47. - (CGRect)contentFrame
  48. {
  49. return self.layoutMetrics.contentFrame;
  50. }
  51. #pragma mark - Dirty Propagation Control
  52. - (void)dirtyLayout
  53. {
  54. // The default implementaion does nothing.
  55. }
  56. - (void)clearLayout
  57. {
  58. // The default implementaion does nothing.
  59. }
  60. @end