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
This commit is contained in:
Valentin Shergin 2017-12-19 08:57:09 -08:00 committed by Facebook Github Bot
parent d89901fa60
commit 2679f3efb6
12 changed files with 3 additions and 103 deletions

View File

@ -24,6 +24,7 @@ extern NSString *const RCTReactTagAttributeName;
@interface RCTShadowText : RCTShadowView @interface RCTShadowText : RCTShadowView
@property (nonatomic, strong) UIColor *color; @property (nonatomic, strong) UIColor *color;
@property (nonatomic, strong) UIColor *backgroundColor;
@property (nonatomic, copy) NSString *fontFamily; @property (nonatomic, copy) NSString *fontFamily;
@property (nonatomic, assign) CGFloat fontSize; @property (nonatomic, assign) CGFloat fontSize;
@property (nonatomic, copy) NSString *fontWeight; @property (nonatomic, copy) NSString *fontWeight;

View File

@ -620,12 +620,6 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f
return requiredSize; return requiredSize;
} }
- (void)setBackgroundColor:(UIColor *)backgroundColor
{
super.backgroundColor = backgroundColor;
[self dirtyText];
}
#define RCT_TEXT_PROPERTY(setProp, ivar, type) \ #define RCT_TEXT_PROPERTY(setProp, ivar, type) \
- (void)set##setProp:(type)value; \ - (void)set##setProp:(type)value; \
{ \ { \

View File

@ -58,6 +58,7 @@ RCT_EXPORT_MODULE()
#pragma mark - Shadow properties #pragma mark - Shadow properties
RCT_EXPORT_SHADOW_PROPERTY(color, UIColor) RCT_EXPORT_SHADOW_PROPERTY(color, UIColor)
RCT_EXPORT_SHADOW_PROPERTY(backgroundColor, UIColor)
RCT_EXPORT_SHADOW_PROPERTY(fontFamily, NSString) RCT_EXPORT_SHADOW_PROPERTY(fontFamily, NSString)
RCT_EXPORT_SHADOW_PROPERTY(fontSize, CGFloat) RCT_EXPORT_SHADOW_PROPERTY(fontSize, CGFloat)
RCT_EXPORT_SHADOW_PROPERTY(fontWeight, NSString) RCT_EXPORT_SHADOW_PROPERTY(fontWeight, NSString)

View File

@ -18,9 +18,6 @@
#import "UIView+React.h" #import "UIView+React.h"
@implementation RCTRootContentView @implementation RCTRootContentView
{
UIColor *_backgroundColor;
}
- (instancetype)initWithFrame:(CGRect)frame - (instancetype)initWithFrame:(CGRect)frame
bridge:(RCTBridge *)bridge bridge:(RCTBridge *)bridge
@ -34,7 +31,6 @@
_touchHandler = [[RCTTouchHandler alloc] initWithBridge:_bridge]; _touchHandler = [[RCTTouchHandler alloc] initWithBridge:_bridge];
[_touchHandler attachToView:self]; [_touchHandler attachToView:self];
[_bridge.uiManager registerRootView:self]; [_bridge.uiManager registerRootView:self];
self.layer.backgroundColor = NULL;
} }
return self; return self;
} }
@ -89,19 +85,6 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder:(nonnull NSCoder *)aDecoder)
[_bridge.uiManager setAvailableSize:self.availableSize forRootView:self]; [_bridge.uiManager setAvailableSize:self.availableSize forRootView:self];
} }
- (void)setBackgroundColor:(UIColor *)backgroundColor
{
_backgroundColor = backgroundColor;
if (self.reactTag && _bridge.isValid) {
[_bridge.uiManager setBackgroundColor:backgroundColor forView:self];
}
}
- (UIColor *)backgroundColor
{
return _backgroundColor;
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{ {
// The root content view itself should never receive touches // The root content view itself should never receive touches

View File

@ -133,12 +133,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
} }
#endif #endif
- (void)setBackgroundColor:(UIColor *)backgroundColor
{
super.backgroundColor = backgroundColor;
_contentView.backgroundColor = backgroundColor;
}
#pragma mark - passThroughTouches #pragma mark - passThroughTouches
- (BOOL)passThroughTouches - (BOOL)passThroughTouches
@ -282,7 +276,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
sizeFlexiblity:_sizeFlexibility]; sizeFlexiblity:_sizeFlexibility];
[self runApplication:bridge]; [self runApplication:bridge];
_contentView.backgroundColor = self.backgroundColor;
_contentView.passThroughTouches = _passThroughTouches; _contentView.passThroughTouches = _passThroughTouches;
[self insertSubview:_contentView atIndex:0]; [self insertSubview:_contentView atIndex:0];

