Skip to content

Commit

Permalink
refactor(ios): remove unused data structure in waterfall item
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed Aug 7, 2024
1 parent e390c33 commit 73e814e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 208 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,12 @@

NS_ASSUME_NONNULL_BEGIN

@interface WaterfallItemChangeContext : NSObject<NSCopying>

- (NSHashTable<__kindof HippyShadowView *> *)addedItems;
- (NSHashTable<__kindof HippyShadowView *> *)frameChangedItems;
- (NSSet<__kindof HippyShadowView *> *)deletedItems;
- (NSHashTable<__kindof HippyShadowView *> *)movedItems;

/// Clear all items recorded.
- (void)clear;

/// Whether has changed item.
- (BOOL)hasChanges;

/// Get all chaned items.
- (NSSet<HippyShadowView *> *)allChangedItems;

@end

/// ListView's shadowView
@interface HippyShadowListView : HippyShadowView <HippyShadowWaterfallItemFrameChangedProtocol>

///// Whether current ShadowList is dirty.
//@property (nonatomic, assign) BOOL isDirty;

@property(nonatomic, readonly, strong)WaterfallItemChangeContext *itemChangeContext;
/// Whether current ShadowList is dirty.
/// Used to determine whether the list needs reload.
@property (nonatomic, assign) BOOL isDirty;

@end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*!
* iOS SDK
*
* Tencent is pleased to support the open source community by making
* Hippy available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company.
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import "HippyShadowListView.h"
#import "HippyWaterfallView.h"
#import "HippyAssert.h"


@implementation HippyShadowListView

- (void)insertHippySubview:(HippyShadowView *)subview atIndex:(NSUInteger)atIndex {
[super insertHippySubview:subview atIndex:atIndex];
if ([subview isKindOfClass:[HippyShadowWaterfallItem class]]) {
HippyShadowWaterfallItem *objectItem = (HippyShadowWaterfallItem *)subview;
objectItem.observer = self;
}
self.isDirty = YES;
}

- (void)removeHippySubview:(HippyShadowView *)subview {
[super removeHippySubview:subview];
if ([subview isKindOfClass:[HippyShadowWaterfallItem class]]) {
HippyShadowWaterfallItem *objectItem = (HippyShadowWaterfallItem *)subview;
objectItem.observer = nil;
}
self.isDirty = YES;
}

- (void)itemFrameChanged:(__kindof HippyShadowWaterfallItem *)item {
self.isDirty = YES;
}

@end

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@ NS_ASSUME_NONNULL_BEGIN
@protocol HippyShadowWaterfallItemFrameChangedProtocol <NSObject>

@required
/// Calledn when item frame changed
/// - Parameter item: shadow waterfall item
- (void)itemFrameChanged:(__kindof HippyShadowWaterfallItem *)item;

@end

/// Waterfall item's shadowView
@interface HippyShadowWaterfallItem : HippyShadowView

@property(nonatomic, assign, getter=isLayoutDirty) BOOL layoutDirty;
@property(nonatomic, weak) id<HippyShadowWaterfallItemFrameChangedProtocol> observer;
@property (nonatomic, assign, getter=isLayoutDirty) BOOL layoutDirty;

/// frame change observer, usually is shadowListView
@property (nonatomic, weak) id<HippyShadowWaterfallItemFrameChangedProtocol> observer;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ - (BOOL)isManualScrolling {

- (void)hippyBridgeDidFinishTransaction {
HippyShadowListView *listNode = self.hippyShadowView;
if (!_dataSource || (listNode && listNode.itemChangeContext.hasChanges)) {
HippyLogTrace(@"🔥 %@ Reload %@", self.hippyTag, [[listNode itemChangeContext] description]);
if (!_dataSource || (listNode && listNode.isDirty)) {
HippyLogTrace(@"🔥 %@ Reload", self.hippyTag);
[self cacheVisibleCellViewsForReuse];
[self reloadData];
[listNode.itemChangeContext clear];
listNode.isDirty = NO;
}
}

Expand Down

0 comments on commit 73e814e

Please sign in to comment.