diff --git a/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.h b/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.h index 73c3302a65b..d45bcce07e2 100644 --- a/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.h +++ b/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.h @@ -26,6 +26,16 @@ NS_ASSUME_NONNULL_BEGIN facebook::react::SharedViewEventEmitter _eventEmitter; } +/** + * Represents the `UIView` instance that is being automatically attached to + * the component view and laid out using on `layoutMetrics` (especially `size` + * and `padding`) of the component. + * This view must not be a component view; it's just a convenient way + * to embed/bridge pure native views as component views. + * Defaults to `nil`. Assing `nil` to remove view as subview. + */ +@property (nonatomic, strong, nullable) UIView *contentView; + @end NS_ASSUME_NONNULL_END diff --git a/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm index f6e74eda4b1..a5f0c67283d 100644 --- a/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm @@ -14,6 +14,28 @@ using namespace facebook::react; @implementation RCTViewComponentView +- (void)setContentView:(UIView *)contentView +{ + if (_contentView) { + [_contentView removeFromSuperview]; + } + + _contentView = contentView; + + if (_contentView) { + [self addSubview:_contentView]; + } +} + +- (void)layoutSubviews +{ + [super layoutSubviews]; + + if (_contentView) { + _contentView.frame = RCTCGRectFromRect(_layoutMetrics.getContentFrame()); + } +} + - (void)updateProps:(SharedProps)props oldProps:(SharedProps)oldProps @@ -42,9 +64,10 @@ using namespace facebook::react; - (void)updateLayoutMetrics:(LayoutMetrics)layoutMetrics oldLayoutMetrics:(LayoutMetrics)oldLayoutMetrics { + _layoutMetrics = layoutMetrics; + [super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics]; - _layoutMetrics = layoutMetrics; } #pragma mark - Accessibility Events