From 11833714d9a98b3963e28f025b4fafb03497b0d1 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 10 Apr 2018 16:36:47 -0700 Subject: [PATCH] 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 --- .../Mounting/MountItems/RCTCreateMountItem.h | 27 ++++++++++++ .../Mounting/MountItems/RCTCreateMountItem.mm | 33 +++++++++++++++ .../Mounting/MountItems/RCTDeleteMountItem.h | 25 +++++++++++ .../Mounting/MountItems/RCTDeleteMountItem.mm | 34 +++++++++++++++ .../Mounting/MountItems/RCTInsertMountItem.h | 28 +++++++++++++ .../Mounting/MountItems/RCTInsertMountItem.mm | 40 ++++++++++++++++++ .../MountItems/RCTMountItemProtocol.h | 23 +++++++++++ .../Mounting/MountItems/RCTRemoveMountItem.h | 26 ++++++++++++ .../Mounting/MountItems/RCTRemoveMountItem.mm | 40 ++++++++++++++++++ .../RCTUpdateLayoutMetricsMountItem.h | 27 ++++++++++++ .../RCTUpdateLayoutMetricsMountItem.mm | 41 +++++++++++++++++++ .../MountItems/RCTUpdatePropsMountItem.h | 27 ++++++++++++ .../MountItems/RCTUpdatePropsMountItem.mm | 39 ++++++++++++++++++ 13 files changed, 410 insertions(+) create mode 100644 React/Fabric/Mounting/MountItems/RCTCreateMountItem.h create mode 100644 React/Fabric/Mounting/MountItems/RCTCreateMountItem.mm create mode 100644 React/Fabric/Mounting/MountItems/RCTDeleteMountItem.h create mode 100644 React/Fabric/Mounting/MountItems/RCTDeleteMountItem.mm create mode 100644 React/Fabric/Mounting/MountItems/RCTInsertMountItem.h create mode 100644 React/Fabric/Mounting/MountItems/RCTInsertMountItem.mm create mode 100644 React/Fabric/Mounting/MountItems/RCTMountItemProtocol.h create mode 100644 React/Fabric/Mounting/MountItems/RCTRemoveMountItem.h create mode 100644 React/Fabric/Mounting/MountItems/RCTRemoveMountItem.mm create mode 100644 React/Fabric/Mounting/MountItems/RCTUpdateLayoutMetricsMountItem.h create mode 100644 React/Fabric/Mounting/MountItems/RCTUpdateLayoutMetricsMountItem.mm create mode 100644 React/Fabric/Mounting/MountItems/RCTUpdatePropsMountItem.h create mode 100644 React/Fabric/Mounting/MountItems/RCTUpdatePropsMountItem.mm diff --git a/React/Fabric/Mounting/MountItems/RCTCreateMountItem.h b/React/Fabric/Mounting/MountItems/RCTCreateMountItem.h new file mode 100644 index 00000000000..6376094894d --- /dev/null +++ b/React/Fabric/Mounting/MountItems/RCTCreateMountItem.h @@ -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 + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@class RCTComponentViewRegistry; + +/** + * Creates a ready-to-mount component view. + */ +@interface RCTCreateMountItem : NSObject + +- (instancetype)initWithComponentName:(NSString *)componentName + tag:(ReactTag)tag; + +@end + +NS_ASSUME_NONNULL_END diff --git a/React/Fabric/Mounting/MountItems/RCTCreateMountItem.mm b/React/Fabric/Mounting/MountItems/RCTCreateMountItem.mm new file mode 100644 index 00000000000..df04396b476 --- /dev/null +++ b/React/Fabric/Mounting/MountItems/RCTCreateMountItem.mm @@ -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 diff --git a/React/Fabric/Mounting/MountItems/RCTDeleteMountItem.h b/React/Fabric/Mounting/MountItems/RCTDeleteMountItem.h new file mode 100644 index 00000000000..a4c6077b56f --- /dev/null +++ b/React/Fabric/Mounting/MountItems/RCTDeleteMountItem.h @@ -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 + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +/** + * Deletes (returns to recycle pool) a component view. + */ +@interface RCTDeleteMountItem : NSObject + +- (instancetype)initWithComponentName:(NSString *)componentName + tag:(ReactTag)tag; + +@end + +NS_ASSUME_NONNULL_END diff --git a/React/Fabric/Mounting/MountItems/RCTDeleteMountItem.mm b/React/Fabric/Mounting/MountItems/RCTDeleteMountItem.mm new file mode 100644 index 00000000000..99909f450cc --- /dev/null +++ b/React/Fabric/Mounting/MountItems/RCTDeleteMountItem.mm @@ -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 *componentView = [registry componentViewByTag:_tag]; + [registry enqueueComponentViewWithName:_componentName tag:_tag componentView:componentView]; +} + +@end diff --git a/React/Fabric/Mounting/MountItems/RCTInsertMountItem.h b/React/Fabric/Mounting/MountItems/RCTInsertMountItem.h new file mode 100644 index 00000000000..e3d4ac29d7a --- /dev/null +++ b/React/Fabric/Mounting/MountItems/RCTInsertMountItem.h @@ -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 + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +@class RCTComponentViewRegistry; + +/** + * Inserts a component view into another component view. + */ +@interface RCTInsertMountItem : NSObject + +- (instancetype)initWithChildTag:(ReactTag)childTag + parentTag:(ReactTag)parentTag + index:(NSInteger)index; + +@end + +NS_ASSUME_NONNULL_END diff --git a/React/Fabric/Mounting/MountItems/RCTInsertMountItem.mm b/React/Fabric/Mounting/MountItems/RCTInsertMountItem.mm new file mode 100644 index 00000000000..f714cb0a70d --- /dev/null +++ b/React/Fabric/Mounting/MountItems/RCTInsertMountItem.mm @@ -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 *childComponentView = [registry componentViewByTag:_childTag]; + UIView *parentComponentView = [registry componentViewByTag:_parentTag]; + + [parentComponentView mountChildComponentView:childComponentView + index:_index]; +} + +@end diff --git a/React/Fabric/Mounting/MountItems/RCTMountItemProtocol.h b/React/Fabric/Mounting/MountItems/RCTMountItemProtocol.h new file mode 100644 index 00000000000..f46c397498b --- /dev/null +++ b/React/Fabric/Mounting/MountItems/RCTMountItemProtocol.h @@ -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 + +NS_ASSUME_NONNULL_BEGIN + +@class RCTComponentViewRegistry; + +/** + * Granular representation of any change in a user interface. + */ +@protocol RCTMountItemProtocol + +- (void)executeWithRegistry:(RCTComponentViewRegistry *)registry; + +@end + +NS_ASSUME_NONNULL_END diff --git a/React/Fabric/Mounting/MountItems/RCTRemoveMountItem.h b/React/Fabric/Mounting/MountItems/RCTRemoveMountItem.h new file mode 100644 index 00000000000..0fe9555a613 --- /dev/null +++ b/React/Fabric/Mounting/MountItems/RCTRemoveMountItem.h @@ -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 + +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +/** + * Removes a component view from another component view. + */ +@interface RCTRemoveMountItem : NSObject + +- (instancetype)initWithChildTag:(ReactTag)childTag + parentTag:(ReactTag)parentTag + index:(NSInteger)index; + +@end + +NS_ASSUME_NONNULL_END diff --git a/React/Fabric/Mounting/MountItems/RCTRemoveMountItem.mm b/React/Fabric/Mounting/MountItems/RCTRemoveMountItem.mm new file mode 100644 index 00000000000..d46b936dd04 --- /dev/null +++ b/React/Fabric/Mounting/MountItems/RCTRemoveMountItem.mm @@ -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 *childComponentView = [registry componentViewByTag:_childTag]; + UIView *parentComponentView = [registry componentViewByTag:_parentTag]; + + [parentComponentView unmountChildComponentView:childComponentView + index:_index]; +} + +@end diff --git a/React/Fabric/Mounting/MountItems/RCTUpdateLayoutMetricsMountItem.h b/React/Fabric/Mounting/MountItems/RCTUpdateLayoutMetricsMountItem.h new file mode 100644 index 00000000000..378c179d3c4 --- /dev/null +++ b/React/Fabric/Mounting/MountItems/RCTUpdateLayoutMetricsMountItem.h @@ -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 + +#import +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +/** + * Updates layout metrics of a component view. + */ +@interface RCTUpdateLayoutMetricsMountItem : NSObject + +- (instancetype)initWithTag:(ReactTag)tag + oldLayoutMetrics:(facebook::react::LayoutMetrics)oldLayoutMetrics + newLayoutMetrics:(facebook::react::LayoutMetrics)newLayoutMetrics; + +@end + +NS_ASSUME_NONNULL_END diff --git a/React/Fabric/Mounting/MountItems/RCTUpdateLayoutMetricsMountItem.mm b/React/Fabric/Mounting/MountItems/RCTUpdateLayoutMetricsMountItem.mm new file mode 100644 index 00000000000..c61a043626a --- /dev/null +++ b/React/Fabric/Mounting/MountItems/RCTUpdateLayoutMetricsMountItem.mm @@ -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 *componentView = [registry componentViewByTag:_tag]; + + [componentView updateLayoutMetrics:_newLayoutMetrics + oldLayoutMetrics:_oldLayoutMetrics]; +} + +@end diff --git a/React/Fabric/Mounting/MountItems/RCTUpdatePropsMountItem.h b/React/Fabric/Mounting/MountItems/RCTUpdatePropsMountItem.h new file mode 100644 index 00000000000..efdfed64ddb --- /dev/null +++ b/React/Fabric/Mounting/MountItems/RCTUpdatePropsMountItem.h @@ -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 + +#import +#import +#import + +NS_ASSUME_NONNULL_BEGIN + +/** + * Updates props of a component view. + */ +@interface RCTUpdatePropsMountItem : NSObject + +- (instancetype)initWithTag:(ReactTag)tag + oldProps:(facebook::react::SharedProps)oldProps + newProps:(facebook::react::SharedProps)newProps; + +@end + +NS_ASSUME_NONNULL_END diff --git a/React/Fabric/Mounting/MountItems/RCTUpdatePropsMountItem.mm b/React/Fabric/Mounting/MountItems/RCTUpdatePropsMountItem.mm new file mode 100644 index 00000000000..694b72e4046 --- /dev/null +++ b/React/Fabric/Mounting/MountItems/RCTUpdatePropsMountItem.mm @@ -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 *componentView = [registry componentViewByTag:_tag]; + [componentView updateProps:_newProps oldProps:_oldProps]; +} + +@end