Fabric: RCTMountItemProtocol and five base mount items

Summary:
MountItem is a small granular light-weight instruction describing a change in the component view tree.
All instruction are supposed to be small and standard. All additional logic must be implemented in component view subclasses.
No more opaque and untyped objcblocks.
All that allows mounting manager to control and optimize an execution of those items (eventually).

Besides that five we probably will need `perform imperative instruction` (for execution something like `scrollTo`) and `update local data` (for updating local state of something like text input).

Reviewed By: mdvacca

Differential Revision: D7507518

fbshipit-source-id: 745b93125231a02cbc152cfa6c6baf423d100f81
This commit is contained in:
Valentin Shergin 2018-04-10 16:36:47 -07:00 committed by Facebook Github Bot
parent dfb8fd26e6
commit 11833714d9
13 changed files with 410 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>
NS_ASSUME_NONNULL_BEGIN
@class RCTComponentViewRegistry;
/**
* Creates a ready-to-mount component view.
*/
@interface RCTCreateMountItem : NSObject <RCTMountItemProtocol>
- (instancetype)initWithComponentName:(NSString *)componentName
tag:(ReactTag)tag;
@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 "RCTCreateMountItem.h"
#import "RCTComponentViewRegistry.h"
@implementation RCTCreateMountItem {
NSString *_componentName;
ReactTag _tag;
}
- (instancetype)initWithComponentName:(NSString *)componentName
tag:(ReactTag)tag
{
if (self = [super init]) {
_componentName = componentName;
_tag = tag;
}
return self;
}
- (void)executeWithRegistry:(RCTComponentViewRegistry *)registry
{
[registry dequeueComponentViewWithName:_componentName tag:_tag];
}
@end

View File

