Skip to content

Commit

Permalink
fix(ios): dynamic changes to zIndex not working (Tencent#4125)
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed Nov 19, 2024
1 parent b793432 commit 671ed2c
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 70 deletions.
10 changes: 3 additions & 7 deletions renderer/native/ios/renderer/component/text/HippyShadowText.mm
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,11 @@ - (void)contentSizeMultiplierDidChange:(__unused NSNotification *)note {
[self dirtyText:YES];
}

- (NSDictionary<NSString *, id> *)processUpdatedProperties:(NSMutableSet<NativeRenderApplierBlock> *)applierBlocks
parentProperties:(NSDictionary<NSString *, id> *)parentProperties {
- (void)processUpdatedPropertiesBeforeMount:(NSMutableSet<NativeRenderApplierBlock> *)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);

Expand Down Expand Up @@ -232,7 +229,6 @@ - (void)contentSizeMultiplierDidChange:(__unused NSNotification *)note {
[(HippyTextView *)parentView performTextUpdate];
}
}];
return parentProperties;
}

- (void)amendLayoutBeforeMount:(NSMutableSet<NativeRenderApplierBlock> *)blocks {
Expand Down Expand Up @@ -322,7 +318,7 @@ - (void)amendLayoutBeforeMount:(NSMutableSet<NativeRenderApplierBlock> *)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 {
Expand Down
10 changes: 0 additions & 10 deletions renderer/native/ios/renderer/component/text/HippyText.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 9 additions & 6 deletions renderer/native/ios/renderer/component/view/HippyShadowView.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,18 @@ typedef void (^HippyViewInsertionBlock)(UIView *container, NSArray<UIView *> *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<NSString *, id> *)processUpdatedProperties:(NSMutableSet<NativeRenderApplierBlock> *)applierBlocks
parentProperties:(nullable NSDictionary<NSString *, id> *)parentProperties;

/// Called by UIManager before mounting views.
/// - Parameter blocks: blocks to be executed
- (void)amendLayoutBeforeMount:(NSMutableSet<NativeRenderApplierBlock> *)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<NativeRenderApplierBlock> *)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
Expand Down
44 changes: 17 additions & 27 deletions renderer/native/ios/renderer/component/view/HippyShadowView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
#import "HippyRenderUtils.h"


static NSString *const HippyBackgroundColorPropKey = @"backgroundColor";

@implementation HippyShadowView

@synthesize hippyTag = _hippyTag;
Expand All @@ -45,14 +43,17 @@ - (void)amendLayoutBeforeMount:(NSMutableSet<NativeRenderApplierBlock> *)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<NSString *, id> *)processUpdatedProperties:(NSMutableSet<NativeRenderApplierBlock> *)applierBlocks
parentProperties:(NSDictionary<NSString *, id> *)parentProperties {
- (void)processUpdatedPropertiesBeforeMount:(NSMutableSet<NativeRenderApplierBlock> *)applierBlocks {
if (_didUpdateSubviews) {
_didUpdateSubviews = NO;
[self didUpdateHippySubviews];
Expand All @@ -70,27 +71,6 @@ - (void)amendLayoutBeforeMount:(NSMutableSet<NativeRenderApplierBlock> *)blocks
}];
_confirmedLayoutDirectionDidUpdated = NO;
}
if (!_backgroundColor) {
UIColor *parentBackgroundColor = parentProperties[HippyBackgroundColorPropKey];
if (parentBackgroundColor) {
[applierBlocks addObject:^(NSDictionary<NSNumber *, UIView *> *viewRegistry, UIView * _Nullable lazyCreatedView) {
UIView *view = lazyCreatedView ?: viewRegistry[self->_hippyTag];
[view hippySetInheritedBackgroundColor: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[HippyBackgroundColorPropKey] = [UIColor clearColor];
} else {
properties[HippyBackgroundColorPropKey] = _backgroundColor;
}
return properties;
}
return parentProperties;
}

- (instancetype)init {
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 0 additions & 11 deletions renderer/native/ios/renderer/component/view/HippyView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions renderer/native/ios/renderer/component/view/UIView+Hippy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
4 changes: 0 additions & 4 deletions renderer/native/ios/renderer/component/view/UIView+Hippy.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 671ed2c

Please sign in to comment.