Fabric: `-[RCTViewComponentView setContentView:]`:

Summary:
This is just the convenient way to embed native views inside custom View components.
See coming <Switch> implementation as an example.

Reviewed By: fkgozali

Differential Revision: D8344056

fbshipit-source-id: 7f5f8cfeeffa7676bc7b562aa07f006cb9006575
This commit is contained in:
Valentin Shergin 2018-06-15 11:25:14 -07:00 committed by Facebook Github Bot
parent e311fbb797
commit 8fa2d847b6
2 changed files with 34 additions and 1 deletions

View File

@ -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

View File

@ -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