Skip to content

Commit 2679f3e

Browse files
sherginfacebook-github-bot
authored andcommitted
Demolishing of background color propagation infra
Summary: As it was mentioned in previous diffs, we are removing this because it overcomplicates rendering layer and provides (almost) no benefits (and cannot be implemented 100% accurate way). Reviewed By: mmmulani Differential Revision: D6582560 fbshipit-source-id: 0778db96a45dd8e2520268d5d00792677cb01a20
1 parent d89901f commit 2679f3e

12 files changed

+3
-103
lines changed

Libraries/Text/RCTShadowText.h

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ extern NSString *const RCTReactTagAttributeName;
2424
@interface RCTShadowText : RCTShadowView
2525

2626
@property (nonatomic, strong) UIColor *color;
27+
@property (nonatomic, strong) UIColor *backgroundColor;
2728
@property (nonatomic, copy) NSString *fontFamily;
2829
@property (nonatomic, assign) CGFloat fontSize;
2930
@property (nonatomic, copy) NSString *fontWeight;

Libraries/Text/RCTShadowText.m

-6
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,6 @@ - (CGSize)calculateSize:(NSTextStorage *)storage
620620
return requiredSize;
621621
}
622622

623-
- (void)setBackgroundColor:(UIColor *)backgroundColor
624-
{
625-
super.backgroundColor = backgroundColor;
626-
[self dirtyText];
627-
}
628-
629623
#define RCT_TEXT_PROPERTY(setProp, ivar, type) \
630624
- (void)set##setProp:(type)value; \
631625
{ \

Libraries/Text/RCTTextManager.m

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ - (RCTShadowView *)shadowView
5858
#pragma mark - Shadow properties
5959

6060
RCT_EXPORT_SHADOW_PROPERTY(color, UIColor)
61+
RCT_EXPORT_SHADOW_PROPERTY(backgroundColor, UIColor)
6162
RCT_EXPORT_SHADOW_PROPERTY(fontFamily, NSString)
6263
RCT_EXPORT_SHADOW_PROPERTY(fontSize, CGFloat)
6364
RCT_EXPORT_SHADOW_PROPERTY(fontWeight, NSString)

React/Base/RCTRootContentView.m

-17
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
#import "UIView+React.h"
1919

2020
@implementation RCTRootContentView
21-
{
22-
UIColor *_backgroundColor;
23-
}
2421

2522
- (instancetype)initWithFrame:(CGRect)frame
2623
bridge:(RCTBridge *)bridge
@@ -34,7 +31,6 @@ - (instancetype)initWithFrame:(CGRect)frame
3431
_touchHandler = [[RCTTouchHandler alloc] initWithBridge:_bridge];
3532
[_touchHandler attachToView:self];
3633
[_bridge.uiManager registerRootView:self];
37-
self.layer.backgroundColor = NULL;
3834
}
3935
return self;
4036
}
@@ -89,19 +85,6 @@ - (void)updateAvailableSize
8985
[_bridge.uiManager setAvailableSize:self.availableSize forRootView:self];
9086
}
9187

92-
- (void)setBackgroundColor:(UIColor *)backgroundColor
93-
{
94-
_backgroundColor = backgroundColor;
95-
if (self.reactTag && _bridge.isValid) {
96-
[_bridge.uiManager setBackgroundColor:backgroundColor forView:self];
97-
}
98-
}
99-
100-
- (UIColor *)backgroundColor
101-
{
102-
return _backgroundColor;
103-
}
104-
10588
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
10689
{
10790
// The root content view itself should never receive touches

React/Base/RCTRootView.m

-7
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,6 @@ - (UIView *)preferredFocusedView
133133
}
134134
#endif
135135

136-
- (void)setBackgroundColor:(UIColor *)backgroundColor
137-
{
138-
super.backgroundColor = backgroundColor;
139-
_contentView.backgroundColor = backgroundColor;
140-
}
141-
142136
#pragma mark - passThroughTouches
143137