View File

@ -88,13 +88,6 @@ RCT_EXTERN NSString *const RCTUIManagerWillUpdateViewsDueToContentSizeMultiplier
*/ */
- (void)setIntrinsicContentSize:(CGSize)intrinsicContentSize forView:(UIView *)view; - (void)setIntrinsicContentSize:(CGSize)intrinsicContentSize forView:(UIView *)view;
/**
* Update the background color of a view. The source of truth for
* backgroundColor is the shadow view, so if to update backgroundColor from
* native code you will need to call this method.
*/
- (void)setBackgroundColor:(UIColor *)color forView:(UIView *)view;
/** /**
* Sets up layout animation which will perform on next layout pass. * Sets up layout animation which will perform on next layout pass.
* The animation will affect only one next layout pass. * The animation will affect only one next layout pass.

View File

@ -298,7 +298,6 @@ static NSDictionary *deviceOrientationEventBody(UIDeviceOrientation orientation)
RCTRootShadowView *shadowView = [RCTRootShadowView new]; RCTRootShadowView *shadowView = [RCTRootShadowView new];
shadowView.availableSize = availableSize; shadowView.availableSize = availableSize;
shadowView.reactTag = reactTag; shadowView.reactTag = reactTag;
shadowView.backgroundColor = rootView.backgroundColor;
shadowView.viewName = NSStringFromClass([rootView class]); shadowView.viewName = NSStringFromClass([rootView class]);
self->_shadowViewRegistry[shadowView.reactTag] = shadowView; self->_shadowViewRegistry[shadowView.reactTag] = shadowView;
[self->_rootViewTags addObject:reactTag]; [self->_rootViewTags addObject:reactTag];
@ -417,20 +416,6 @@ static NSDictionary *deviceOrientationEventBody(UIDeviceOrientation orientation)
} forTag:view.reactTag]; } forTag:view.reactTag];
} }
- (void)setBackgroundColor:(UIColor *)color forView:(UIView *)view
{
RCTAssertMainQueue();
[self _executeBlockWithShadowView:^(RCTShadowView *shadowView) {
if (!self->_viewRegistry) {
return;
}
shadowView.backgroundColor = color;
[self _amendPendingUIBlocksWithStylePropagationUpdateForShadowView:shadowView];
[self flushUIBlocksWithCompletion:^{}];
} forTag:view.reactTag];
}
/** /**
* Unregisters views from registries * Unregisters views from registries
*/ */
@ -969,11 +954,6 @@ RCT_EXPORT_METHOD(createView:(nonnull NSNumber *)reactTag
shadowView.rootView = (RCTRootShadowView *)rootView; shadowView.rootView = (RCTRootShadowView *)rootView;
} }
// Shadow view is the source of truth for background color this is a little
// bit counter-intuitive if people try to set background color when setting up
// the view, but it's the only way that makes sense given our threading model
UIColor *backgroundColor = shadowView.backgroundColor;
// Dispatch view creation directly to the main thread instead of adding to // Dispatch view creation directly to the main thread instead of adding to
// UIBlocks array. This way, it doesn't get deferred until after layout. // UIBlocks array. This way, it doesn't get deferred until after layout.
__weak RCTUIManager *weakManager = self; __weak RCTUIManager *weakManager = self;
@ -984,11 +964,7 @@ RCT_EXPORT_METHOD(createView:(nonnull NSNumber *)reactTag
} }
UIView *view = [componentData createViewWithTag:reactTag]; UIView *view = [componentData createViewWithTag:reactTag];
if (view) { if (view) {
[componentData setProps:props forView:view]; // Must be done before bgColor to prevent wrong default [componentData setProps:props forView:view];
if ([view respondsToSelector:@selector(setBackgroundColor:)]) {
((UIView *)view).backgroundColor = backgroundColor;
}
uiManager->_viewRegistry[reactTag] = view; uiManager->_viewRegistry[reactTag] = view;
#if RCT_DEV #if RCT_DEV

View File

@ -55,7 +55,6 @@ typedef void (^RCTApplierBlock)(NSDictionary<NSNumber *, UIView *> *viewRegistry
@property (nonatomic, weak, readonly) RCTShadowView *superview; @property (nonatomic, weak, readonly) RCTShadowView *superview;
@property (nonatomic, assign, readonly) YGNodeRef yogaNode; @property (nonatomic, assign, readonly) YGNodeRef yogaNode;
@property (nonatomic, copy) NSString *viewName; @property (nonatomic, copy) NSString *viewName;
@property (nonatomic, strong) UIColor *backgroundColor; // Used to propagate to children
@property (nonatomic, copy) RCTDirectEventBlock onLayout; @property (nonatomic, copy) RCTDirectEventBlock onLayout;
/** /**

View File

@ -19,8 +19,6 @@
typedef void (^RCTActionBlock)(RCTShadowView *shadowViewSelf, id value); typedef void (^RCTActionBlock)(RCTShadowView *shadowViewSelf, id value);
typedef void (^RCTResetActionBlock)(RCTShadowView *shadowViewSelf); typedef void (^RCTResetActionBlock)(RCTShadowView *shadowViewSelf);
static NSString *const RCTBackgroundColorProp = @"backgroundColor";
typedef NS_ENUM(unsigned int, meta_prop_t) { typedef NS_ENUM(unsigned int, meta_prop_t) {
META_PROP_LEFT, META_PROP_LEFT,
META_PROP_TOP, META_PROP_TOP,
@ -278,26 +276,6 @@ static void RCTProcessMetaPropsBorder(const YGValue metaProps[META_PROP_COUNT],
}]; }];
} }
if (!_backgroundColor) {
UIColor *parentBackgroundColor = parentProperties[RCTBackgroundColorProp];
if (parentBackgroundColor) {
[applierBlocks addObject:^(NSDictionary<NSNumber *, UIView *> *viewRegistry) {
UIView *view = viewRegistry[self->_reactTag];
[view reactSetInheritedBackgroundColor:parentBackgroundColor];
}];
}
} else {
// Update parent properties for children
NSMutableDictionary<NSString *, id> *properties = [NSMutableDictionary dictionaryWithDictionary:parentProperties];
CGFloat alpha = CGColorGetAlpha(_backgroundColor.CGColor);
if (alpha < 1.0) {
// If bg is non-opaque, don't propagate further
properties[RCTBackgroundColorProp] = [UIColor clearColor];
} else {
properties[RCTBackgroundColorProp] = _backgroundColor;
}
return properties;
}
return parentProperties; return parentProperties;
} }
@ -786,12 +764,6 @@ RCT_STYLE_PROPERTY(Display, display, Display, YGDisplay)
RCT_STYLE_PROPERTY(Direction, direction, Direction, YGDirection) RCT_STYLE_PROPERTY(Direction, direction, Direction, YGDirection)
RCT_STYLE_PROPERTY(AspectRatio, aspectRatio, AspectRatio, float) RCT_STYLE_PROPERTY(AspectRatio, aspectRatio, AspectRatio, float)
- (void)setBackgroundColor:(UIColor *)color
{
_backgroundColor = color;
[self dirtyPropagation];
}
- (void)didUpdateReactSubviews - (void)didUpdateReactSubviews
{ {
// Does nothing by default // Does nothing by default

View File

@ -273,8 +273,6 @@ RCT_REMAP_VIEW_PROPERTY(zIndex, reactZIndex, NSInteger)
#pragma mark - ShadowView properties #pragma mark - ShadowView properties
RCT_EXPORT_SHADOW_PROPERTY(backgroundColor, UIColor)
RCT_EXPORT_SHADOW_PROPERTY(top, YGValue) RCT_EXPORT_SHADOW_PROPERTY(top, YGValue)
RCT_EXPORT_SHADOW_PROPERTY(right, YGValue) RCT_EXPORT_SHADOW_PROPERTY(right, YGValue)
RCT_EXPORT_SHADOW_PROPERTY(start, YGValue) RCT_EXPORT_SHADOW_PROPERTY(start, YGValue)

View File

@ -66,11 +66,6 @@
*/ */
- (void)reactSetFrame:(CGRect)frame; - (void)reactSetFrame:(CGRect)frame;
/**
* Used to improve performance when compositing views with translucent content.
*/
- (void)reactSetInheritedBackgroundColor:(UIColor *)inheritedBackgroundColor;
/** /**
* This method finds and returns the containing view controller for the view. * This method finds and returns the containing view controller for the view.
*/ */

View File

@ -193,11 +193,6 @@
self.bounds = bounds; self.bounds = bounds;
} }
- (void)reactSetInheritedBackgroundColor:(__unused UIColor *)inheritedBackgroundColor
{
// Does nothing by default
}
- (UIViewController *)reactViewController - (UIViewController *)reactViewController
{ {
id responder = [self nextResponder]; id responder = [self nextResponder];