Skip to content

Commit

Permalink
fix(ios): refactor & fix listview and waterfall's data loading procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed Dec 18, 2023
1 parent 305cc5a commit 6e6c79c
Show file tree
Hide file tree
Showing 22 changed files with 348 additions and 417 deletions.
38 changes: 20 additions & 18 deletions renderer/native/ios/renderer/HippyComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
typedef void (^HippyDirectEventBlock)(NSDictionary *body);

/**
* Logical node in a tree of application components. Both `NativeRenderObject` and
* `UIView` conforms to this. Allows us to write utilities that reason about
* trees generally.
* Logical node in a tree of application components.
* Both `HippyShadowView` and `UIView` conforms to this.
* Allows us to write utilities that reason about trees generally.
*/
@protocol HippyComponent <NSObject>

Expand All @@ -43,35 +43,37 @@ typedef void (^HippyDirectEventBlock)(NSDictionary *body);
@property (nonatomic, copy) NSDictionary *props;
@property (nonatomic, assign) CGRect frame;

@property(nonatomic, readwrite)__kindof id<HippyComponent> parentComponent;
/// The parent of current component
@property (nonatomic, weak) id<HippyComponent> parent;

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

/// <#Description#>
/// Inset
/// - Parameters:
/// - subview: <#subview description#>
/// - atIndex: <#atIndex description#>
/// - subview: id
/// - atIndex: NSInteger
- (void)insertHippySubview:(id<HippyComponent>)subview atIndex:(NSInteger)atIndex;

/// <#Description#>
/// - Parameter subview: <#subview description#>
/// Remove
/// - Parameter subview: id
- (void)removeHippySubview:(id<HippyComponent>)subview;

/// <#Description#>
/// Move
/// - Parameters:
/// - subview: <#subview description#>
/// - atIndex: <#atIndex description#>
/// - subview: id
/// - atIndex: NSInteger
- (void)moveHippySubview:(id<HippyComponent>)subview toIndex:(NSInteger)atIndex;

/// <#Description#>
/// Remove from superview
- (void)removeFromHippySuperview;

/// <#Description#>
/// - Parameter frame: <#frame description#>
/// Set Frame
/// - Parameter frame: CGRect
- (void)hippySetFrame:(CGRect)frame;

/// <#Description#>
/// - Parameter point: <#point description#>
/// Get accurate tag in special cases such as subviews
/// - Parameter point: CGPoint
- (NSNumber *)hippyTagAtPoint:(CGPoint)point;

/// View/ShadowView is a root view
Expand Down
4 changes: 3 additions & 1 deletion renderer/native/ios/renderer/HippyComponentMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ NS_ASSUME_NONNULL_BEGIN

- (void)addRootComponent:(id<HippyComponent>)component
rootNode:(std::weak_ptr<hippy::RootNode>)rootNode
forTag:(NSNumber *)tag;
forTag:(NSNumber *)tag
strongHoldComponents:(BOOL)shouldStrongHoldAllComponents;


- (void)removeRootComponentWithTag:(NSNumber *)tag;

Expand Down
12 changes: 9 additions & 3 deletions renderer/native/ios/renderer/HippyComponentMap.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

@interface HippyComponentMap () {
NSMapTable<NSNumber *, id<HippyComponent>> *_rootComponentsMap;
NSMutableDictionary<NSNumber *, NSMutableDictionary<NSNumber *, id<HippyComponent>> *> *_componentsMap;
NSMutableDictionary<NSNumber *, id> *_componentsMap;
std::unordered_map<int32_t, std::weak_ptr<RootNode>> _rootNodesMap;
}

Expand All @@ -52,11 +52,17 @@ - (BOOL)threadCheck {

- (void)addRootComponent:(id<HippyComponent>)component
rootNode:(std::weak_ptr<hippy::RootNode>)rootNode
forTag:(NSNumber *)tag {
forTag:(NSNumber *)tag
strongHoldComponents:(BOOL)shouldStrongHoldAllComponents {
NSAssert(component && tag, @"component &&tag must not be null in method %@", NSStringFromSelector(_cmd));
NSAssert([self threadCheck], @"%@ method needs run in main thread", NSStringFromSelector(_cmd));
if (component && tag && ![_componentsMap objectForKey:tag]) {
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
id dic = nil;
if (shouldStrongHoldAllComponents) {
dic = [NSMutableDictionary dictionary];
} else {
dic = [NSMapTable strongToWeakObjectsMapTable];
}
[dic setObject:component forKey:tag];
[_componentsMap setObject:dic forKey:tag];
[_rootComponentsMap setObject:component forKey:tag];
Expand Down
2 changes: 1 addition & 1 deletion renderer/native/ios/renderer/HippyUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
* @param renderObject HippyShadowView corresponding to UIView
* @return view created by HippyShadowView
*/
- (UIView *)createViewRecursivelyFromRenderObject:(HippyShadowView *)renderObject;
- (UIView *)createViewForShadowListItem:(HippyShadowView *)renderObject;

/// Register extra components
/// @param extraComponents extra components classes
Expand Down
Loading

0 comments on commit 6e6c79c

Please sign in to comment.