144138
- (BOOL)passThroughTouches
@@ -282,7 +276,6 @@ - (void)bundleFinishedLoading:(RCTBridge *)bridge
282276
sizeFlexiblity:_sizeFlexibility];
283277
[self runApplication:bridge];
284278

285-
_contentView.backgroundColor = self.backgroundColor;
286279
_contentView.passThroughTouches = _passThroughTouches;
287280
[self insertSubview:_contentView atIndex:0];
288281

React/Modules/RCTUIManager.h

-7
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,6 @@ RCT_EXTERN NSString *const RCTUIManagerWillUpdateViewsDueToContentSizeMultiplier
8888
*/
8989
- (void)setIntrinsicContentSize:(CGSize)intrinsicContentSize forView:(UIView *)view;
9090

91-
/**
92-
* Update the background color of a view. The source of truth for
93-
* backgroundColor is the shadow view, so if to update backgroundColor from
94-
* native code you will need to call this method.
95-
*/
96-
- (void)setBackgroundColor:(UIColor *)color forView:(UIView *)view;
97-
9891
/**
9992
* Sets up layout animation which will perform on next layout pass.
10093
* The animation will affect only one next layout pass.

React/Modules/RCTUIManager.m

+1-25
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ - (void)registerRootView:(RCTRootContentView *)rootView
298298
RCTRootShadowView *shadowView = [RCTRootShadowView new];
299299
shadowView.availableSize = availableSize;
300300
shadowView.reactTag = reactTag;
301-
shadowView.backgroundColor = rootView.backgroundColor;
302301
shadowView.viewName = NSStringFromClass([rootView class]);
303302
self->_shadowViewRegistry[shadowView.reactTag] = shadowView;
304303
[self->_rootViewTags addObject:reactTag];
@@ -417,20 +416,6 @@ - (void)setIntrinsicContentSize:(CGSize)intrinsicContentSize forView:(UIView *)v
417416
} forTag:view.reactTag];
418417
}
419418

420-
- (void)setBackgroundColor:(UIColor *)color forView:(UIView *)view
421-
{
422-
RCTAssertMainQueue();
423-
[self _executeBlockWithShadowView:^(RCTShadowView *shadowView) {
424-
if (!self->_viewRegistry) {
425-
return;
426-
}
427-
428-
shadowView.backgroundColor = color;
429-
[self _amendPendingUIBlocksWithStylePropagationUpdateForShadowView:shadowView];
430-
[self flushUIBlocksWithCompletion:^{}];
431-
} forTag:view.reactTag];
432-
}
433-
434419
/**
435420
* Unregisters views from registries
436421
*/
@@ -969,11 +954,6 @@ - (void)_manageChildren:(NSNumber *)containerTag
969954
shadowView.rootView = (RCTRootShadowView *)rootView;
970955
}
971956

