Skip to content

Commit

Permalink
Merge branch 'main' into feature/update-vue-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
open-hippy authored Dec 22, 2023
2 parents d4050ed + 4d904b0 commit 0b96ebb
Show file tree
Hide file tree
Showing 22 changed files with 442 additions and 599 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
20 changes: 19 additions & 1 deletion renderer/native/ios/renderer/HippyComponentMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,28 @@ class RootNode;

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSUInteger, HippyComponentReferenceType) {
HippyComponentReferenceTypeStrong,
HippyComponentReferenceTypeWeak,
};

@interface HippyComponentMap : NSObject

/// Whether all recorded elements are strongly referenced,
///
/// Attention, Attention, Attention:
/// All UI views are weakly referenced!
/// All Shadowviews are strongly referenced!
@property (nonatomic, assign, readonly) BOOL isStrongHoldAllComponents;

/// Whether access is required from the main thread
@property(nonatomic, assign) BOOL requireInMainThread;

/// Init Method
- (instancetype)initWithComponentsReferencedType:(HippyComponentReferenceType)type;
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;

- (void)addRootComponent:(id<HippyComponent>)component
rootNode:(std::weak_ptr<hippy::RootNode>)rootNode
forTag:(NSNumber *)tag;
Expand All @@ -60,7 +78,7 @@ NS_ASSUME_NONNULL_BEGIN

- (void)removeComponentByComponentTag:(NSNumber *)componentTag onRootTag:(NSNumber *)rootTag;

- (NSMutableDictionary<NSNumber *, __kindof id<HippyComponent>> *)componentsForRootTag:(NSNumber *)tag;
- (NSDictionary<NSNumber *, __kindof id<HippyComponent>> *)componentsForRootTag:(NSNumber *)tag;

- (__kindof id<HippyComponent>)componentForTag:(NSNumber *)componentTag
onRootTag:(NSNumber *)tag;
Expand Down
27 changes: 19 additions & 8 deletions renderer/native/ios/renderer/HippyComponentMap.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,25 @@
*/

#import "HippyComponentMap.h"

#import "HippyLog.h"
#include "dom/root_node.h"

using RootNode = hippy::RootNode;

@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;
}

@end

@implementation HippyComponentMap

- (instancetype)init {
- (instancetype)initWithComponentsReferencedType:(HippyComponentReferenceType)type {
self = [super init];
if (self) {
_isStrongHoldAllComponents = (HippyComponentReferenceTypeStrong == type);
_rootComponentsMap = [NSMapTable strongToWeakObjectsMapTable];
_componentsMap = [NSMutableDictionary dictionary];
_rootNodesMap.reserve(8);
Expand All @@ -56,7 +57,12 @@ - (void)addRootComponent:(id<HippyComponent>)component
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 (_isStrongHoldAllComponents) {
dic = [NSMutableDictionary dictionary];
} else {
dic = [NSMapTable strongToWeakObjectsMapTable];
}
[dic setObject:component forKey:tag];
[_componentsMap setObject:dic forKey:tag];
[_rootComponentsMap setObject:component forKey:tag];
Expand Down Expand Up @@ -122,23 +128,28 @@ - (void)removeComponentByComponentTag:(NSNumber *)componentTag onRootTag:(NSNumb
}
}

- (NSMutableDictionary<NSNumber * ,__kindof id<HippyComponent>> *)componentsForRootTag:(NSNumber *)tag {
- (NSDictionary<NSNumber * ,__kindof id<HippyComponent>> *)componentsForRootTag:(NSNumber *)tag {
NSAssert(tag, @"tag must not be null in method %@", NSStringFromSelector(_cmd));
NSAssert([self threadCheck], @"%@ method needs run in main thread", NSStringFromSelector(_cmd));
if (tag) {
id map = [_componentsMap objectForKey:tag];
return map;
if (_isStrongHoldAllComponents) {
return map;
} else {
return ((NSMapTable *)map).dictionaryRepresentation;
}
}
return nil;
}

- (__kindof id<HippyComponent>)componentForTag:(NSNumber *)componentTag
onRootTag:(NSNumber *)tag {
NSAssert(componentTag && tag, @"componentTag && tag must not be null in method %@", NSStringFromSelector(_cmd));
onRootTag:(NSNumber *)tag {
NSAssert([self threadCheck], @"%@ method needs run in main thread", NSStringFromSelector(_cmd));
if (componentTag && tag) {
id map = [_componentsMap objectForKey:tag];
return [map objectForKey:componentTag];
} else {
HippyLogError(@"componentTag && tag must not be null");
}
return nil;
}
Expand Down
5 changes: 1 addition & 4 deletions renderer/native/ios/renderer/HippyUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@
/// Get all rootView
- (NSArray<__kindof UIView *> *)rootViews;

/// Purge view from superView
- (void)purgeViewsFromComponentTags:(NSArray<NSNumber *> *)componentTag onRootTag:(NSNumber *)rootTag;

/// Update view with props
- (void)updateView:(NSNumber *)componentTag onRootTag:(NSNumber *)rootTag props:(NSDictionary *)pros;

Expand All @@ -112,7 +109,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 0b96ebb

Please sign in to comment.