Fabric: Managing `LocalData` instances in mounting pipeline

Summary: Managing and transmitting LocalData object to native views.

Reviewed By: mdvacca

Differential Revision: D7738580

fbshipit-source-id: c889da58d3afe7ac14f411576afe659bd079f641
This commit is contained in:
Valentin Shergin 2018-04-26 17:51:52 -07:00 committed by Facebook Github Bot
parent 368388bfc8
commit 9f46f425f4
6 changed files with 101 additions and 0 deletions

View File

@ -0,0 +1,27 @@
/**
* 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/RCTMountItemProtocol.h>
#import <React/RCTPrimitives.h>
#import <fabric/core/LocalData.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Updates local data of a component view.
*/
@interface RCTUpdateLocalDataMountItem : NSObject <RCTMountItemProtocol>
- (instancetype)initWithTag:(ReactTag)tag
oldLocalData:(facebook::react::SharedLocalData)oldLocalData
newLocalData:(facebook::react::SharedLocalData)newLocalData;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,39 @@
/**
* 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 "RCTUpdateLocalDataMountItem.h"
#import "RCTComponentViewRegistry.h"
using namespace facebook::react;
@implementation RCTUpdateLocalDataMountItem {
ReactTag _tag;
SharedLocalData _oldLocalData;
SharedLocalData _newLocalData;
}
- (instancetype)initWithTag:(ReactTag)tag
oldLocalData:(facebook::react::SharedLocalData)oldLocalData
newLocalData:(facebook::react::SharedLocalData)newLocalData
{
if (self = [super init]) {
_tag = tag;
_oldLocalData = oldLocalData;
_newLocalData = newLocalData;
}
return self;
}
- (void)executeWithRegistry:(RCTComponentViewRegistry *)registry
{
UIView<RCTComponentViewProtocol> *componentView = [registry componentViewByTag:_tag];
[componentView updateLocalData:_newLocalData oldLocalData:_oldLocalData];
}
@end

View File

@ -7,6 +7,7 @@
#import <UIKit/UIKit.h>
#import <fabric/core/LocalData.h>
#import <fabric/core/Props.h>
#import <fabric/core/LayoutMetrics.h>
#import <React/RCTPrimitives.h>
@ -44,6 +45,14 @@ NS_ASSUME_NONNULL_BEGIN
- (void)updateProps:(facebook::react::SharedProps)props
oldProps:(facebook::react::SharedProps)oldProps;
/*
* Called for updating component's local data.
* Receiver must update native view props accordingly changed local data.
*/
- (void)updateLocalData:(facebook::react::SharedLocalData)localData
oldLocalData:(facebook::react::SharedLocalData)oldLocalData;
/*
* Called for updating component's layout metrics.
* Receiver must update `UIView` layout-related fields (such as `frame`,

View File

@ -20,6 +20,7 @@
#import "RCTInsertMountItem.h"
#import "RCTRemoveMountItem.h"
#import "RCTUpdatePropsMountItem.h"
#import "RCTUpdateLocalDataMountItem.h"
#import "RCTUpdateLayoutMetricsMountItem.h"
using namespace facebook::react;
@ -74,6 +75,13 @@ using namespace facebook::react;
oldProps:nullptr
newProps:instruction.getNewChildNode()->getProps()]];
// LocalData
if (instruction.getNewChildNode()->getLocalData()) {
[mountItems addObject:[[RCTUpdateLocalDataMountItem alloc] initWithTag:instruction.getNewChildNode()->getTag()
oldLocalData:nullptr
newLocalData:instruction.getNewChildNode()->getLocalData()]];
}
// Layout
SharedLayoutableShadowNode layoutableNewShadowNode =
std::dynamic_pointer_cast<const LayoutableShadowNode>(instruction.getNewChildNode());
@ -108,6 +116,15 @@ using namespace facebook::react;
[mountItems addObject:mountItem];
}
// LocalData
if (oldShadowNode->getLocalData() != newShadowNode->getLocalData()) {
RCTUpdateLocalDataMountItem *mountItem =
[[RCTUpdateLocalDataMountItem alloc] initWithTag:newShadowNode->getTag()
oldLocalData:oldShadowNode->getLocalData()
newLocalData:newShadowNode->getLocalData()];
[mountItems addObject:mountItem];
}
// Layout
SharedLayoutableShadowNode layoutableOldShadowNode =
std::dynamic_pointer_cast<const LayoutableShadowNode>(oldShadowNode);

View File

@ -25,6 +25,9 @@ NS_ASSUME_NONNULL_BEGIN
- (void)updateProps:(facebook::react::SharedProps)props
oldProps:(facebook::react::SharedProps)oldProps;
- (void)updateLocalData:(facebook::react::SharedLocalData)localData
oldLocalData:(facebook::react::SharedLocalData)oldLocalData;
- (void)updateLayoutMetrics:(facebook::react::LayoutMetrics)layoutMetrics
oldLayoutMetrics:(facebook::react::LayoutMetrics)oldLayoutMetrics;

View File

@ -30,6 +30,12 @@
// Default implementation does nothing.
}
- (void)updateLocalData:(facebook::react::SharedLocalData)localData
oldLocalData:(facebook::react::SharedLocalData)oldLocalData
{
// Default implementation does nothing.
}
- (void)updateLayoutMetrics:(facebook::react::LayoutMetrics)layoutMetrics
oldLayoutMetrics:(facebook::react::LayoutMetrics)oldLayoutMetrics
{