972-
// Shadow view is the source of truth for background color this is a little
973-
// bit counter-intuitive if people try to set background color when setting up
974-
// the view, but it's the only way that makes sense given our threading model
975-
UIColor *backgroundColor = shadowView.backgroundColor;
976-
977957
// Dispatch view creation directly to the main thread instead of adding to
978958
// UIBlocks array. This way, it doesn't get deferred until after layout.
979959
__weak RCTUIManager *weakManager = self;
@@ -984,11 +964,7 @@ - (void)_manageChildren:(NSNumber *)containerTag
984964
}
985965
UIView *view = [componentData createViewWithTag:reactTag];
986966
if (view) {
987-
[componentData setProps:props forView:view]; // Must be done before bgColor to prevent wrong default
988-
if ([view respondsToSelector:@selector(setBackgroundColor:)]) {
989-
((UIView *)view).backgroundColor = backgroundColor;
990-
}
991-
967+
[componentData setProps:props forView:view];
992968
uiManager->_viewRegistry[reactTag] = view;
993969

994970
#if RCT_DEV

React/Views/RCTShadowView.h

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ typedef void (^RCTApplierBlock)(NSDictionary<NSNumber *, UIView *> *viewRegistry
5555
@property (nonatomic, weak, readonly) RCTShadowView *superview;
5656
@property (nonatomic, assign, readonly) YGNodeRef yogaNode;
5757
@property (nonatomic, copy) NSString *viewName;
58-
@property (nonatomic, strong) UIColor *backgroundColor; // Used to propagate to children
5958
@property (nonatomic, copy) RCTDirectEventBlock onLayout;
6059

6160
/**

React/Views/RCTShadowView.m

-28
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
typedef void (^RCTActionBlock)(RCTShadowView *shadowViewSelf, id value);
2020
typedef void (^RCTResetActionBlock)(RCTShadowView *shadowViewSelf);
2121

22-
static NSString *const RCTBackgroundColorProp = @"backgroundColor";
23-
2422
typedef NS_ENUM(unsigned int, meta_prop_t) {
2523
META_PROP_LEFT,
2624
META_PROP_TOP,
@@ -278,26 +276,6 @@ - (void)applyLayoutToChildren:(YGNodeRef)node
278276
}];
279277
}
280278

281-
if (!_backgroundColor) {
282-
UIColor *parentBackgroundColor = parentProperties[RCTBackgroundColorProp];
283-
if (parentBackgroundColor) {
284-
[applierBlocks addObject:^(NSDictionary<NSNumber *, UIView *> *viewRegistry) {
285-
UIView *view = viewRegistry[self->_reactTag];
286-
[view reactSetInheritedBackgroundColor:parentBackgroundColor];
287-
}];
288-
}
289-
} else {
290-
// Update parent properties for children
291-
NSMutableDictionary<NSString *, id> *properties = [NSMutableDictionary dictionaryWithDictionary:parentProperties];
292-
CGFloat alpha = CGColorGetAlpha(_backgroundColor.CGColor);
293-
if (alpha < 1.0) {
294-
// If bg is non-opaque, don't propagate further
295-
properties[RCTBackgroundColorProp] = [UIColor clearColor];
296-
} else {
297-
properties[RCTBackgroundColorProp] = _backgroundColor;
298-
}
299-
return properties;
300-
}
301279
return parentProperties;
302280
}
303281

@@ -786,12 +764,6 @@ - (type)getProp \
786764
RCT_STYLE_PROPERTY(Direction, direction, Direction, YGDirection)
787765
RCT_STYLE_PROPERTY(AspectRatio, aspectRatio, AspectRatio, float)
788766

789-
- (void)setBackgroundColor:(UIColor *)color
790-
{
791-
_backgroundColor = color;
792-
[self dirtyPropagation];
793-
}
794-
795767
- (void)didUpdateReactSubviews
796768
{
797769
// Does nothing by default

React/Views/RCTViewManager.m

-2
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,6 @@ - (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(__unused NSDictio
273273

274274
#pragma mark - ShadowView properties
275275

276-
RCT_EXPORT_SHADOW_PROPERTY(backgroundColor, UIColor)
277-
278276
RCT_EXPORT_SHADOW_PROPERTY(top, YGValue)
279277
RCT_EXPORT_SHADOW_PROPERTY(right, YGValue)
280278
RCT_EXPORT_SHADOW_PROPERTY(start, YGValue)

React/Views/UIView+React.h

-5
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@
6666
*/
6767
- (void)reactSetFrame:(CGRect)frame;
6868

69-
/**
70-
* Used to improve performance when compositing views with translucent content.
71-
*/
72-
- (void)reactSetInheritedBackgroundColor:(UIColor *)inheritedBackgroundColor;
73-
7469
/**
7570
* This method finds and returns the containing view controller for the view.
7671
*/

React/Views/UIView+React.m

-5
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,6 @@ - (void)reactSetFrame:(CGRect)frame
193193
self.bounds = bounds;
194194
}
195195

196-
- (void)reactSetInheritedBackgroundColor:(__unused UIColor *)inheritedBackgroundColor
197-
{
198-
// Does nothing by default
199-
}
200-
201196
- (UIViewController *)reactViewController
202197
{
203198
id responder = [self nextResponder];

0 commit comments

Comments
 (0)