From 2679f3efb69bc7b0db1840b4ea59ebe791a54dd2 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 19 Dec 2017 08:57:09 -0800 Subject: [PATCH] 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 --- Libraries/Text/RCTShadowText.h | 1 + Libraries/Text/RCTShadowText.m | 6 ------ Libraries/Text/RCTTextManager.m | 1 + React/Base/RCTRootContentView.m | 17 ----------------- React/Base/RCTRootView.m | 7 ------- React/Modules/RCTUIManager.h | 7 ------- React/Modules/RCTUIManager.m | 26 +------------------------- React/Views/RCTShadowView.h | 1 - React/Views/RCTShadowView.m | 28 ---------------------------- React/Views/RCTViewManager.m | 2 -- React/Views/UIView+React.h | 5 ----- React/Views/UIView+React.m | 5 ----- 12 files changed, 3 insertions(+), 103 deletions(-) diff --git a/Libraries/Text/RCTShadowText.h b/Libraries/Text/RCTShadowText.h index 98a667bfa4..5fece77fab 100644 --- a/Libraries/Text/RCTShadowText.h +++ b/Libraries/Text/RCTShadowText.h @@ -24,6 +24,7 @@ extern NSString *const RCTReactTagAttributeName; @interface RCTShadowText : RCTShadowView @property (nonatomic, strong) UIColor *color; +@property (nonatomic, strong) UIColor *backgroundColor; @property (nonatomic, copy) NSString *fontFamily; @property (nonatomic, assign) CGFloat fontSize; @property (nonatomic, copy) NSString *fontWeight; diff --git a/Libraries/Text/RCTShadowText.m b/Libraries/Text/RCTShadowText.m index fe2b037724..92108a55f7 100644 --- a/Libraries/Text/RCTShadowText.m +++ b/Libraries/Text/RCTShadowText.m @@ -620,12 +620,6 @@ static YGSize RCTMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, f return requiredSize; } -- (void)setBackgroundColor:(UIColor *)backgroundColor -{ - super.backgroundColor = backgroundColor; - [self dirtyText]; -} - #define RCT_TEXT_PROPERTY(setProp, ivar, type) \ - (void)set##setProp:(type)value; \ { \ diff --git a/Libraries/Text/RCTTextManager.m b/Libraries/Text/RCTTextManager.m index b26a29d7e0..fd0b08d2de 100644 --- a/Libraries/Text/RCTTextManager.m +++ b/Libraries/Text/RCTTextManager.m @@ -58,6 +58,7 @@ RCT_EXPORT_MODULE() #pragma mark - Shadow properties RCT_EXPORT_SHADOW_PROPERTY(color, UIColor) +RCT_EXPORT_SHADOW_PROPERTY(backgroundColor, UIColor) RCT_EXPORT_SHADOW_PROPERTY(fontFamily, NSString) RCT_EXPORT_SHADOW_PROPERTY(fontSize, CGFloat) RCT_EXPORT_SHADOW_PROPERTY(fontWeight, NSString) diff --git a/React/Base/RCTRootContentView.m b/React/Base/RCTRootContentView.m index 57ebdd201e..2bd63c9ebc 100644 --- a/React/Base/RCTRootContentView.m +++ b/React/Base/RCTRootContentView.m @@ -18,9 +18,6 @@ #import "UIView+React.h" @implementation RCTRootContentView -{ - UIColor *_backgroundColor; -} - (instancetype)initWithFrame:(CGRect)frame bridge:(RCTBridge *)bridge @@ -34,7 +31,6 @@ _touchHandler = [[RCTTouchHandler alloc] initWithBridge:_bridge]; [_touchHandler attachToView:self]; [_bridge.uiManager registerRootView:self]; - self.layer.backgroundColor = NULL; } return self; } @@ -89,19 +85,6 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder:(nonnull NSCoder *)aDecoder) [_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 { // The root content view itself should never receive touches diff --git a/React/Base/RCTRootView.m b/React/Base/RCTRootView.m index 4a5e53c650..6504097d42 100644 --- a/React/Base/RCTRootView.m +++ b/React/Base/RCTRootView.m @@ -133,12 +133,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) } #endif -- (void)setBackgroundColor:(UIColor *)backgroundColor -{ - super.backgroundColor = backgroundColor; - _contentView.backgroundColor = backgroundColor; -} - #pragma mark - passThroughTouches - (BOOL)passThroughTouches @@ -282,7 +276,6 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) sizeFlexiblity:_sizeFlexibility]; [self runApplication:bridge]; - _contentView.backgroundColor = self.backgroundColor; _contentView.passThroughTouches = _passThroughTouches; [self insertSubview:_contentView atIndex:0]; diff --git a/React/Modules/RCTUIManager.h b/React/Modules/RCTUIManager.h index 59547c2201..1c8a12a5a4 100644 --- a/React/Modules/RCTUIManager.h +++ b/React/Modules/RCTUIManager.h @@ -88,13 +88,6 @@ RCT_EXTERN NSString *const RCTUIManagerWillUpdateViewsDueToContentSizeMultiplier */ - (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. * The animation will affect only one next layout pass. diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index b943fb92fe..a22437a10f 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -298,7 +298,6 @@ static NSDictionary *deviceOrientationEventBody(UIDeviceOrientation orientation) RCTRootShadowView *shadowView = [RCTRootShadowView new]; shadowView.availableSize = availableSize; shadowView.reactTag = reactTag; - shadowView.backgroundColor = rootView.backgroundColor; shadowView.viewName = NSStringFromClass([rootView class]); self->_shadowViewRegistry[shadowView.reactTag] = shadowView; [self->_rootViewTags addObject:reactTag]; @@ -417,20 +416,6 @@ static NSDictionary *deviceOrientationEventBody(UIDeviceOrientation orientation) } 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 */ @@ -969,11 +954,6 @@ RCT_EXPORT_METHOD(createView:(nonnull NSNumber *)reactTag 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 // UIBlocks array. This way, it doesn't get deferred until after layout. __weak RCTUIManager *weakManager = self; @@ -984,11 +964,7 @@ RCT_EXPORT_METHOD(createView:(nonnull NSNumber *)reactTag } UIView *view = [componentData createViewWithTag:reactTag]; if (view) { - [componentData setProps:props forView:view]; // Must be done before bgColor to prevent wrong default - if ([view respondsToSelector:@selector(setBackgroundColor:)]) { - ((UIView *)view).backgroundColor = backgroundColor; - } - + [componentData setProps:props forView:view]; uiManager->_viewRegistry[reactTag] = view; #if RCT_DEV diff --git a/React/Views/RCTShadowView.h b/React/Views/RCTShadowView.h index f3b334e634..0e2c2771dc 100644 --- a/React/Views/RCTShadowView.h +++ b/React/Views/RCTShadowView.h @@ -55,7 +55,6 @@ typedef void (^RCTApplierBlock)(NSDictionary *viewRegistry @property (nonatomic, weak, readonly) RCTShadowView *superview; @property (nonatomic, assign, readonly) YGNodeRef yogaNode; @property (nonatomic, copy) NSString *viewName; -@property (nonatomic, strong) UIColor *backgroundColor; // Used to propagate to children @property (nonatomic, copy) RCTDirectEventBlock onLayout; /** diff --git a/React/Views/RCTShadowView.m b/React/Views/RCTShadowView.m index b3d9d69101..ee4617278f 100644 --- a/React/Views/RCTShadowView.m +++ b/React/Views/RCTShadowView.m @@ -19,8 +19,6 @@ typedef void (^RCTActionBlock)(RCTShadowView *shadowViewSelf, id value); typedef void (^RCTResetActionBlock)(RCTShadowView *shadowViewSelf); -static NSString *const RCTBackgroundColorProp = @"backgroundColor"; - typedef NS_ENUM(unsigned int, meta_prop_t) { META_PROP_LEFT, 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 *viewRegistry) { - UIView *view = viewRegistry[self->_reactTag]; - [view reactSetInheritedBackgroundColor:parentBackgroundColor]; - }]; - } - } else { - // Update parent properties for children - NSMutableDictionary *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; } @@ -786,12 +764,6 @@ RCT_STYLE_PROPERTY(Display, display, Display, YGDisplay) RCT_STYLE_PROPERTY(Direction, direction, Direction, YGDirection) RCT_STYLE_PROPERTY(AspectRatio, aspectRatio, AspectRatio, float) -- (void)setBackgroundColor:(UIColor *)color -{ - _backgroundColor = color; - [self dirtyPropagation]; -} - - (void)didUpdateReactSubviews { // Does nothing by default diff --git a/React/Views/RCTViewManager.m b/React/Views/RCTViewManager.m index 99c40a7fdb..54ad89d2df 100644 --- a/React/Views/RCTViewManager.m +++ b/React/Views/RCTViewManager.m @@ -273,8 +273,6 @@ RCT_REMAP_VIEW_PROPERTY(zIndex, reactZIndex, NSInteger) #pragma mark - ShadowView properties -RCT_EXPORT_SHADOW_PROPERTY(backgroundColor, UIColor) - RCT_EXPORT_SHADOW_PROPERTY(top, YGValue) RCT_EXPORT_SHADOW_PROPERTY(right, YGValue) RCT_EXPORT_SHADOW_PROPERTY(start, YGValue) diff --git a/React/Views/UIView+React.h b/React/Views/UIView+React.h index b81b8f645a..345570a036 100644 --- a/React/Views/UIView+React.h +++ b/React/Views/UIView+React.h @@ -66,11 +66,6 @@ */ - (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. */ diff --git a/React/Views/UIView+React.m b/React/Views/UIView+React.m index b8970ab083..0387066252 100644 --- a/React/Views/UIView+React.m +++ b/React/Views/UIView+React.m @@ -193,11 +193,6 @@ self.bounds = bounds; } -- (void)reactSetInheritedBackgroundColor:(__unused UIColor *)inheritedBackgroundColor -{ - // Does nothing by default -} - - (UIViewController *)reactViewController { id responder = [self nextResponder];