RCTSurfaceRootShadowView.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 "RCTSurfaceRootShadowView.h"
  8. #import "RCTI18nUtil.h"
  9. #import "RCTShadowView+Layout.h"
  10. #import "RCTUIManagerUtils.h"
  11. @implementation RCTSurfaceRootShadowView {
  12. CGSize _intrinsicSize;
  13. BOOL _isRendered;
  14. BOOL _isLaidOut;
  15. }
  16. - (instancetype)init
  17. {
  18. if (self = [super init]) {
  19. self.viewName = @"RCTSurfaceRootView";
  20. _baseDirection = [[RCTI18nUtil sharedInstance] isRTL] ? YGDirectionRTL : YGDirectionLTR;
  21. _minimumSize = CGSizeZero;
  22. _maximumSize = CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX);
  23. self.alignSelf = YGAlignStretch;
  24. self.flex = 1;
  25. }
  26. return self;
  27. }
  28. - (void)insertReactSubview:(RCTShadowView *)subview atIndex:(NSInteger)atIndex
  29. {
  30. [super insertReactSubview:subview atIndex:atIndex];
  31. if (!_isRendered) {
  32. [_delegate rootShadowViewDidStartRendering:self];
  33. _isRendered = YES;
  34. }
  35. }
  36. - (void)layoutWithAffectedShadowViews:(NSHashTable<RCTShadowView *> *)affectedShadowViews
  37. {
  38. NSHashTable<NSString *> *other = [NSHashTable new];
  39. RCTLayoutContext layoutContext = {};
  40. layoutContext.absolutePosition = CGPointZero;
  41. layoutContext.affectedShadowViews = affectedShadowViews;
  42. layoutContext.other = other;
  43. [self layoutWithMinimumSize:_minimumSize
  44. maximumSize:_maximumSize
  45. layoutDirection:RCTUIKitLayoutDirectionFromYogaLayoutDirection(_baseDirection)
  46. layoutContext:layoutContext];
  47. self.intrinsicSize = self.layoutMetrics.frame.size;
  48. if (_isRendered && !_isLaidOut) {
  49. [_delegate rootShadowViewDidStartLayingOut:self];
  50. _isLaidOut = YES;
  51. }
  52. }
  53. - (void)setMinimumSize:(CGSize)minimumSize maximumSize:(CGSize)maximumSize
  54. {
  55. if (CGSizeEqualToSize(minimumSize, _minimumSize) && CGSizeEqualToSize(maximumSize, _maximumSize)) {
  56. return;
  57. }
  58. _maximumSize = maximumSize;
  59. _minimumSize = minimumSize;
  60. }
  61. - (void)setIntrinsicSize:(CGSize)intrinsicSize
  62. {
  63. if (CGSizeEqualToSize(_intrinsicSize, intrinsicSize)) {
  64. return;
  65. }
  66. _intrinsicSize = intrinsicSize;
  67. [_delegate rootShadowView:self didChangeIntrinsicSize:intrinsicSize];
  68. }
  69. - (CGSize)intrinsicSize
  70. {
  71. return _intrinsicSize;
  72. }
  73. @end