Skip to content

Commit

Permalink
refactor(ios): subcomponents to hippySubviews prop for compatibility
Browse files Browse the repository at this point in the history
Earlier Hippy3 versions used subcomponents to represent children,
For better compatibility with Hippy2, change back to hippySubviews
  • Loading branch information
wwwcg committed Aug 7, 2024
1 parent 73e814e commit 4b2506e
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion renderer/native/ios/renderer/HippyComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ typedef void (^HippyDirectEventBlock)(NSDictionary *body);
@property (nonatomic, weak) __kindof id<HippyComponent> parent;

/// Subviews of current component
- (NSArray<__kindof id<HippyComponent>> *)subcomponents;
- (NSArray<__kindof id<HippyComponent>> *)hippySubviews;

/// Inset
/// - Parameters:
Expand Down
2 changes: 1 addition & 1 deletion renderer/native/ios/renderer/HippyRootShadowView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ - (void)applySizeConstraints {
}

- (void)amendLayoutBeforeMount:(NSMutableSet<NativeRenderApplierBlock> *)blocks {
for (HippyShadowView *renderObject in self.subcomponents) {
for (HippyShadowView *renderObject in self.hippySubviews) {
[renderObject amendLayoutBeforeMount:blocks];
}
}
Expand Down
4 changes: 2 additions & 2 deletions renderer/native/ios/renderer/HippyUIManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ - (void)removeAllObjects {
static void NativeRenderTraverseViewNodes(id<HippyComponent> view, void (^block)(id<HippyComponent>)) {
if (view.hippyTag != nil) {
block(view);
for (id<HippyComponent> subview in view.subcomponents) {
for (id<HippyComponent> subview in view.hippySubviews) {
NativeRenderTraverseViewNodes(subview, block);
}
}
Expand Down Expand Up @@ -597,7 +597,7 @@ - (UIView *)createViewRecursiveFromRenderObjectWithNOLock:(HippyShadowView *)sha
}
NSUInteger index = 0;
for (HippyShadowView *subRenderObject in shadowView.subcomponents) {
for (HippyShadowView *subRenderObject in shadowView.hippySubviews) {
UIView *subview = [self createViewRecursiveFromRenderObjectWithNOLock:subRenderObject];
[view insertHippySubview:subview atIndex:index];
index++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ - (void)setScrollEnabled:(BOOL)value {
// here we use super's hippyBridgeDidFinishTransaction imp to trigger reload,
// and override reloadData to handle special logic
- (void)reloadData {
NSArray<HippyShadowView *> *datasource = [self.hippyShadowView.subcomponents copy];
NSArray<HippyShadowView *> *datasource = [self.hippyShadowView.hippySubviews copy];
self->_dataSource = [[HippyNextBaseListViewDataSource alloc] initWithDataSource:datasource
itemViewName:[self compoentItemName]
containBannerView:NO];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ - (void)insertHippySubview:(UIView *)view atIndex:(NSInteger)atIndex {
}
}

- (NSArray<UIView *> *)subcomponents {
- (NSArray<UIView *> *)hippySubviews {
return _contentView ? [NSMutableArray arrayWithObject:_contentView] : nil;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ - (NSArray *)refreshItemIndexArrayWithOldArrayLength:(NSInteger)length {
}

- (void)refreshItemNodes {
[self.dataSource setDataSource:self.hippyShadowView.subcomponents containBannerView:NO];
_itemIndexArray = [self refreshItemIndexArrayWithOldArrayLength:self.hippyShadowView.subcomponents.count];
[self.dataSource setDataSource:self.hippyShadowView.hippySubviews containBannerView:NO];
_itemIndexArray = [self refreshItemIndexArrayWithOldArrayLength:self.hippyShadowView.hippySubviews.count];
[self setPreviousMargin:_previousMargin nextMargin:_nextMargin pageGap:_pageGap];
}

Expand Down
10 changes: 5 additions & 5 deletions renderer/native/ios/renderer/component/text/HippyShadowText.mm
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ - (void)amendLayoutBeforeMount:(NSMutableSet<NativeRenderApplierBlock> *)blocks
// so only call amendXxx when subcomponent is not a <Text>.
if (NativeRenderUpdateLifecycleComputed != _propagationLifecycle) {
_propagationLifecycle = NativeRenderUpdateLifecycleComputed;
for (HippyShadowView *shadowView in self.subcomponents) {
for (HippyShadowView *shadowView in self.hippySubviews) {
if (![shadowView isKindOfClass:HippyShadowText.class]) {
[shadowView amendLayoutBeforeMount:blocks];
}
Expand Down Expand Up @@ -441,7 +441,7 @@ - (NSAttributedString *)attributedString {
info.foregroundColor = self.color ?: [UIColor blackColor];
info.backgroundColor = self.backgroundColor;
info.opacity = self.opacity;
info.isNestedText = self.subcomponents.count > 0;
info.isNestedText = self.hippySubviews.count > 0;
_isNestedText = info.isNestedText;
return [self _attributedStringWithStyleInfo:info];
}
Expand Down Expand Up @@ -496,7 +496,7 @@ - (NSAttributedString *)_attributedStringWithStyleInfo:(HippyAttributedStringSty

CGFloat heightOfTallestSubview = 0.0;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.text ?: @""];
for (HippyShadowView *child in [self subcomponents]) {
for (HippyShadowView *child in [self hippySubviews]) {
if ([child isKindOfClass:[HippyShadowText class]]) {
HippyShadowText *childShadowText = (HippyShadowText *)child;
HippyAttributedStringStyleInfo *childInfo = [HippyAttributedStringStyleInfo new];
Expand Down Expand Up @@ -966,7 +966,7 @@ - (void)setAllowFontScaling:(BOOL)allowFontScaling {
return;
}
_allowFontScaling = allowFontScaling;
for (HippyShadowView *child in [self subcomponents]) {
for (HippyShadowView *child in [self hippySubviews]) {
if ([child isKindOfClass:[HippyShadowText class]]) {
((HippyShadowText *)child).allowFontScaling = allowFontScaling;
}
Expand All @@ -983,7 +983,7 @@ - (void)setFontSizeMultiplier:(CGFloat)fontSizeMultiplier {
HippyLogError(@"fontSizeMultiplier value must be > zero.");
_fontSizeMultiplier = 1.0;
}
for (HippyShadowView *child in [self subcomponents]) {
for (HippyShadowView *child in [self hippySubviews]) {
if ([child isKindOfClass:[HippyShadowText class]]) {
((HippyShadowText *)child).fontSizeMultiplier = fontSizeMultiplier;
}
Expand Down
6 changes: 3 additions & 3 deletions renderer/native/ios/renderer/component/text/HippyText.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#import "HippyLog.h"

static void collectNonTextDescendants(HippyText *view, NSMutableArray *nonTextDescendants) {
for (UIView *child in view.subcomponents) {
for (UIView *child in view.hippySubviews) {
if ([child isKindOfClass:[HippyText class]]) {
collectNonTextDescendants((HippyText *)child, nonTextDescendants);
} else {
Expand Down Expand Up @@ -65,11 +65,11 @@ - (void)hippySetFrame:(CGRect)frame {
}

- (void)removeHippySubview:(UIView *)subview {
if ([[self subcomponents] containsObject:subview]) {
if ([[self hippySubviews] containsObject:subview]) {
[super removeHippySubview:subview];
}
else {
NSArray<UIView *> *hippySubviews = [self subcomponents];
NSArray<UIView *> *hippySubviews = [self hippySubviews];
for (UIView *hippySubview in hippySubviews) {
[hippySubview removeHippySubview:subview];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#import "UIView+Hippy.h"

static void collectDirtyNonTextDescendants(HippyShadowText *renderObject, NSMutableArray *nonTextDescendants) {
for (HippyShadowView *child in renderObject.subcomponents) {
for (HippyShadowView *child in renderObject.hippySubviews) {
if ([child isKindOfClass:[HippyShadowText class]]) {
collectDirtyNonTextDescendants((HippyShadowText *)child, nonTextDescendants);
} else if ([child isTextDirty]) {
Expand Down Expand Up @@ -109,7 +109,7 @@ - (HippyViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(NSDictionary<NS
[(HippyShadowText *)shadowView recomputeText];
collectDirtyNonTextDescendants((HippyShadowText *)shadowView, queue);
} else {
for (HippyShadowView *child in [shadowView subcomponents]) {
for (HippyShadowView *child in [shadowView hippySubviews]) {
if ([child isTextDirty]) {
[queue addObject:child];
}
Expand Down
14 changes: 7 additions & 7 deletions renderer/native/ios/renderer/component/view/HippyShadowView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ - (void)amendLayoutBeforeMount:(NSMutableSet<NativeRenderApplierBlock> *)blocks
return;
}
_propagationLifecycle = NativeRenderUpdateLifecycleComputed;
for (HippyShadowView *renderObjectView in self.subcomponents) {
for (HippyShadowView *renderObjectView in self.hippySubviews) {
[renderObjectView amendLayoutBeforeMount:blocks];
}
}
Expand Down Expand Up @@ -160,15 +160,15 @@ - (void)setTextComputed {

- (void)synchronousRecusivelySetCreationTypeToInstant {
self.creationType = HippyCreationTypeInstantly;
for (HippyShadowView *subShadowView in self.subcomponents) {
for (HippyShadowView *subShadowView in self.hippySubviews) {
[subShadowView synchronousRecusivelySetCreationTypeToInstant];
}
}

- (UIView *)createView:(HippyViewCreationBlock)creationBlock insertChildren:(HippyViewInsertionBlock)insertionBlock {
UIView *container = creationBlock(self);
NSMutableArray *children = [NSMutableArray arrayWithCapacity:[self.subcomponents count]];
for (HippyShadowView *subviews in self.subcomponents) {
NSMutableArray *children = [NSMutableArray arrayWithCapacity:[self.hippySubviews count]];
for (HippyShadowView *subviews in self.hippySubviews) {
UIView *subview = [subviews createView:creationBlock insertChildren:insertionBlock];
if (subview) {
[children addObject:subview];
Expand Down Expand Up @@ -217,7 +217,7 @@ - (void)removeFromHippySuperview {
[superview removeHippySubview:self];
}

- (NSArray<HippyShadowView *> *)subcomponents {
- (NSArray<HippyShadowView *> *)hippySubviews {
return _objectSubviews;
}

Expand Down Expand Up @@ -415,7 +415,7 @@ - (void)setConfirmedLayoutDirection:(hippy::Direction)confirmedLayoutDirection {

- (void)applyConfirmedLayoutDirectionToSubviews:(hippy::Direction)confirmedLayoutDirection {
_confirmedLayoutDirection = confirmedLayoutDirection;
for (HippyShadowView *subviews in self.subcomponents) {
for (HippyShadowView *subviews in self.hippySubviews) {
[subviews applyConfirmedLayoutDirectionToSubviews:confirmedLayoutDirection];
}
}
Expand Down Expand Up @@ -448,7 +448,7 @@ - (void)checkLayoutDirection:(NSMutableSet<HippyShadowView *> *)viewsSet directi
- (void)superviewLayoutDirectionChangedTo:(hippy::Direction)direction {
if (hippy::Direction::Inherit == self.layoutDirection) {
self.confirmedLayoutDirection = ((HippyShadowView *)[self parent]).confirmedLayoutDirection;
for (HippyShadowView *subview in self.subcomponents) {
for (HippyShadowView *subview in self.hippySubviews) {
[subview superviewLayoutDirectionChangedTo:self.confirmedLayoutDirection];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ - (void)checkLayoutDirection:(NSMutableSet<UIView *> *)viewsSet direction:(hippy
- (void)superviewLayoutDirectionChangedTo:(hippy::Direction)direction {
if (hippy::Direction::Inherit == self.layoutDirection) {
self.confirmedLayoutDirection = [self superview].confirmedLayoutDirection;
for (UIView *subview in self.subcomponents) {
for (UIView *subview in self.hippySubviews) {
[subview superviewLayoutDirectionChangedTo:self.confirmedLayoutDirection];
}
}
Expand Down
20 changes: 10 additions & 10 deletions renderer/native/ios/renderer/component/view/UIView+Hippy.mm
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ - (NSNumber *)hippyTagAtPoint:(CGPoint)point {
return view.hippyTag;
}

- (NSArray<UIView *> *)subcomponents {
- (NSArray<__kindof id<HippyComponent>> *)hippySubviews {
return objc_getAssociatedObject(self, _cmd);
}

Expand All @@ -160,14 +160,14 @@ - (void)setParent:(id<HippyComponent>)parent {

- (void)insertHippySubview:(UIView *)subview atIndex:(NSUInteger)atIndex {
// We access the associated object directly here in case someone overrides
// the `subcomponents` getter method and returns an immutable array.
// the `hippySubviews` getter method and returns an immutable array.
if (nil == subview) {
return;
}
NSMutableArray *subviews = objc_getAssociatedObject(self, @selector(subcomponents));
NSMutableArray *subviews = objc_getAssociatedObject(self, @selector(hippySubviews));
if (!subviews) {
subviews = [NSMutableArray new];
objc_setAssociatedObject(self, @selector(subcomponents), subviews, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
objc_setAssociatedObject(self, @selector(hippySubviews), subviews, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

if (atIndex <= [subviews count]) {
Expand All @@ -188,8 +188,8 @@ - (void)moveHippySubview:(UIView *)subview toIndex:(NSUInteger)atIndex {

- (void)removeHippySubview:(UIView *)subview {
// We access the associated object directly here in case someone overrides
// the `subcomponents` getter method and returns an immutable array.
NSMutableArray *subviews = objc_getAssociatedObject(self, @selector(subcomponents));
// the `hippySubviews` getter method and returns an immutable array.
NSMutableArray *subviews = objc_getAssociatedObject(self, @selector(hippySubviews));
[subviews removeObject:subview];
[subview sendDetachedFromWindowEvent];
[subview removeFromSuperview];
Expand All @@ -201,7 +201,7 @@ - (void)removeFromHippySuperview {
}

- (void)resetHippySubviews {
NSMutableArray *subviews = objc_getAssociatedObject(self, @selector(subcomponents));
NSMutableArray *subviews = objc_getAssociatedObject(self, @selector(hippySubviews));
if (subviews) {
[subviews makeObjectsPerformSelector:@selector(sendDetachedFromWindowEvent)];
[subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
Expand Down Expand Up @@ -241,21 +241,21 @@ - (void)setHippySubviewsUpdated:(BOOL)subViewsUpdated {
if (!subviews) {
// Check if sorting is required - in most cases it won't be
BOOL sortingRequired = NO;
for (UIView *subview in self.subcomponents) {
for (UIView *subview in self.hippySubviews) {
if (subview.hippyZIndex != 0) {
sortingRequired = YES;
break;
}
}
subviews = sortingRequired ? [self.subcomponents sortedArrayUsingComparator:^NSComparisonResult(UIView *a, UIView *b) {
subviews = sortingRequired ? [self.hippySubviews sortedArrayUsingComparator:^NSComparisonResult(UIView *a, UIView *b) {
if (a.hippyZIndex > b.hippyZIndex) {
return NSOrderedDescending;
} else {
// ensure sorting is stable by treating equal zIndex as ascending so
// that original order is preserved
return NSOrderedAscending;
}
}] : self.subcomponents;
}] : self.hippySubviews;
objc_setAssociatedObject(self, _cmd, subviews, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
return subviews;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ - (void)amendLayoutBeforeMount:(NSMutableSet<NativeRenderApplierBlock> *)blocks
_layoutDirty = YES;
}
_propagationLifecycle = NativeRenderUpdateLifecycleComputed;
for (HippyShadowView *renderObjectView in self.subcomponents) {
for (HippyShadowView *renderObjectView in self.hippySubviews) {
[renderObjectView amendLayoutBeforeMount:blocks];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ - (void)hippyBridgeDidFinishTransaction {
}

- (void)reloadData {
NSArray<HippyShadowView *> *datasource = [self.hippyShadowView.subcomponents copy];
NSArray<HippyShadowView *> *datasource = [self.hippyShadowView.hippySubviews copy];
_dataSource = [[HippyWaterfallViewDataSource alloc] initWithDataSource:datasource
itemViewName:[self compoentItemName]
containBannerView:_containBannerView];
Expand Down

0 comments on commit 4b2506e

Please sign in to comment.