diff --git a/React/Fabric/Mounting/MountItems/RCTCreateMountItem.h b/React/Fabric/Mounting/MountItems/RCTCreateMountItem.h deleted file mode 100644 index a503df5a98a..00000000000 --- a/React/Fabric/Mounting/MountItems/RCTCreateMountItem.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * 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 - -@class RCTComponentViewRegistry; - -/** - * Creates a ready-to-mount component view. - */ -@interface RCTCreateMountItem : NSObject - -- (instancetype)initWithComponentHandle:(facebook::react::ComponentHandle)componentHandle tag:(ReactTag)tag; - -@end - -NS_ASSUME_NONNULL_END diff --git a/React/Fabric/Mounting/MountItems/RCTCreateMountItem.mm b/React/Fabric/Mounting/MountItems/RCTCreateMountItem.mm deleted file mode 100644 index ace7dad11ea..00000000000 --- a/React/Fabric/Mounting/MountItems/RCTCreateMountItem.mm +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * 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" - -using namespace facebook::react; - -@implementation RCTCreateMountItem { - ComponentHandle _componentHandle; - ReactTag _tag; -} - -- (instancetype)initWithComponentHandle:(facebook::react::ComponentHandle)componentHandle tag:(ReactTag)tag -{ - if (self = [super init]) { - _componentHandle = componentHandle; - _tag = tag; - } - - return self; -} - -- (void)executeWithRegistry:(RCTComponentViewRegistry *)registry -{ - [registry dequeueComponentViewWithComponentHandle:_componentHandle tag:_tag]; -} - -@end diff --git a/React/Fabric/Mounting/MountItems/RCTDeleteMountItem.h b/React/Fabric/Mounting/MountItems/RCTDeleteMountItem.h deleted file mode 100644 index ac53f3c22aa..00000000000 --- a/React/Fabric/Mounting/MountItems/RCTDeleteMountItem.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * 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 - -/** - * Deletes (returns to recycle pool) a component view. - */ -@interface RCTDeleteMountItem : NSObject - -- (instancetype)initWithComponentHandle:(facebook::react::ComponentHandle)componentHandle tag:(ReactTag)tag; - -@end - -NS_ASSUME_NONNULL_END diff --git a/React/Fabric/Mounting/MountItems/RCTDeleteMountItem.mm b/React/Fabric/Mounting/MountItems/RCTDeleteMountItem.mm deleted file mode 100644 index 58f20cec1b9..00000000000 --- a/React/Fabric/Mounting/MountItems/RCTDeleteMountItem.mm +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * 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" - -using namespace facebook::react; - -@implementation RCTDeleteMountItem { - ComponentHandle _componentHandle; - ReactTag _tag; -} - -- (instancetype)initWithComponentHandle:(facebook::react::ComponentHandle)componentHandle tag:(ReactTag)tag -{ - if (self = [super init]) { - _componentHandle = componentHandle; - _tag = tag; - } - - return self; -} - -- (void)executeWithRegistry:(RCTComponentViewRegistry *)registry -{ - UIView *componentView = [registry componentViewByTag:_tag]; - - if (componentView == nil) { - return; - } - - [registry enqueueComponentViewWithComponentHandle:_componentHandle tag:_tag componentView:componentView]; -} - -@end diff --git a/React/Fabric/Mounting/MountItems/RCTInsertMountItem.h b/React/Fabric/Mounting/MountItems/RCTInsertMountItem.h deleted file mode 100644 index 43a0d24035d..00000000000 --- a/React/Fabric/Mounting/MountItems/RCTInsertMountItem.h +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * 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 deleted file mode 100644 index fad2f055aa9..00000000000 --- a/React/Fabric/Mounting/MountItems/RCTInsertMountItem.mm +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * 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]; - - if (childComponentView == nil || parentComponentView == nil) { - return; - } - - [parentComponentView mountChildComponentView:childComponentView index:_index]; -} - -@end diff --git a/React/Fabric/Mounting/MountItems/RCTMountItemProtocol.h b/React/Fabric/Mounting/MountItems/RCTMountItemProtocol.h deleted file mode 100644 index 4f3d7fe4b59..00000000000 --- a/React/Fabric/Mounting/MountItems/RCTMountItemProtocol.h +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * 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 deleted file mode 100644 index ec8b58403d6..00000000000 --- a/React/Fabric/Mounting/MountItems/RCTRemoveMountItem.h +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * 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 deleted file mode 100644 index e753c03f656..00000000000 --- a/React/Fabric/Mounting/MountItems/RCTRemoveMountItem.mm +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * 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]; - - if (childComponentView == nil || parentComponentView == nil) { - return; - } - - [parentComponentView unmountChildComponentView:childComponentView index:_index]; -} - -@end diff --git a/React/Fabric/Mounting/MountItems/RCTUpdateEventEmitterMountItem.h b/React/Fabric/Mounting/MountItems/RCTUpdateEventEmitterMountItem.h deleted file mode 100644 index 5c0595f7fc4..00000000000 --- a/React/Fabric/Mounting/MountItems/RCTUpdateEventEmitterMountItem.h +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * 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 event handlers of a component view. - */ -@interface RCTUpdateEventEmitterMountItem : NSObject - -- (instancetype)initWithTag:(ReactTag)tag eventEmitter:(facebook::react::SharedEventEmitter)eventEmitter; - -@end - -NS_ASSUME_NONNULL_END diff --git a/React/Fabric/Mounting/MountItems/RCTUpdateEventEmitterMountItem.mm b/React/Fabric/Mounting/MountItems/RCTUpdateEventEmitterMountItem.mm deleted file mode 100644 index 6ef2fee2c6f..00000000000 --- a/React/Fabric/Mounting/MountItems/RCTUpdateEventEmitterMountItem.mm +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import "RCTUpdateEventEmitterMountItem.h" - -#import "RCTComponentViewRegistry.h" - -using namespace facebook::react; - -@implementation RCTUpdateEventEmitterMountItem { - ReactTag _tag; - SharedEventEmitter _eventEmitter; -} - -- (instancetype)initWithTag:(ReactTag)tag eventEmitter:(SharedEventEmitter)eventEmitter -{ - if (self = [super init]) { - _tag = tag; - _eventEmitter = eventEmitter; - } - - return self; -} - -- (void)executeWithRegistry:(RCTComponentViewRegistry *)registry -{ - UIView *componentView = [registry componentViewByTag:_tag]; - - [componentView updateEventEmitter:_eventEmitter]; -} - -@end diff --git a/React/Fabric/Mounting/MountItems/RCTUpdateLayoutMetricsMountItem.h b/React/Fabric/Mounting/MountItems/RCTUpdateLayoutMetricsMountItem.h deleted file mode 100644 index 7fbab407cdf..00000000000 --- a/React/Fabric/Mounting/MountItems/RCTUpdateLayoutMetricsMountItem.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * 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 deleted file mode 100644 index 695ac1d3517..00000000000 --- a/React/Fabric/Mounting/MountItems/RCTUpdateLayoutMetricsMountItem.mm +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * 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/RCTUpdateLocalDataMountItem.h b/React/Fabric/Mounting/MountItems/RCTUpdateLocalDataMountItem.h deleted file mode 100644 index f25d4b7aa44..00000000000 --- a/React/Fabric/Mounting/MountItems/RCTUpdateLocalDataMountItem.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * 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 local data of a component view. - */ -@interface RCTUpdateLocalDataMountItem : NSObject - -- (instancetype)initWithTag:(ReactTag)tag - oldLocalData:(facebook::react::SharedLocalData)oldLocalData - newLocalData:(facebook::react::SharedLocalData)newLocalData; - -@end - -NS_ASSUME_NONNULL_END diff --git a/React/Fabric/Mounting/MountItems/RCTUpdateLocalDataMountItem.mm b/React/Fabric/Mounting/MountItems/RCTUpdateLocalDataMountItem.mm deleted file mode 100644 index 80ae5af8f0c..00000000000 --- a/React/Fabric/Mounting/MountItems/RCTUpdateLocalDataMountItem.mm +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * 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 *componentView = [registry componentViewByTag:_tag]; - [componentView updateLocalData:_newLocalData oldLocalData:_oldLocalData]; -} - -@end diff --git a/React/Fabric/Mounting/MountItems/RCTUpdatePropsMountItem.h b/React/Fabric/Mounting/MountItems/RCTUpdatePropsMountItem.h deleted file mode 100644 index 7c05196e5d5..00000000000 --- a/React/Fabric/Mounting/MountItems/RCTUpdatePropsMountItem.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * 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 deleted file mode 100644 index ae415cb445c..00000000000 --- a/React/Fabric/Mounting/MountItems/RCTUpdatePropsMountItem.mm +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * 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 diff --git a/React/Fabric/Mounting/MountItems/RCTUpdateStateMountItem.h b/React/Fabric/Mounting/MountItems/RCTUpdateStateMountItem.h deleted file mode 100644 index f92eb00be24..00000000000 --- a/React/Fabric/Mounting/MountItems/RCTUpdateStateMountItem.h +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * 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 state of a component view. - */ -@interface RCTUpdateStateMountItem : NSObject - -- (instancetype)initWithTag:(ReactTag)tag - oldState:(facebook::react::State::Shared)oldState - newState:(facebook::react::State::Shared)newState; - -@end - -NS_ASSUME_NONNULL_END diff --git a/React/Fabric/Mounting/MountItems/RCTUpdateStateMountItem.mm b/React/Fabric/Mounting/MountItems/RCTUpdateStateMountItem.mm deleted file mode 100644 index ec6949f204a..00000000000 --- a/React/Fabric/Mounting/MountItems/RCTUpdateStateMountItem.mm +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import "RCTUpdateStateMountItem.h" - -#import "RCTComponentViewRegistry.h" - -using namespace facebook::react; - -@implementation RCTUpdateStateMountItem { - ReactTag _tag; - State::Shared _oldState; - State::Shared _newState; -} - -- (instancetype)initWithTag:(ReactTag)tag - oldState:(facebook::react::State::Shared)oldState - newState:(facebook::react::State::Shared)newState -{ - if (self = [super init]) { - _tag = tag; - _oldState = oldState; - _newState = newState; - } - - return self; -} - -- (void)executeWithRegistry:(RCTComponentViewRegistry *)registry -{ - UIView *componentView = [registry componentViewByTag:_tag]; - [componentView updateState:_newState oldState:_oldState]; -} - -@end diff --git a/React/Fabric/Mounting/RCTMountingManager.h b/React/Fabric/Mounting/RCTMountingManager.h index 19d945abb67..28f7858028f 100644 --- a/React/Fabric/Mounting/RCTMountingManager.h +++ b/React/Fabric/Mounting/RCTMountingManager.h @@ -27,11 +27,10 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, strong) RCTComponentViewRegistry *componentViewRegistry; /** - * Transfroms mutation instructions to mount items and executes them. - * The order of mutation instructions matters. + * Schedule mutations to be performed on the main thread. * Can be called from any thread. */ -- (void)performTransactionWithMutations:(facebook::react::ShadowViewMutationList)mutations rootTag:(ReactTag)rootTag; +- (void)scheduleMutations:(facebook::react::ShadowViewMutationList const &)mutations rootTag:(ReactTag)rootTag; /** * Suggests preliminary creation of a component view of given type. diff --git a/React/Fabric/Mounting/RCTMountingManager.mm b/React/Fabric/Mounting/RCTMountingManager.mm index 6ae40799291..62657530d8b 100644 --- a/React/Fabric/Mounting/RCTMountingManager.mm +++ b/React/Fabric/Mounting/RCTMountingManager.mm @@ -16,21 +16,165 @@ #import "RCTComponentViewProtocol.h" #import "RCTComponentViewRegistry.h" -#import "RCTMountItemProtocol.h" - #import "RCTConversions.h" -#import "RCTCreateMountItem.h" -#import "RCTDeleteMountItem.h" -#import "RCTInsertMountItem.h" -#import "RCTRemoveMountItem.h" -#import "RCTUpdateEventEmitterMountItem.h" -#import "RCTUpdateLayoutMetricsMountItem.h" -#import "RCTUpdateLocalDataMountItem.h" -#import "RCTUpdatePropsMountItem.h" -#import "RCTUpdateStateMountItem.h" using namespace facebook::react; +// `Create` instruction +static void RNCreateMountInstruction(ShadowViewMutation const &mutation, RCTComponentViewRegistry *registry) +{ + [registry dequeueComponentViewWithComponentHandle:mutation.newChildShadowView.componentHandle + tag:mutation.newChildShadowView.tag]; +} + +// `Delete` instruction +static void RNDeleteMountInstruction(ShadowViewMutation const &mutation, RCTComponentViewRegistry *registry) +{ + auto const &oldChildShadowView = mutation.oldChildShadowView; + UIView *componentView = [registry componentViewByTag:oldChildShadowView.tag]; + + // TODO(shergin): Make sure that we don't need this check anymore and delete it. + if (componentView == nil) { + return; + } + + [registry enqueueComponentViewWithComponentHandle:oldChildShadowView.componentHandle + tag:oldChildShadowView.tag + componentView:componentView]; +} + +// `Insert` instruction +static void RNInsertMountInstruction(ShadowViewMutation const &mutation, RCTComponentViewRegistry *registry) +{ + auto const &newShadowView = mutation.newChildShadowView; + auto const &parentShadowView = mutation.parentShadowView; + + UIView *childComponentView = [registry componentViewByTag:newShadowView.tag]; + UIView *parentComponentView = [registry componentViewByTag:parentShadowView.tag]; + + // TODO(shergin): Make sure that we don't need this check anymore and delete it. + if (childComponentView == nil || parentComponentView == nil) { + return; + } + + [parentComponentView mountChildComponentView:childComponentView index:mutation.index]; +} + +// `Remove` instruction +static void RNRemoveMountInstruction(ShadowViewMutation const &mutation, RCTComponentViewRegistry *registry) +{ + auto const &oldShadowView = mutation.oldChildShadowView; + auto const &parentShadowView = mutation.parentShadowView; + + UIView *childComponentView = [registry componentViewByTag:oldShadowView.tag]; + UIView *parentComponentView = [registry componentViewByTag:parentShadowView.tag]; + + // TODO(shergin): Make sure that we don't need this check anymore and delete it. + if (childComponentView == nil || parentComponentView == nil) { + return; + } + + [parentComponentView unmountChildComponentView:childComponentView index:mutation.index]; +} + +// `Update Props` instruction +static void RNUpdatePropsMountInstruction(ShadowViewMutation const &mutation, RCTComponentViewRegistry *registry) +{ + auto const &oldShadowView = mutation.oldChildShadowView; + auto const &newShadowView = mutation.newChildShadowView; + UIView *componentView = [registry componentViewByTag:newShadowView.tag]; + [componentView updateProps:newShadowView.props oldProps:oldShadowView.props]; +} + +// `Update EventEmitter` instruction +static void RNUpdateEventEmitterMountInstruction(ShadowViewMutation const &mutation, RCTComponentViewRegistry *registry) +{ + auto const &newShadowView = mutation.newChildShadowView; + UIView *componentView = [registry componentViewByTag:newShadowView.tag]; + [componentView updateEventEmitter:newShadowView.eventEmitter]; +} + +// `Update LayoutMetrics` instruction +static void RNUpdateLayoutMetricsMountInstruction( + ShadowViewMutation const &mutation, + RCTComponentViewRegistry *registry) +{ + auto const &oldShadowView = mutation.oldChildShadowView; + auto const &newShadowView = mutation.newChildShadowView; + UIView *componentView = [registry componentViewByTag:newShadowView.tag]; + [componentView updateLayoutMetrics:newShadowView.layoutMetrics oldLayoutMetrics:oldShadowView.layoutMetrics]; +} + +// `Update LocalData` instruction +static void RNUpdateLocalDataMountInstruction(ShadowViewMutation const &mutation, RCTComponentViewRegistry *registry) +{ + auto const &oldShadowView = mutation.oldChildShadowView; + auto const &newShadowView = mutation.newChildShadowView; + UIView *componentView = [registry componentViewByTag:newShadowView.tag]; + [componentView updateLocalData:newShadowView.localData oldLocalData:oldShadowView.localData]; +} + +// `Update State` instruction +static void RNUpdateStateMountInstruction(ShadowViewMutation const &mutation, RCTComponentViewRegistry *registry) +{ + auto const &oldShadowView = mutation.oldChildShadowView; + auto const &newShadowView = mutation.newChildShadowView; + UIView *componentView = [registry componentViewByTag:newShadowView.tag]; + [componentView updateState:newShadowView.state oldState:oldShadowView.state]; +} + +// `Update` instruction +static void RNPerformMountInstructions(ShadowViewMutationList const &mutations, RCTComponentViewRegistry *registry) +{ + SystraceSection s("RNPerformMountInstructions"); + + for (auto const &mutation : mutations) { + switch (mutation.type) { + case ShadowViewMutation::Create: { + RNCreateMountInstruction(mutation, registry); + break; + } + case ShadowViewMutation::Delete: { + RNDeleteMountInstruction(mutation, registry); + break; + } + case ShadowViewMutation::Insert: { + RNUpdatePropsMountInstruction(mutation, registry); + RNUpdateEventEmitterMountInstruction(mutation, registry); + RNUpdateLocalDataMountInstruction(mutation, registry); + RNUpdateStateMountInstruction(mutation, registry); + RNUpdateLayoutMetricsMountInstruction(mutation, registry); + RNInsertMountInstruction(mutation, registry); + break; + } + case ShadowViewMutation::Remove: { + RNRemoveMountInstruction(mutation, registry); + break; + } + case ShadowViewMutation::Update: { + auto const &oldChildShadowView = mutation.oldChildShadowView; + auto const &newChildShadowView = mutation.newChildShadowView; + if (oldChildShadowView.props != newChildShadowView.props) { + RNUpdatePropsMountInstruction(mutation, registry); + } + if (oldChildShadowView.eventEmitter != newChildShadowView.eventEmitter) { + RNUpdateEventEmitterMountInstruction(mutation, registry); + } + if (oldChildShadowView.localData != newChildShadowView.localData) { + RNUpdateLocalDataMountInstruction(mutation, registry); + } + if (oldChildShadowView.state != newChildShadowView.state) { + RNUpdateStateMountInstruction(mutation, registry); + } + if (oldChildShadowView.layoutMetrics != newChildShadowView.layoutMetrics) { + RNUpdateLayoutMetricsMountInstruction(mutation, registry); + } + break; + } + } + } +} + @implementation RCTMountingManager - (instancetype)init @@ -42,155 +186,34 @@ using namespace facebook::react; return self; } -- (void)performTransactionWithMutations:(ShadowViewMutationList)mutations rootTag:(ReactTag)rootTag +- (void)scheduleMutations:(ShadowViewMutationList const &)mutations rootTag:(ReactTag)rootTag { - NSMutableArray *mountItems; - - { - // This section is measured separately from `_performMountItems:rootTag:` because that can be asynchronous. - SystraceSection s("-[RCTMountingManager performTransactionWithMutations:rootTag:]"); - - mountItems = - [[NSMutableArray alloc] initWithCapacity:mutations.size() * 2 /* ~ the worst case */]; - - for (const auto &mutation : mutations) { - switch (mutation.type) { - case ShadowViewMutation::Create: { - RCTCreateMountItem *mountItem = - [[RCTCreateMountItem alloc] initWithComponentHandle:mutation.newChildShadowView.componentHandle - tag:mutation.newChildShadowView.tag]; - [mountItems addObject:mountItem]; - break; - } - - case ShadowViewMutation::Delete: { - RCTDeleteMountItem *mountItem = - [[RCTDeleteMountItem alloc] initWithComponentHandle:mutation.oldChildShadowView.componentHandle - tag:mutation.oldChildShadowView.tag]; - [mountItems addObject:mountItem]; - break; - } - - case ShadowViewMutation::Insert: { - // Props - [mountItems addObject:[[RCTUpdatePropsMountItem alloc] initWithTag:mutation.newChildShadowView.tag - oldProps:nullptr - newProps:mutation.newChildShadowView.props]]; - - // EventEmitter - [mountItems - addObject:[[RCTUpdateEventEmitterMountItem alloc] initWithTag:mutation.newChildShadowView.tag - eventEmitter:mutation.newChildShadowView.eventEmitter]]; - - // LocalData - if (mutation.newChildShadowView.localData) { - [mountItems - addObject:[[RCTUpdateLocalDataMountItem alloc] initWithTag:mutation.newChildShadowView.tag - oldLocalData:nullptr - newLocalData:mutation.newChildShadowView.localData]]; - } - - // State - if (mutation.newChildShadowView.state) { - [mountItems addObject:[[RCTUpdateStateMountItem alloc] initWithTag:mutation.newChildShadowView.tag - oldState:nullptr - newState:mutation.newChildShadowView.state]]; - } - - // Layout - if (mutation.newChildShadowView.layoutMetrics != EmptyLayoutMetrics) { - [mountItems addObject:[[RCTUpdateLayoutMetricsMountItem alloc] - initWithTag:mutation.newChildShadowView.tag - oldLayoutMetrics:{} - newLayoutMetrics:mutation.newChildShadowView.layoutMetrics]]; - } - - // Insertion - RCTInsertMountItem *mountItem = [[RCTInsertMountItem alloc] initWithChildTag:mutation.newChildShadowView.tag - parentTag:mutation.parentShadowView.tag - index:mutation.index]; - [mountItems addObject:mountItem]; - - break; - } - - case ShadowViewMutation::Remove: { - RCTRemoveMountItem *mountItem = [[RCTRemoveMountItem alloc] initWithChildTag:mutation.oldChildShadowView.tag - parentTag:mutation.parentShadowView.tag - index:mutation.index]; - [mountItems addObject:mountItem]; - break; - } - - case ShadowViewMutation::Update: { - auto oldChildShadowView = mutation.oldChildShadowView; - auto newChildShadowView = mutation.newChildShadowView; - - // Props - if (oldChildShadowView.props != newChildShadowView.props) { - RCTUpdatePropsMountItem *mountItem = - [[RCTUpdatePropsMountItem alloc] initWithTag:mutation.oldChildShadowView.tag - oldProps:mutation.oldChildShadowView.props - newProps:mutation.newChildShadowView.props]; - [mountItems addObject:mountItem]; - } - - // EventEmitter - if (oldChildShadowView.eventEmitter != newChildShadowView.eventEmitter) { - RCTUpdateEventEmitterMountItem *mountItem = - [[RCTUpdateEventEmitterMountItem alloc] initWithTag:mutation.oldChildShadowView.tag - eventEmitter:mutation.oldChildShadowView.eventEmitter]; - [mountItems addObject:mountItem]; - } - - // LocalData - if (oldChildShadowView.localData != newChildShadowView.localData) { - RCTUpdateLocalDataMountItem *mountItem = - [[RCTUpdateLocalDataMountItem alloc] initWithTag:newChildShadowView.tag - oldLocalData:oldChildShadowView.localData - newLocalData:newChildShadowView.localData]; - [mountItems addObject:mountItem]; - } - - // State - if (oldChildShadowView.state != newChildShadowView.state) { - RCTUpdateStateMountItem *mountItem = [[RCTUpdateStateMountItem alloc] initWithTag:newChildShadowView.tag - oldState:oldChildShadowView.state - newState:newChildShadowView.state]; - [mountItems addObject:mountItem]; - } - - // Layout - if (oldChildShadowView.layoutMetrics != newChildShadowView.layoutMetrics) { - RCTUpdateLayoutMetricsMountItem *mountItem = - [[RCTUpdateLayoutMetricsMountItem alloc] initWithTag:mutation.oldChildShadowView.tag - oldLayoutMetrics:oldChildShadowView.layoutMetrics - newLayoutMetrics:newChildShadowView.layoutMetrics]; - [mountItems addObject:mountItem]; - } - - break; - } - } - } + if (RCTIsMainQueue()) { + // Already on the proper thread, so: + // * No need to do a thread jump; + // * No need to do expensive copy of all mutations; + // * No need to allocate a block. + [self mountMutations:mutations rootTag:rootTag]; + return; } + // We need a non-reference for `mutations` to allow copy semantic. + auto mutationsCopy = mutations; + RCTExecuteOnMainQueue(^{ - [self _performMountItems:mountItems rootTag:rootTag]; + RCTAssertMainQueue(); + [self mountMutations:mutationsCopy rootTag:rootTag]; }); } -- (void)_performMountItems:(NSArray *)mountItems rootTag:(ReactTag)rootTag +- (void)mountMutations:(ShadowViewMutationList const &)mutations rootTag:(ReactTag)rootTag { - SystraceSection s("-[RCTMountingManager _performMountItems:rootTag:]"); + SystraceSection s("-[RCTMountingManager mountMutations:rootTag:]"); + RCTAssertMainQueue(); [self.delegate mountingManager:self willMountComponentsWithRootTag:rootTag]; - - for (id mountItem in mountItems) { - [mountItem executeWithRegistry:_componentViewRegistry]; - } - + RNPerformMountInstructions(mutations, self.componentViewRegistry); [self.delegate mountingManager:self didMountComponentsWithRootTag:rootTag]; } @@ -198,14 +221,11 @@ using namespace facebook::react; changedProps:(NSDictionary *)props componentDescriptor:(const ComponentDescriptor &)componentDescriptor { - UIView *componentView = [self->_componentViewRegistry componentViewByTag:reactTag]; + RCTAssertMainQueue(); + UIView *componentView = [_componentViewRegistry componentViewByTag:reactTag]; SharedProps oldProps = [componentView props]; SharedProps newProps = componentDescriptor.cloneProps(oldProps, RawProps(convertIdToFollyDynamic(props))); - RCTUpdatePropsMountItem *mountItem = [[RCTUpdatePropsMountItem alloc] initWithTag:reactTag - oldProps:oldProps - newProps:newProps]; - RCTAssertMainQueue(); - [mountItem executeWithRegistry:self->_componentViewRegistry]; + [componentView updateProps:newProps oldProps:oldProps]; } - (void)optimisticallyCreateComponentViewWithComponentHandle:(ComponentHandle)componentHandle diff --git a/React/Fabric/RCTScheduler.h b/React/Fabric/RCTScheduler.h index ef0bc1bbabd..d5ea6530da7 100644 --- a/React/Fabric/RCTScheduler.h +++ b/React/Fabric/RCTScheduler.h @@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN */ @protocol RCTSchedulerDelegate -- (void)schedulerDidFinishTransaction:(facebook::react::ShadowViewMutationList)mutations +- (void)schedulerDidFinishTransaction:(facebook::react::ShadowViewMutationList const &)mutations rootTag:(ReactTag)rootTag; - (void)schedulerOptimisticallyCreateComponentViewWithComponentHandle:(facebook::react::ComponentHandle)componentHandle; diff --git a/React/Fabric/RCTSurfacePresenter.mm b/React/Fabric/RCTSurfacePresenter.mm index 464dde4269e..a441331087f 100644 --- a/React/Fabric/RCTSurfacePresenter.mm +++ b/React/Fabric/RCTSurfacePresenter.mm @@ -299,15 +299,14 @@ using namespace facebook::react; #pragma mark - RCTSchedulerDelegate -- (void)schedulerDidFinishTransaction:(facebook::react::ShadowViewMutationList)mutations - rootTag:(ReactTag)rootTag +- (void)schedulerDidFinishTransaction:(facebook::react::ShadowViewMutationList const &)mutations + rootTag:(ReactTag)rootTag { RCTFabricSurface *surface = [_surfaceRegistry surfaceForRootTag:rootTag]; [surface _setStage:RCTSurfaceStagePrepared]; - [_mountingManager performTransactionWithMutations:mutations - rootTag:rootTag]; + [_mountingManager scheduleMutations:mutations rootTag:rootTag]; } - (void)schedulerOptimisticallyCreateComponentViewWithComponentHandle:(ComponentHandle)componentHandle diff --git a/ReactCommon/fabric/uimanager/SchedulerDelegate.h b/ReactCommon/fabric/uimanager/SchedulerDelegate.h index c2d81cdbd53..cc5fe052b6a 100644 --- a/ReactCommon/fabric/uimanager/SchedulerDelegate.h +++ b/ReactCommon/fabric/uimanager/SchedulerDelegate.h @@ -26,7 +26,7 @@ class SchedulerDelegate { */ virtual void schedulerDidFinishTransaction( Tag rootTag, - const ShadowViewMutationList &mutations, + ShadowViewMutationList const &mutations, const long commitStartTime, const long layoutTime) = 0;