@ -0,0 +1,25 @@
/**
* 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>
NS_ASSUME_NONNULL_BEGIN
/**
* Deletes (returns to recycle pool) a component view.
*/
@interface RCTDeleteMountItem : NSObject <RCTMountItemProtocol>
- (instancetype)initWithComponentName:(NSString *)componentName
tag:(ReactTag)tag;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,34 @@
/**
* 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 "RCTDeleteMountItem.h"
#import "RCTComponentViewRegistry.h"
@implementation RCTDeleteMountItem {
NSString *_componentName;
ReactTag _tag;
}
- (instancetype)initWithComponentName:(NSString *)componentName
tag:(ReactTag)tag
{
if (self = [super init]) {
_componentName = componentName;
_tag = tag;
}
return self;
}
- (void)executeWithRegistry:(RCTComponentViewRegistry *)registry
{
UIView<RCTComponentViewProtocol> *componentView = [registry componentViewByTag:_tag];
[registry enqueueComponentViewWithName:_componentName tag:_tag componentView:componentView];
}
@end

View File

@ -0,0 +1,28 @@
/**
* 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>
NS_ASSUME_NONNULL_BEGIN
@class RCTComponentViewRegistry;
/**
* Inserts a component view into another component view.
*/
@interface RCTInsertMountItem : NSObject <RCTMountItemProtocol>
- (instancetype)initWithChildTag:(ReactTag)childTag
parentTag:(ReactTag)parentTag
index:(NSInteger)index;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,40 @@
/**
* 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 "RCTInsertMountItem.h"
#import "RCTComponentViewRegistry.h"
@implementation RCTInsertMountItem {
ReactTag _childTag;
ReactTag _parentTag;
NSInteger _index;
}
- (instancetype)initWithChildTag:(ReactTag)childTag
parentTag:(ReactTag)parentTag
index:(NSInteger)index
{
if (self = [super init]) {
_childTag = childTag;
_parentTag = parentTag;
_index = index;
}
return self;
}
- (void)executeWithRegistry:(RCTComponentViewRegistry *)registry
{
UIView<RCTComponentViewProtocol> *childComponentView = [registry componentViewByTag:_childTag];
UIView<RCTComponentViewProtocol> *parentComponentView = [registry componentViewByTag:_parentTag];
[parentComponentView mountChildComponentView:childComponentView
index:_index];
}
@end

View File

@ -0,0 +1,23 @@
/**
* 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>
NS_ASSUME_NONNULL_BEGIN
@class RCTComponentViewRegistry;
/**
* Granular representation of any change in a user interface.
*/
@protocol RCTMountItemProtocol <NSObject>
- (void)executeWithRegistry:(RCTComponentViewRegistry *)registry;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,26 @@
/**
* 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>
NS_ASSUME_NONNULL_BEGIN
/**
* Removes a component view from another component view.
*/
@interface RCTRemoveMountItem : NSObject <RCTMountItemProtocol>
- (instancetype)initWithChildTag:(ReactTag)childTag
parentTag:(ReactTag)parentTag
index:(NSInteger)index;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,40 @@
/**
* 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 "RCTRemoveMountItem.h"
#import "RCTComponentViewRegistry.h"
@implementation RCTRemoveMountItem {
ReactTag _childTag;
ReactTag _parentTag;
NSInteger _index;
}
- (instancetype)initWithChildTag:(ReactTag)childTag
parentTag:(ReactTag)parentTag
index:(NSInteger)index
{
if (self = [super init]) {
_childTag = childTag;
_parentTag = parentTag;
_index = index;
}
return self;
}
- (void)executeWithRegistry:(RCTComponentViewRegistry *)registry
{
UIView<RCTComponentViewProtocol> *childComponentView = [registry componentViewByTag:_childTag];
UIView<RCTComponentViewProtocol> *parentComponentView = [registry componentViewByTag:_parentTag];
[parentComponentView unmountChildComponentView:childComponentView
index:_index];
}
@end

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/LayoutMetrics.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Updates layout metrics of a component view.
*/
@interface RCTUpdateLayoutMetricsMountItem : NSObject <RCTMountItemProtocol>
- (instancetype)initWithTag:(ReactTag)tag
oldLayoutMetrics:(facebook::react::LayoutMetrics)oldLayoutMetrics
newLayoutMetrics:(facebook::react::LayoutMetrics)newLayoutMetrics;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,41 @@
/**
* 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 "RCTUpdateLayoutMetricsMountItem.h"
#import "RCTComponentViewRegistry.h"
using namespace facebook::react;
@implementation RCTUpdateLayoutMetricsMountItem {
ReactTag _tag;
LayoutMetrics _oldLayoutMetrics;
LayoutMetrics _newLayoutMetrics;
}
- (instancetype)initWithTag:(ReactTag)tag
oldLayoutMetrics:(facebook::react::LayoutMetrics)oldLayoutMetrics
newLayoutMetrics:(facebook::react::LayoutMetrics)newLayoutMetrics
{
if (self = [super init]) {
_tag = tag;
_oldLayoutMetrics = oldLayoutMetrics;
_newLayoutMetrics = newLayoutMetrics;
}
return self;
}
- (void)executeWithRegistry:(RCTComponentViewRegistry *)registry
{
UIView<RCTComponentViewProtocol> *componentView = [registry componentViewByTag:_tag];
[componentView updateLayoutMetrics:_newLayoutMetrics
oldLayoutMetrics:_oldLayoutMetrics];
}
@end

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/Props.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Updates props of a component view.
*/
@interface RCTUpdatePropsMountItem : NSObject <RCTMountItemProtocol>
- (instancetype)initWithTag:(ReactTag)tag
oldProps:(facebook::react::SharedProps)oldProps
newProps:(facebook::react::SharedProps)newProps;
@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 "RCTUpdatePropsMountItem.h"
#import "RCTComponentViewRegistry.h"
using namespace facebook::react;
@implementation RCTUpdatePropsMountItem {
ReactTag _tag;
SharedProps _oldProps;
SharedProps _newProps;
}
- (instancetype)initWithTag:(ReactTag)tag
oldProps:(SharedProps)oldProps
newProps:(SharedProps)newProps
{
if (self = [super init]) {
_tag = tag;
_oldProps = oldProps;
_newProps = newProps;
}
return self;
}
- (void)executeWithRegistry:(RCTComponentViewRegistry *)registry
{
UIView<RCTComponentViewProtocol> *componentView = [registry componentViewByTag:_tag];
[componentView updateProps:_newProps oldProps:_oldProps];
}
@end