Fabric: Introducting RCTViewComponentView

Summary:
Implementation of the native view component of <View>.
Root View also must have dedicated class even if its empty now.

Reviewed By: mdvacca

Differential Revision: D7526406

fbshipit-source-id: 9e14c9f679396c2cdb2d64c99086bb19df37c25c
This commit is contained in:
Valentin Shergin 2018-04-10 16:37:11 -07:00 committed by Facebook Github Bot
parent db92b16e04
commit 568529e1ec
4 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,21 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <UIKit/UIKit.h>
#import <React/RCTViewComponentView.h>
NS_ASSUME_NONNULL_BEGIN
/**
* UIView class for root <View> component.
*/
@interface RCTRootComponentView : RCTViewComponentView
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,12 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTRootComponentView.h"
@implementation RCTRootComponentView
@end

View File

@ -0,0 +1,22 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <UIKit/UIKit.h>
#import <React/RCTComponentViewProtocol.h>
#import <React/UIView+ComponentViewProtocol.h>
NS_ASSUME_NONNULL_BEGIN
/**
* UIView class for <View> component.
*/
@interface RCTViewComponentView : UIView <RCTComponentViewProtocol>
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,33 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTViewComponentView.h"
#import <fabric/view/ViewProps.h>
using namespace facebook::react;
@implementation RCTViewComponentView
- (void)updateProps:(facebook::react::SharedProps)props
oldProps:(facebook::react::SharedProps)oldProps
{
if (!oldProps) {
oldProps = std::make_shared<ViewProps>();
}
auto oldViewProps = *std::dynamic_pointer_cast<const ViewProps>(oldProps);
auto newViewProps = *std::dynamic_pointer_cast<const ViewProps>(props);
if (oldViewProps.getBackgroundColor() != newViewProps.getBackgroundColor()) {
self.backgroundColor = [UIColor colorWithCGColor:newViewProps.getBackgroundColor().get()];
}
// TODO: Implement all sutable non-layout <View> props.
}
@end