Skip to content

Commit

Permalink
Use defaultSharedProps in ComponentView init (facebook#41623)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#41623

`static` fields require additional code to ensure the field is only ever initialized once. We already have a static "default props" field in the shadow node, so let's reuse that as much as possible.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D51547638

fbshipit-source-id: e4957ffb0f9352847b8cd8dc3a010dcfac8be699
  • Loading branch information
javache authored and facebook-github-bot committed Nov 23, 2023
1 parent 342041e commit f1dc061
Show file tree
Hide file tree
Showing 17 changed files with 18 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ + (ComponentDescriptorProvider)componentDescriptorProvider
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const ActivityIndicatorViewProps>();
const auto &defaultProps = ActivityIndicatorViewShadowNode::defaultSharedProps();
_props = defaultProps;

_activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:self.bounds];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ @implementation RCTDebuggingOverlayComponentView {
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const DebuggingOverlayProps>();
_props = defaultProps;

_props = DebuggingOverlayShadowNode::defaultSharedProps();
_overlay = [[RCTDebuggingOverlay alloc] initWithFrame:self.bounds];

self.contentView = _overlay;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ @implementation RCTImageComponentView {
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const ImageProps>();
const auto &defaultProps = ImageShadowNode::defaultSharedProps();
_props = defaultProps;

_imageView = [RCTUIImageViewAnimated new];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ @implementation RCTInputAccessoryComponentView {
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const InputAccessoryProps>();
_props = defaultProps;
_props = InputAccessoryShadowNode::defaultSharedProps();
_contentView = [RCTInputAccessoryContentView new];
_touchHandler = [RCTSurfaceTouchHandler new];
[_touchHandler attachToView:_contentView];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ @implementation RCTLegacyViewManagerInteropComponentView {
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const LegacyViewManagerInteropViewProps>();
_props = defaultProps;
_props = LegacyViewManagerInteropShadowNode::defaultSharedProps();
_viewsToBeMounted = [NSMutableArray new];
_viewsToBeUnmounted = [NSMutableArray new];
_hasInvokedForwardingWarning = NO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ @implementation RCTModalHostViewComponentView {
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const ModalHostViewProps>();
_props = defaultProps;
_props = ModalHostViewShadowNode::defaultSharedProps();
_shouldAnimatePresentation = YES;

_isPresented = NO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ @implementation RCTRootComponentView
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const RootProps>();
_props = defaultProps;
_props = RootShadowNode::defaultSharedProps();
}

return self;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ @implementation RCTSafeAreaViewComponentView {
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const SafeAreaViewProps>();
_props = defaultProps;
_props = SafeAreaViewShadowNode::defaultSharedProps();
}

return self;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ - (instancetype)initWithFrame:(CGRect)frame
// The pull-to-refresh view is not a subview of this view.
self.hidden = YES;

static const auto defaultProps = std::make_shared<const PullToRefreshViewProps>();
_props = defaultProps;
_props = PullToRefreshViewShadowNode::defaultSharedProps();

_refreshControl = [UIRefreshControl new];
[_refreshControl addTarget:self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ + (RCTScrollViewComponentView *_Nullable)findScrollViewComponentViewForView:(UIV
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const ScrollViewProps>();
_props = defaultProps;
_props = ScrollViewShadowNode::defaultSharedProps();

_scrollView = [[RCTEnhancedScrollView alloc] initWithFrame:self.bounds];
_scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ @implementation RCTSwitchComponentView {
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const SwitchProps>();
_props = defaultProps;
_props = SwitchShadowNode::defaultSharedProps();

_switchView = [[UISwitch alloc] initWithFrame:self.bounds];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ @implementation RCTParagraphComponentView {
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const ParagraphProps>();
_props = defaultProps;
_props = ParagraphShadowNode::defaultSharedProps();

self.opaque = NO;
self.contentMode = UIViewContentModeRedraw;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ @implementation RCTTextInputComponentView {
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const TextInputProps>();
const auto &defaultProps = TextInputShadowNode::defaultSharedProps();
_props = defaultProps;
auto &props = *defaultProps;

_backedTextInputView = props.traits.multiline ? [RCTUITextView new] : [RCTUITextField new];
_backedTextInputView = defaultProps->traits.multiline ? [RCTUITextView new] : [RCTUITextField new];
_backedTextInputView.textInputDelegate = self;
_ignoreNextTextInputCall = NO;
_comingFromJS = NO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ @implementation RCTUnimplementedNativeComponentView {
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const UnimplementedNativeViewProps>();
_props = defaultProps;
_props = UnimplementedNativeViewShadowNode::defaultSharedProps();

CGRect bounds = self.bounds;
_label = [[UILabel alloc] initWithFrame:bounds];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ @implementation RCTUnimplementedViewComponentView {
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const UnimplementedViewProps>();
_props = defaultProps;
_props = UnimplementedViewShadowNode::defaultSharedProps();

_label = [[UILabel alloc] initWithFrame:self.bounds];
_label.backgroundColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.3];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ + (void)load
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const ViewProps>();
_props = defaultProps;
_props = ViewShadowNode::defaultSharedProps();
_reactSubviews = [NSMutableArray new];
self.multipleTouchEnabled = YES;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ConcreteShadowNode : public BaseShadowNodeT {
rawProps);
}

static SharedConcreteProps defaultSharedProps() {
static const SharedConcreteProps& defaultSharedProps() {
static const SharedConcreteProps defaultSharedProps =
std::make_shared<const PropsT>();
return defaultSharedProps;
Expand Down

0 comments on commit f1dc061

Please sign in to comment.