mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fabric: Passing props as const & in RCTComponentViewProtocol
Summary: Passing shared pointers as references can save us a couple of milliseconds at scale. Originally, I didn't expect that Objective-C supports passing values by references, but apparently it does. Reviewed By: mdvacca Differential Revision: D15473218 fbshipit-source-id: 15eb3770cc0889654647a8e91607d8aa78010121
This commit is contained in:
committed by
Facebook Github Bot
parent
e4240da560
commit
0e9c764e28
+1
-1
@@ -58,7 +58,7 @@ static UIActivityIndicatorViewStyle convertActivityIndicatorViewStyle(const Acti
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)updateProps:(SharedProps)props oldProps:(SharedProps)oldProps
|
||||
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
||||
{
|
||||
const auto &oldViewProps = *std::static_pointer_cast<const ActivityIndicatorViewProps>(oldProps ?: _props);
|
||||
const auto &newViewProps = *std::static_pointer_cast<const ActivityIndicatorViewProps>(props);
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
return concreteComponentDescriptorProvider<ImageComponentDescriptor>();
|
||||
}
|
||||
|
||||
- (void)updateProps:(SharedProps)props oldProps:(SharedProps)oldProps
|
||||
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
||||
{
|
||||
const auto &oldImageProps = *std::static_pointer_cast<const ImageProps>(oldProps ?: _props);
|
||||
const auto &newImageProps = *std::static_pointer_cast<const ImageProps>(props);
|
||||
|
||||
@@ -69,7 +69,7 @@ using namespace facebook::react;
|
||||
return concreteComponentDescriptorProvider<ScrollViewComponentDescriptor>();
|
||||
}
|
||||
|
||||
- (void)updateProps:(SharedProps)props oldProps:(SharedProps)oldProps
|
||||
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
||||
{
|
||||
const auto &oldScrollViewProps = *std::static_pointer_cast<const ScrollViewProps>(oldProps ?: _props);
|
||||
const auto &newScrollViewProps = *std::static_pointer_cast<const ScrollViewProps>(props);
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
#import <react/components/rncore/EventEmitters.h>
|
||||
#import <react/components/rncore/Props.h>
|
||||
|
||||
#import <React/RCTScrollViewComponentView.h>
|
||||
#import <React/RCTConversions.h>
|
||||
#import <React/RCTScrollViewComponentView.h>
|
||||
|
||||
using namespace facebook::react;
|
||||
|
||||
@@ -33,7 +33,9 @@ using namespace facebook::react;
|
||||
_props = defaultProps;
|
||||
|
||||
_refreshControl = [[UIRefreshControl alloc] init];
|
||||
[_refreshControl addTarget:self action:@selector(handleUIControlEventValueChanged) forControlEvents:UIControlEventValueChanged];
|
||||
[_refreshControl addTarget:self
|
||||
action:@selector(handleUIControlEventValueChanged)
|
||||
forControlEvents:UIControlEventValueChanged];
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -46,7 +48,7 @@ using namespace facebook::react;
|
||||
return concreteComponentDescriptorProvider<PullToRefreshViewComponentDescriptor>();
|
||||
}
|
||||
|
||||
- (void)updateProps:(SharedProps)props oldProps:(SharedProps)oldProps
|
||||
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
||||
{
|
||||
auto const &oldConcreteProps = *std::static_pointer_cast<PullToRefreshViewProps const>(oldProps ?: _props);
|
||||
auto const &newConcreteProps = *std::static_pointer_cast<PullToRefreshViewProps const>(props);
|
||||
@@ -97,7 +99,8 @@ using namespace facebook::react;
|
||||
attributes[NSForegroundColorAttributeName] = RCTUIColorFromSharedColor(concreteProps.titleColor);
|
||||
}
|
||||
|
||||
_refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:RCTNSStringFromString(concreteProps.title) attributes:attributes];
|
||||
_refreshControl.attributedTitle =
|
||||
[[NSAttributedString alloc] initWithString:RCTNSStringFromString(concreteProps.title) attributes:attributes];
|
||||
}
|
||||
|
||||
#pragma mark - Attaching & Detaching
|
||||
|
||||
@@ -107,7 +107,7 @@ using namespace facebook::react;
|
||||
return concreteComponentDescriptorProvider<SliderComponentDescriptor>();
|
||||
}
|
||||
|
||||
- (void)updateProps:(SharedProps)props oldProps:(SharedProps)oldProps
|
||||
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
||||
{
|
||||
const auto &oldSliderProps = *std::static_pointer_cast<const SliderProps>(oldProps ?: _props);
|
||||
const auto &newSliderProps = *std::static_pointer_cast<const SliderProps>(props);
|
||||
|
||||
@@ -43,7 +43,7 @@ using namespace facebook::react;
|
||||
return concreteComponentDescriptorProvider<SwitchComponentDescriptor>();
|
||||
}
|
||||
|
||||
- (void)updateProps:(SharedProps)props oldProps:(SharedProps)oldProps
|
||||
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
||||
{
|
||||
const auto &oldSwitchProps = *std::static_pointer_cast<const SwitchProps>(oldProps ?: _props);
|
||||
const auto &newSwitchProps = *std::static_pointer_cast<const SwitchProps>(props);
|
||||
|
||||
@@ -53,7 +53,7 @@ using namespace facebook::react;
|
||||
concreteComponentDescriptorProvider<TextComponentDescriptor>()};
|
||||
}
|
||||
|
||||
- (void)updateProps:(SharedProps)props oldProps:(SharedProps)oldProps
|
||||
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
||||
{
|
||||
const auto ¶graphProps = std::static_pointer_cast<const ParagraphProps>(props);
|
||||
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ using namespace facebook::react;
|
||||
return concreteComponentDescriptorProvider<UnimplementedNativeViewComponentDescriptor>();
|
||||
}
|
||||
|
||||
- (void)updateProps:(SharedProps)props oldProps:(SharedProps)oldProps
|
||||
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
||||
{
|
||||
const auto &oldViewProps = *std::static_pointer_cast<const UnimplementedNativeViewProps>(oldProps ?: _props);
|
||||
const auto &newViewProps = *std::static_pointer_cast<const UnimplementedNativeViewProps>(props);
|
||||
|
||||
@@ -71,8 +71,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
/**
|
||||
* Enforcing `call super` semantic for overridden methods from `RCTComponentViewProtocol`.
|
||||
*/
|
||||
- (void)updateProps:(facebook::react::SharedProps)props
|
||||
oldProps:(facebook::react::SharedProps)oldProps NS_REQUIRES_SUPER;
|
||||
- (void)updateProps:(facebook::react::Props::Shared const &)props
|
||||
oldProps:(facebook::react::Props::Shared const &)oldProps NS_REQUIRES_SUPER;
|
||||
- (void)updateEventEmitter:(facebook::react::SharedEventEmitter)eventEmitter NS_REQUIRES_SUPER;
|
||||
- (void)updateLayoutMetrics:(facebook::react::LayoutMetrics)layoutMetrics
|
||||
oldLayoutMetrics:(facebook::react::LayoutMetrics)oldLayoutMetrics NS_REQUIRES_SUPER;
|
||||
|
||||
@@ -94,7 +94,7 @@ using namespace facebook::react;
|
||||
return concreteComponentDescriptorProvider<ViewComponentDescriptor>();
|
||||
}
|
||||
|
||||
- (void)updateProps:(SharedProps)props oldProps:(SharedProps)oldProps
|
||||
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
||||
{
|
||||
#ifndef NS_BLOCK_ASSERTIONS
|
||||
auto propsRawPtr = _props.get();
|
||||
@@ -332,12 +332,10 @@ static RCTCornerRadii RCTCornerRadiiFromBorderRadii(BorderRadii borderRadii)
|
||||
|
||||
static RCTBorderColors RCTBorderColorsFromBorderColors(BorderColors borderColors)
|
||||
{
|
||||
return RCTBorderColors{
|
||||
.left = RCTCGColorRefUnretainedFromSharedColor(borderColors.left),
|
||||
.top = RCTCGColorRefUnretainedFromSharedColor(borderColors.top),
|
||||
.bottom = RCTCGColorRefUnretainedFromSharedColor(borderColors.bottom),
|
||||
.right = RCTCGColorRefUnretainedFromSharedColor(borderColors.right)
|
||||
};
|
||||
return RCTBorderColors{.left = RCTCGColorRefUnretainedFromSharedColor(borderColors.left),
|
||||
.top = RCTCGColorRefUnretainedFromSharedColor(borderColors.top),
|
||||
.bottom = RCTCGColorRefUnretainedFromSharedColor(borderColors.bottom),
|
||||
.right = RCTCGColorRefUnretainedFromSharedColor(borderColors.right)};
|
||||
}
|
||||
|
||||
static UIEdgeInsets UIEdgeInsetsFromBorderInsets(EdgeInsets edgeInsets)
|
||||
|
||||
@@ -70,7 +70,8 @@ typedef NS_OPTIONS(NSInteger, RNComponentViewUpdateMask) {
|
||||
* Called for updating component's props.
|
||||
* Receiver must update native view props accordingly changed props.
|
||||
*/
|
||||
- (void)updateProps:(facebook::react::SharedProps)props oldProps:(facebook::react::SharedProps)oldProps;
|
||||
- (void)updateProps:(facebook::react::Props::Shared const &)props
|
||||
oldProps:(facebook::react::Props::Shared const &)oldProps;
|
||||
|
||||
/*
|
||||
* Called for updating component's local data.
|
||||
|
||||
@@ -22,7 +22,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index;
|
||||
|
||||
- (void)updateProps:(facebook::react::SharedProps)props oldProps:(facebook::react::SharedProps)oldProps;
|
||||
- (void)updateProps:(facebook::react::Props::Shared const &)props
|
||||
oldProps:(facebook::react::Props::Shared const &)oldProps;
|
||||
|
||||
- (void)updateEventEmitter:(facebook::react::SharedEventEmitter)eventEmitter;
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ using namespace facebook::react;
|
||||
[childComponentView removeFromSuperview];
|
||||
}
|
||||
|
||||
- (void)updateProps:(SharedProps)props oldProps:(SharedProps)oldProps
|
||||
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
|
||||
{
|
||||
// Default implementation does nothing.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user