diff --git a/React/Fabric/Mounting/UIView+ComponentViewProtocol.h b/React/Fabric/Mounting/UIView+ComponentViewProtocol.h new file mode 100644 index 000000000..b38b41ba5 --- /dev/null +++ b/React/Fabric/Mounting/UIView+ComponentViewProtocol.h @@ -0,0 +1,35 @@ +/** + * 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 + +NS_ASSUME_NONNULL_BEGIN + +/** + * Default implementation of RCTComponentViewProtocol. + */ +@interface UIView (ComponentViewProtocol) + +- (void)mountChildComponentView:(UIView *)childComponentView + index:(NSInteger)index; + +- (void)unmountChildComponentView:(UIView *)childComponentView + index:(NSInteger)index; + +- (void)updateProps:(facebook::react::SharedProps)props + oldProps:(facebook::react::SharedProps)oldProps; + +- (void)updateLayoutMetrics:(facebook::react::LayoutMetrics)layoutMetrics + oldLayoutMetrics:(facebook::react::LayoutMetrics)oldLayoutMetrics; + +- (void)prepareForRecycle; + +@end + +NS_ASSUME_NONNULL_END diff --git a/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm b/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm new file mode 100644 index 000000000..93b5784e3 --- /dev/null +++ b/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm @@ -0,0 +1,57 @@ +/** + * 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 "UIView+ComponentViewProtocol.h" + +#import + +@implementation UIView (ComponentViewProtocol) + +- (void)mountChildComponentView:(UIView *)childComponentView + index:(NSInteger)index +{ + [self insertSubview:childComponentView atIndex:index]; +} + +- (void)unmountChildComponentView:(UIView *)childComponentView + index:(NSInteger)index +{ + RCTAssert(childComponentView.superview == self, @"Attempt to unmount improperly mounted component view."); + [childComponentView removeFromSuperview]; +} + +- (void)updateProps:(facebook::react::SharedProps)props + oldProps:(facebook::react::SharedProps)oldProps +{ + // Default implementation does nothing. +} + +- (void)updateLayoutMetrics:(facebook::react::LayoutMetrics)layoutMetrics + oldLayoutMetrics:(facebook::react::LayoutMetrics)oldLayoutMetrics +{ + if (layoutMetrics.frame != oldLayoutMetrics.frame) { + self.frame = { + .origin = { + .x = layoutMetrics.frame.origin.x, + .y = layoutMetrics.frame.origin.y + }, + .size = { + .width = layoutMetrics.frame.size.width, + .height = layoutMetrics.frame.size.height + } + }; + } + + // TODO: Apply another layout metrics here. +} + +- (void)prepareForRecycle +{ + // Default implementation does nothing. +} + +@end