mirror of
https://github.com/status-im/react-native.git
synced 2025-02-26 08:05:34 +00:00
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:
parent
dfb8fd26e6
commit
11833714d9
27
React/Fabric/Mounting/MountItems/RCTCreateMountItem.h
Normal file
27
React/Fabric/Mounting/MountItems/RCTCreateMountItem.h
Normal 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
|
33
React/Fabric/Mounting/MountItems/RCTCreateMountItem.mm
Normal file
33
React/Fabric/Mounting/MountItems/RCTCreateMountItem.mm
Normal 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
|
25
React/Fabric/Mounting/MountItems/RCTDeleteMountItem.h
Normal file
25
React/Fabric/Mounting/MountItems/RCTDeleteMountItem.h
Normal 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
|
34
React/Fabric/Mounting/MountItems/RCTDeleteMountItem.mm
Normal file
34
React/Fabric/Mounting/MountItems/RCTDeleteMountItem.mm
Normal 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
|
28
React/Fabric/Mounting/MountItems/RCTInsertMountItem.h
Normal file
28
React/Fabric/Mounting/MountItems/RCTInsertMountItem.h
Normal 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
|
40
React/Fabric/Mounting/MountItems/RCTInsertMountItem.mm
Normal file
40
React/Fabric/Mounting/MountItems/RCTInsertMountItem.mm
Normal 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
|
23
React/Fabric/Mounting/MountItems/RCTMountItemProtocol.h
Normal file
23
React/Fabric/Mounting/MountItems/RCTMountItemProtocol.h
Normal 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
|
26
React/Fabric/Mounting/MountItems/RCTRemoveMountItem.h
Normal file
26
React/Fabric/Mounting/MountItems/RCTRemoveMountItem.h
Normal 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
|
40
React/Fabric/Mounting/MountItems/RCTRemoveMountItem.mm
Normal file
40
React/Fabric/Mounting/MountItems/RCTRemoveMountItem.mm
Normal 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
|
@ -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
|
@ -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
|
27
React/Fabric/Mounting/MountItems/RCTUpdatePropsMountItem.h
Normal file
27
React/Fabric/Mounting/MountItems/RCTUpdatePropsMountItem.h
Normal 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
|
39
React/Fabric/Mounting/MountItems/RCTUpdatePropsMountItem.mm
Normal file
39
React/Fabric/Mounting/MountItems/RCTUpdatePropsMountItem.mm
Normal 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
|
Loading…
x
Reference in New Issue
Block a user