diff --git a/React/Fabric/Mounting/MountItems/RCTUpdateLocalDataMountItem.h b/React/Fabric/Mounting/MountItems/RCTUpdateLocalDataMountItem.h new file mode 100644 index 000000000..b5aedcade --- /dev/null +++ b/React/Fabric/Mounting/MountItems/RCTUpdateLocalDataMountItem.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 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 new file mode 100644 index 000000000..c10bc3c4b --- /dev/null +++ b/React/Fabric/Mounting/MountItems/RCTUpdateLocalDataMountItem.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 "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/RCTComponentViewProtocol.h b/React/Fabric/Mounting/RCTComponentViewProtocol.h index d23ac72ad..fc56aa7e0 100644 --- a/React/Fabric/Mounting/RCTComponentViewProtocol.h +++ b/React/Fabric/Mounting/RCTComponentViewProtocol.h @@ -7,6 +7,7 @@ #import +#import #import #import #import @@ -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`, diff --git a/React/Fabric/Mounting/RCTMountingManager.mm b/React/Fabric/Mounting/RCTMountingManager.mm index 5f16ac251..5b7e7f131 100644 --- a/React/Fabric/Mounting/RCTMountingManager.mm +++ b/React/Fabric/Mounting/RCTMountingManager.mm @@ -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(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(oldShadowNode); diff --git a/React/Fabric/Mounting/UIView+ComponentViewProtocol.h b/React/Fabric/Mounting/UIView+ComponentViewProtocol.h index b38b41ba5..cffe51a2f 100644 --- a/React/Fabric/Mounting/UIView+ComponentViewProtocol.h +++ b/React/Fabric/Mounting/UIView+ComponentViewProtocol.h @@ -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; diff --git a/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm b/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm index 93b5784e3..1a4136cfd 100644 --- a/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm +++ b/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm @@ -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 {