Skip to content

Commit

Permalink
Demolishing of background color propagation infra
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shergin authored and facebook-github-bot committed Dec 19, 2017
1 parent d89901f commit 2679f3e
Show file tree
Hide file tree
Showing 12 changed files with 3 additions and 103 deletions.
1 change: 1 addition & 0 deletions Libraries/Text/RCTShadowText.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions Libraries/Text/RCTShadowText.m
Original file line number Diff line number Diff line change
Expand Up @@ -620,12 +620,6 @@ - (CGSize)calculateSize:(NSTextStorage *)storage
return requiredSize;
}

- (void)setBackgroundColor:(UIColor *)backgroundColor
{
super.backgroundColor = backgroundColor;
[self dirtyText];
}

#define RCT_TEXT_PROPERTY(setProp, ivar, type) \
- (void)set##setProp:(type)value; \
{ \
Expand Down
1 change: 1 addition & 0 deletions Libraries/Text/RCTTextManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ - (RCTShadowView *)shadowView
#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)
Expand Down
17 changes: 0 additions & 17 deletions React/Base/RCTRootContentView.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
#import "UIView+React.h"

@implementation RCTRootContentView
{
UIColor *_backgroundColor;
}

- (instancetype)initWithFrame:(CGRect)frame
bridge:(RCTBridge *)bridge
Expand All @@ -34,7 +31,6 @@ - (instancetype)initWithFrame:(CGRect)frame
_touchHandler = [[RCTTouchHandler alloc] initWithBridge:_bridge];
[_touchHandler attachToView:self];
[_bridge.uiManager registerRootView:self];
self.layer.backgroundColor = NULL;
}
return self;
}
Expand Down Expand Up @@ -89,19 +85,6 @@ - (void)updateAvailableSize
[_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
Expand Down
7 changes: 0 additions & 7 deletions React/Base/RCTRootView.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,6 @@ - (UIView *)preferredFocusedView
}
#endif

- (void)setBackgroundColor:(UIColor *)backgroundColor
{
super.backgroundColor = backgroundColor;
_contentView.backgroundColor = backgroundColor;
}

#pragma mark - passThroughTouches

- (BOOL)passThroughTouches
Expand Down Expand Up @@ -282,7 +276,6 @@ - (void)bundleFinishedLoading:(RCTBridge *)bridge
sizeFlexiblity:_sizeFlexibility];
[self runApplication:bridge];

_contentView.backgroundColor = self.backgroundColor;
_contentView.passThroughTouches = _passThroughTouches;
[self insertSubview:_contentView atIndex:0];

Expand Down
7 changes: 0 additions & 7 deletions React/Modules/RCTUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 1 addition & 25 deletions React/Modules/RCTUIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ - (void)registerRootView:(RCTRootContentView *)rootView
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];
Expand Down Expand Up @@ -417,20 +416,6 @@ - (void)setIntrinsicContentSize:(CGSize)intrinsicContentSize forView:(UIView *)v
} 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
*/
Expand Down Expand Up @@ -969,11 +954,6 @@ - (void)_manageChildren:(NSNumber *)containerTag
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;
Expand All @@ -984,11 +964,7 @@ - (void)_manageChildren:(NSNumber *)containerTag
}
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
Expand Down
1 change: 0 additions & 1 deletion React/Views/RCTShadowView.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ typedef void (^RCTApplierBlock)(NSDictionary<NSNumber *, UIView *> *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;

/**
Expand Down
28 changes: 0 additions & 28 deletions React/Views/RCTShadowView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -278,26 +276,6 @@ - (void)applyLayoutToChildren:(YGNodeRef)node
}];
}

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;
}

Expand Down Expand Up @@ -786,12 +764,6 @@ - (type)getProp \
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
Expand Down
2 changes: 0 additions & 2 deletions React/Views/RCTViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,6 @@ - (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(__unused NSDictio

#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)
Expand Down
5 changes: 0 additions & 5 deletions React/Views/UIView+React.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
5 changes: 0 additions & 5 deletions React/Views/UIView+React.m
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,6 @@ - (void)reactSetFrame:(CGRect)frame
self.bounds = bounds;
}

- (void)reactSetInheritedBackgroundColor:(__unused UIColor *)inheritedBackgroundColor
{
// Does nothing by default
}

- (UIViewController *)reactViewController
{
id responder = [self nextResponder];
Expand Down

0 comments on commit 2679f3e

Please sign in to comment.