diff --git a/renderer/native/ios/renderer/component/text/HippyShadowText.mm b/renderer/native/ios/renderer/component/text/HippyShadowText.mm index cdf95d7cbb6..a9e404624b8 100644 --- a/renderer/native/ios/renderer/component/text/HippyShadowText.mm +++ b/renderer/native/ios/renderer/component/text/HippyShadowText.mm @@ -191,14 +191,11 @@ - (void)contentSizeMultiplierDidChange:(__unused NSNotification *)note { [self dirtyText:YES]; } -- (NSDictionary *)processUpdatedProperties:(NSMutableSet *)applierBlocks - parentProperties:(NSDictionary *)parentProperties { +- (void)processUpdatedPropertiesBeforeMount:(NSMutableSet *)applierBlocks { if ([[self parent] isKindOfClass:[HippyShadowText class]]) { - return parentProperties; + return; } -// parentProperties = [super processUpdatedProperties:applierBlocks parentProperties:parentProperties]; - UIEdgeInsets padding = self.paddingAsInsets; CGFloat width = self.frame.size.width - (padding.left + padding.right); @@ -232,7 +229,6 @@ - (void)contentSizeMultiplierDidChange:(__unused NSNotification *)note { [(HippyTextView *)parentView performTextUpdate]; } }]; - return parentProperties; } - (void)amendLayoutBeforeMount:(NSMutableSet *)blocks { @@ -322,7 +318,7 @@ - (void)amendLayoutBeforeMount:(NSMutableSet *)blocks } @catch (NSException *exception) { HippyLogError(@"Exception while doing %s: %@, %@", __func__, exception.description, self); } - [self processUpdatedProperties:blocks parentProperties:nil]; + [self processUpdatedPropertiesBeforeMount:blocks]; } - (void)applyConfirmedLayoutDirectionToSubviews:(hippy::Direction)confirmedLayoutDirection { diff --git a/renderer/native/ios/renderer/component/text/HippyText.mm b/renderer/native/ios/renderer/component/text/HippyText.mm index 2e9ebd1a129..13ecbe2afdd 100644 --- a/renderer/native/ios/renderer/component/text/HippyText.mm +++ b/renderer/native/ios/renderer/component/text/HippyText.mm @@ -80,16 +80,6 @@ - (BOOL)canBeRetrievedFromViewCache { return NO; } -- (void)hippySetInheritedBackgroundColor:(__unused UIColor *)inheritedBackgroundColor { - // mttrn: - // UIColor *backgroundColor = [self rightBackgroundColorOfTheme]; - // - // if (backgroundColor) { - // self.backgroundColor = backgroundColor; - // } else - // self.backgroundColor = inheritedBackgroundColor; -} - - (void)didUpdateHippySubviews { // Do nothing, as subviews are managed by `setTextStorage:` method } diff --git a/renderer/native/ios/renderer/component/view/HippyShadowView.h b/renderer/native/ios/renderer/component/view/HippyShadowView.h index 07448d6d4d0..8fe4ac2e40a 100644 --- a/renderer/native/ios/renderer/component/view/HippyShadowView.h +++ b/renderer/native/ios/renderer/component/view/HippyShadowView.h @@ -142,15 +142,18 @@ typedef void (^HippyViewInsertionBlock)(UIView *container, NSArray *ch - (void)setLayoutFrame:(CGRect)frame; - (void)setLayoutFrame:(CGRect)frame dirtyPropagation:(BOOL)dirtyPropagation; -/** - * Process the updated properties and apply them to view. Shadow view classes - * that add additional propagating properties should override this method. - */ -- (NSDictionary *)processUpdatedProperties:(NSMutableSet *)applierBlocks - parentProperties:(nullable NSDictionary *)parentProperties; +/// Called by UIManager before mounting views. +/// - Parameter blocks: blocks to be executed - (void)amendLayoutBeforeMount:(NSMutableSet *)blocks; +/// Provide a time to modify the View before mounting, +/// Call by amendLayoutBeforeMount. +/// Such as to handle some layout tasks that need to be adjusted independently +/// after layout engine has completed the layout calculation. +/// - Parameter applierBlocks: blocks to be executed +- (void)processUpdatedPropertiesBeforeMount:(NSMutableSet *)applierBlocks; + /** * Return whether or not this node acts as a leaf node in the eyes of CSSLayout. For example * HippyShadowText has children which it does not want CSSLayout to lay out so in the eyes of diff --git a/renderer/native/ios/renderer/component/view/HippyShadowView.mm b/renderer/native/ios/renderer/component/view/HippyShadowView.mm index 8f59aacd67b..2aa96d1277a 100644 --- a/renderer/native/ios/renderer/component/view/HippyShadowView.mm +++ b/renderer/native/ios/renderer/component/view/HippyShadowView.mm @@ -31,8 +31,6 @@ #import "HippyRenderUtils.h" -static NSString *const HippyBackgroundColorPropKey = @"backgroundColor"; - @implementation HippyShadowView @synthesize hippyTag = _hippyTag; @@ -45,14 +43,17 @@ - (void)amendLayoutBeforeMount:(NSMutableSet *)blocks if (NativeRenderUpdateLifecycleComputed == _propagationLifecycle) { return; } + + // do some additional layout adjust + [self processUpdatedPropertiesBeforeMount:blocks]; + _propagationLifecycle = NativeRenderUpdateLifecycleComputed; - for (HippyShadowView *renderObjectView in self.hippySubviews) { - [renderObjectView amendLayoutBeforeMount:blocks]; + for (HippyShadowView *subShadowView in self.hippySubviews) { + [subShadowView amendLayoutBeforeMount:blocks]; } } -- (NSDictionary *)processUpdatedProperties:(NSMutableSet *)applierBlocks - parentProperties:(NSDictionary *)parentProperties { +- (void)processUpdatedPropertiesBeforeMount:(NSMutableSet *)applierBlocks { if (_didUpdateSubviews) { _didUpdateSubviews = NO; [self didUpdateHippySubviews]; @@ -70,27 +71,6 @@ - (void)amendLayoutBeforeMount:(NSMutableSet *)blocks }]; _confirmedLayoutDirectionDidUpdated = NO; } - if (!_backgroundColor) { - UIColor *parentBackgroundColor = parentProperties[HippyBackgroundColorPropKey]; - if (parentBackgroundColor) { - [applierBlocks addObject:^(NSDictionary *viewRegistry, UIView * _Nullable lazyCreatedView) { - UIView *view = lazyCreatedView ?: viewRegistry[self->_hippyTag]; - [view hippySetInheritedBackgroundColor: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[HippyBackgroundColorPropKey] = [UIColor clearColor]; - } else { - properties[HippyBackgroundColorPropKey] = _backgroundColor; - } - return properties; - } - return parentProperties; } - (instancetype)init { @@ -328,6 +308,16 @@ - (void)setBackgroundColor:(UIColor *)color { [self dirtyPropagation:NativeRenderUpdateLifecyclePropsDirtied]; } +- (void)setZIndex:(NSInteger)zIndex { + _zIndex = zIndex; + HippyShadowView *superShadowView = _superview; + if (superShadowView) { + // Changing zIndex means the subview order of the parent needs updating + superShadowView->_didUpdateSubviews = YES; + [superShadowView dirtyPropagation:NativeRenderUpdateLifecycleLayoutDirtied]; + } +} + - (void)didUpdateHippySubviews { // Does nothing by default } diff --git a/renderer/native/ios/renderer/component/view/HippyView.m b/renderer/native/ios/renderer/component/view/HippyView.m index 77e0b33d068..978089368e5 100644 --- a/renderer/native/ios/renderer/component/view/HippyView.m +++ b/renderer/native/ios/renderer/component/view/HippyView.m @@ -385,17 +385,6 @@ - (BOOL)getLayerContentForColor:(UIColor *)color completionBlock:(void (^)(UIIma return YES; } -static BOOL NativeRenderLayerHasShadow(CALayer *layer) { - return layer.shadowOpacity * CGColorGetAlpha(layer.shadowColor) > 0; -} - -- (void)hippySetInheritedBackgroundColor:(UIColor *)inheritedBackgroundColor { - // Inherit background color if a shadow has been set, as an optimization - if (NativeRenderLayerHasShadow(self.layer)) { - self.backgroundColor = inheritedBackgroundColor; - } -} - - (void)updateClippingForLayer:(CALayer *)layer { CALayer *mask = nil; CGFloat cornerRadius = 0; diff --git a/renderer/native/ios/renderer/component/view/UIView+Hippy.h b/renderer/native/ios/renderer/component/view/UIView+Hippy.h index 3e0899f5ddf..908b5bcb842 100644 --- a/renderer/native/ios/renderer/component/view/UIView+Hippy.h +++ b/renderer/native/ios/renderer/component/view/UIView+Hippy.h @@ -76,11 +76,6 @@ NS_ASSUME_NONNULL_BEGIN */ - (void)hippySetFrame:(CGRect)frame; -/** - * Used to improve performance when compositing views with translucent content. - */ -- (void)hippySetInheritedBackgroundColor:(UIColor *)inheritedBackgroundColor; - /** * This method finds and returns the containing view controller for the view. */ diff --git a/renderer/native/ios/renderer/component/view/UIView+Hippy.mm b/renderer/native/ios/renderer/component/view/UIView+Hippy.mm index 34b7a2e270b..fc8d2732aba 100644 --- a/renderer/native/ios/renderer/component/view/UIView+Hippy.mm +++ b/renderer/native/ios/renderer/component/view/UIView+Hippy.mm @@ -286,10 +286,6 @@ - (void)hippySetFrame:(CGRect)frame { self.frame = frame; } -- (void)hippySetInheritedBackgroundColor:(__unused UIColor *)inheritedBackgroundColor { - // Does nothing by default -} - - (UIViewController *)hippyViewController { id responder = [self nextResponder]; while (responder) {