Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pub/framework/voltron/dio-5.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
open-hippy authored Oct 30, 2023
2 parents 01aa427 + 941eec7 commit 5050ebd
Show file tree
Hide file tree
Showing 21 changed files with 1,040 additions and 1,089 deletions.
11 changes: 6 additions & 5 deletions renderer/native/ios/renderer/HippyRootView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#import "HippyBridge.h"
#import "HippyUIManager.h"
#import "HippyDeviceBaseInfo.h"
#import "HippyTouchHandler.h"
#include <objc/runtime.h>

// Sent when the first subviews are added to the root view
Expand All @@ -51,7 +52,7 @@
@interface HippyRootContentView : HippyView <HippyInvalidating>

@property (nonatomic, readonly) BOOL contentHasAppeared;
//@property (nonatomic, strong) HippyTouchHandler *touchHandler;
@property (nonatomic, strong) HippyTouchHandler *touchHandler;
@property (nonatomic, assign) int64_t startTimpStamp;

- (instancetype)initWithFrame:(CGRect)frame
Expand Down Expand Up @@ -200,7 +201,7 @@ - (BOOL)canBecomeFirstResponder {
}

- (void)cancelTouches {
// [[_contentView touchHandler] cancelTouch];
[[_contentView touchHandler] cancelTouch];
}

- (NSNumber *)hippyTag {
Expand Down Expand Up @@ -293,9 +294,9 @@ - (instancetype)initWithFrame:(CGRect)frame
_bridge = bridge;
self.hippyTag = hippyTag;

// FIXME: HippyTouchHandler
// _touchHandler = [[HippyTouchHandler alloc] initWithRootView:self bridge:bridge];
// [self addGestureRecognizer:_touchHandler];
// 添加Hippy自定义手势识别器,用于管理手势事件,并将其发送至js端。
_touchHandler = [[HippyTouchHandler alloc] initWithRootView:self bridge:bridge];
[self addGestureRecognizer:_touchHandler];

self.layer.backgroundColor = NULL;
_startTimpStamp = CACurrentMediaTime() * 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#import <Foundation/Foundation.h>

@protocol NativeRenderScrollProtocol <NSObject>
@protocol HippyScrollProtocol <NSObject>

@required

Expand Down
13 changes: 9 additions & 4 deletions renderer/native/ios/renderer/HippyUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#import "HippyInvalidating.h"
#import "NativeRenderDefines.h"
#import "HippyBridgeModule.h"
#import "HippyCustomTouchHandlerProtocol.h"
#include <memory>
#include <unordered_map>
#include <functional>
Expand Down Expand Up @@ -73,15 +74,15 @@ class HippyValue;
/**
* Gets the view associated with a hippyTag.
*/
- (UIView *)viewForComponentTag:(NSNumber *)componentTag
onRootTag:(NSNumber *)rootTag;
- (UIView *)viewForHippyTag:(NSNumber *)hippyTag
onRootTag:(NSNumber *)rootTag;


/**
* Get the shadow view associated with a hippyTag
*/
- (HippyShadowView *)renderObjectForcomponentTag:(NSNumber *)componentTag
onRootTag:(NSNumber *)rootTag;
- (HippyShadowView *)shadowViewForHippyTag:(NSNumber *)hippyTag
onRootTag:(NSNumber *)rootTag;

/**
* Update the frame of a view. This might be in response to a screen rotation
Expand Down Expand Up @@ -262,4 +263,8 @@ class HippyValue;
/// The current HippyUIManager instance
@property (nonatomic, readonly) HippyUIManager *uiManager;

/// A custom touch handler for gesture special processing
/// You can use it when you need to modify Hippy's default gesture handling logic
@property (nonatomic, strong, readonly) id<HippyCustomTouchHandlerProtocol> customTouchHandler;

@end
172 changes: 72 additions & 100 deletions renderer/native/ios/renderer/HippyUIManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,17 @@ - (HippyComponentMap *)viewRegistry {

- (__kindof UIView *)viewFromRenderViewTag:(NSNumber *)componentTag
onRootTag:(NSNumber *)rootTag {
return [self viewForComponentTag:componentTag onRootTag:rootTag];
return [self viewForHippyTag:componentTag onRootTag:rootTag];
}

- (UIView *)viewForComponentTag:(NSNumber *)componentTag
onRootTag:(NSNumber *)rootTag {
- (UIView *)viewForHippyTag:(NSNumber *)hippyTag onRootTag:(NSNumber *)rootTag {
AssertMainQueue();
return [_viewRegistry componentForTag:componentTag onRootTag:rootTag];
return [_viewRegistry componentForTag:hippyTag onRootTag:rootTag];
}

- (HippyShadowView *)renderObjectForcomponentTag:(NSNumber *)componentTag
- (HippyShadowView *)shadowViewForHippyTag:(NSNumber *)hippyTag
onRootTag:(NSNumber *)rootTag {
return [_shadowViewRegistry componentForTag:componentTag onRootTag:rootTag];
return [_shadowViewRegistry componentForTag:hippyTag onRootTag:rootTag];
}

- (std::weak_ptr<hippy::RenderManager>)renderManager {
Expand Down Expand Up @@ -444,7 +443,7 @@ - (void)purgeChildren:(NSArray<id<HippyComponent>> *)children
- (void)purgeViewsFromComponentTags:(NSArray<NSNumber *> *)componentTags onRootTag:(NSNumber *)rootTag {
for (NSNumber *componentTag in componentTags) {
UIView *view = [self viewForComponentTag:componentTag onRootTag:rootTag];
UIView *view = [self viewForHippyTag:componentTag onRootTag:rootTag];
HippyComponentMap *componentMap = _viewRegistry;
NativeRenderTraverseViewNodes(view, ^(id<HippyComponent> subview) {
NSAssert(![subview isHippyRootView], @"Root views should not be unregistered");
Expand Down Expand Up @@ -555,7 +554,7 @@ - (UIView *)createViewByComponentData:(HippyComponentData *)componentData
rootTag:(NSNumber *)rootTag
properties:(NSDictionary *)props
viewName:(NSString *)viewName {
UIView *view = [self viewForComponentTag:componentTag onRootTag:rootTag];
UIView *view = [self viewForHippyTag:componentTag onRootTag:rootTag];
BOOL canBeRetrievedFromCache = YES;
if (view && [view respondsToSelector:@selector(canBeRetrievedFromViewCache)]) {
canBeRetrievedFromCache = [view canBeRetrievedFromViewCache];
Expand Down Expand Up @@ -1068,8 +1067,8 @@ - (void)registerExtraComponent:(NSArray<Class> *)extraComponents {
_extraComponents = extraComponents;
}
#pragma mark -
#pragma mark Event Handler
#pragma mark - Event Handler
- (void)addEventName:(const std::string &)name forDomNodeId:(int32_t)node_id
onRootNode:(std::weak_ptr<hippy::RootNode>)rootNode {
Expand All @@ -1078,7 +1077,7 @@ - (void)addEventName:(const std::string &)name forDomNodeId:(int32_t)node_id
return;
}
int32_t root_id = strongRootNode->GetId();
HippyShadowView *renderObject = [self renderObjectForcomponentTag:@(node_id) onRootTag:@(root_id)];
HippyShadowView *renderObject = [self shadowViewForHippyTag:@(node_id) onRootTag:@(root_id)];
[renderObject addEventName:name];
if (name == hippy::kClickEvent) {
[self addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
Expand Down Expand Up @@ -1136,6 +1135,7 @@ - (void)addEventName:(const std::string &)name forDomNodeId:(int32_t)node_id
}
}
/// Called when creating view from shadowView
- (void)addEventNameInMainThread:(const std::string &)name
forDomNodeId:(int32_t)node_id
onRootNode:(std::weak_ptr<RootNode>)rootNode {
Expand Down Expand Up @@ -1163,14 +1163,14 @@ - (void)addClickEventListenerForView:(int32_t)componentTag onRootNode:(std::weak
return;
}
int32_t root_id = strongRootNode->GetId();
UIView *view = [self viewForComponentTag:@(componentTag) onRootTag:@(root_id)];
UIView *view = [self viewForHippyTag:@(componentTag) onRootTag:@(root_id)];
if (view) {
__weak id weakSelf = self;
[view addViewEvent:NativeRenderViewEventTypeClick eventListener:^(CGPoint point,
BOOL canCapture,
BOOL canBubble,
BOOL canBePreventedInCapture,
BOOL canBePreventedInBubbling) {
OnTouchEventHandler eventListener = ^(CGPoint point,
BOOL canCapture,
BOOL canBubble,
BOOL canBePreventedInCapture,
BOOL canBePreventedInBubbling) {
id strongSelf = weakSelf;
if (strongSelf) {
[strongSelf domNodeForComponentTag:componentTag onRootNode:rootNode resultNode:^(std::shared_ptr<DomNode> node) {
Expand All @@ -1183,7 +1183,9 @@ - (void)addClickEventListenerForView:(int32_t)componentTag onRootNode:(std::weak
}
}];
}
}];
};
// [view addViewEvent:NativeRenderViewEventTypeClick eventListener:eventListener];
[view setOnClick:eventListener];
}
else {
}
Expand All @@ -1196,14 +1198,14 @@ - (void)addLongClickEventListenerForView:(int32_t)componentTag onRootNode:(std::
return;
}
int32_t root_id = strongRootNode->GetId();
UIView *view = [self viewForComponentTag:@(componentTag) onRootTag:@(root_id)];
UIView *view = [self viewForHippyTag:@(componentTag) onRootTag:@(root_id)];
if (view) {
__weak id weakSelf = self;
[view addViewEvent:NativeRenderViewEventTypeLongClick eventListener:^(CGPoint point,
BOOL canCapture,
BOOL canBubble,
BOOL canBePreventedInCapture,
BOOL canBePreventedInBubbling) {
OnTouchEventHandler eventListener = ^(CGPoint point,
BOOL canCapture,
BOOL canBubble,
BOOL canBePreventedInCapture,
BOOL canBePreventedInBubbling) {
id strongSelf = weakSelf;
if (strongSelf) {
[strongSelf domNodeForComponentTag:componentTag onRootNode:rootNode resultNode:^(std::shared_ptr<DomNode> node) {
Expand All @@ -1216,7 +1218,10 @@ - (void)addLongClickEventListenerForView:(int32_t)componentTag onRootNode:(std::
}
}];
}
}];
};
// [view addViewEvent:NativeRenderViewEventTypeLongClick eventListener:];
[view setOnLongClick:eventListener];
}
else {
}
Expand All @@ -1231,16 +1236,15 @@ - (void)addPressEventListenerForType:(const std::string &)type
}
int32_t root_id = strongRootNode->GetId();
AssertMainQueue();
UIView *view = [self viewForComponentTag:@(componentTag) onRootTag:@(root_id)];
NativeRenderViewEventType eventType = hippy::kPressIn == type ? NativeRenderViewEventType::NativeRenderViewEventTypePressIn : NativeRenderViewEventType::NativeRenderViewEventTypePressOut;
UIView *view = [self viewForHippyTag:@(componentTag) onRootTag:@(root_id)];
if (view) {
std::string block_type = type;
__weak id weakSelf = self;
[view addViewEvent:eventType eventListener:^(CGPoint point,
BOOL canCapture,
BOOL canBubble,
BOOL canBePreventedInCapture,
BOOL canBePreventedInBubbling) {
OnTouchEventHandler eventListener = ^(CGPoint point,
BOOL canCapture,
BOOL canBubble,
BOOL canBePreventedInCapture,
BOOL canBePreventedInBubbling) {
id strongSelf = weakSelf;
if (strongSelf) {
[strongSelf domNodeForComponentTag:componentTag onRootNode:rootNode resultNode:^(std::shared_ptr<DomNode> node) {
Expand All @@ -1253,9 +1257,12 @@ - (void)addPressEventListenerForType:(const std::string &)type
}
}];
}
}];
}
else {
};
if (hippy::kPressIn == type) {
[view setOnPressIn:eventListener];
} else if (hippy::kPressOut == type) {
[view setOnPressOut:eventListener];
}
}
}
Expand All @@ -1268,26 +1275,15 @@ - (void)addTouchEventListenerForType:(const std::string &)type
return;
}
int32_t root_id = strongRootNode->GetId();
UIView *view = [self viewForComponentTag:@(componentTag) onRootTag:@(root_id)];
UIView *view = [self viewForHippyTag:@(componentTag) onRootTag:@(root_id)];
if (view) {
// todo 默认值应该有个值代表未知
NativeRenderViewEventType event_type = NativeRenderViewEventType::NativeRenderViewEventTypeTouchStart;
if (type == hippy::kTouchStartEvent) {
event_type = NativeRenderViewEventType::NativeRenderViewEventTypeTouchStart;
} else if (type == hippy::kTouchMoveEvent) {
event_type = NativeRenderViewEventType::NativeRenderViewEventTypeTouchMove;
} else if (type == hippy::kTouchEndEvent) {
event_type = NativeRenderViewEventType::NativeRenderViewEventTypeTouchEnd;
} else if (type == hippy::kTouchCancelEvent) {
event_type = NativeRenderViewEventType::NativeRenderViewEventTypeTouchCancel;
}
const std::string type_ = type;
__weak id weakSelf = self;
[view addViewEvent:event_type eventListener:^(CGPoint point,
BOOL canCapture,
BOOL canBubble,
BOOL canBePreventedInCapture,
BOOL canBePreventedInBubbling) {
OnTouchEventHandler eventListener = ^(CGPoint point,
BOOL canCapture,
BOOL canBubble,
BOOL canBePreventedInCapture,
BOOL canBePreventedInBubbling) {
id strongSelf = weakSelf;
if (strongSelf) {
[strongSelf domNodeForComponentTag:componentTag onRootNode:rootNode resultNode:^(std::shared_ptr<DomNode> node) {
Expand All @@ -1303,46 +1299,24 @@ - (void)addTouchEventListenerForType:(const std::string &)type
}
}];
}
}];
}
else {
};
if (type == hippy::kTouchStartEvent) {
[view setOnTouchDown:eventListener];
} else if (type == hippy::kTouchMoveEvent) {
[view setOnTouchMove:eventListener];
} else if (type == hippy::kTouchEndEvent) {
[view setOnTouchEnd:eventListener];
} else if (type == hippy::kTouchCancelEvent) {
[view setOnTouchCancel:eventListener];
}
}
}
- (void)addShowEventListenerForType:(const std::string &)type
forView:(int32_t)componentTag
onRootNode:(std::weak_ptr<RootNode>)rootNode {
AssertMainQueue();
auto strongRootNode = rootNode.lock();
if (!strongRootNode) {
return;
}
int32_t root_id = strongRootNode->GetId();
UIView *view = [self viewForComponentTag:@(componentTag) onRootTag:@(root_id)];
if (view) {
NativeRenderViewEventType event_type = hippy::kShowEvent == type ? NativeRenderViewEventTypeShow : NativeRenderViewEventTypeDismiss;
__weak id weakSelf = self;
std::string type_ = type;
[view addViewEvent:event_type eventListener:^(CGPoint point,
BOOL canCapture,
BOOL canBubble,
BOOL canBePreventedInCapture,
BOOL canBePreventedInBubbling) {
id strongSelf = weakSelf;
if (strongSelf) {
[strongSelf domNodeForComponentTag:componentTag onRootNode:rootNode resultNode:^(std::shared_ptr<DomNode> node) {
if (node) {
std::shared_ptr<HippyValue> domValue = std::make_shared<HippyValue>(true);
auto event = std::make_shared<DomEvent>(type_, node, canCapture, canBubble, domValue);
node->HandleEvent(event);
[strongSelf domEventDidHandle:type_ forNode:componentTag onRoot:root_id];
}
}];
}
}];
}
else {
}
// Note: not implemented
// iOS do not have these event.
}
- (void)removeEventName:(const std::string &)eventName
Expand All @@ -1352,20 +1326,9 @@ - (void)removeEventName:(const std::string &)eventName
if (!strongRootNode) {
return;
}
int32_t root_id = strongRootNode->GetId();
int32_t componentTag = node_id;
if (eventName == hippy::kClickEvent ||
eventName ==hippy::kLongClickEvent ||
eventName == hippy::kTouchStartEvent || eventName == hippy::kTouchMoveEvent ||
eventName == hippy::kTouchEndEvent || eventName == hippy::kTouchCancelEvent ||
eventName == hippy::kShowEvent || eventName == hippy::kDismissEvent ||
eventName == hippy::kPressIn || eventName == hippy::kPressOut) {
std::string name_ = eventName;
[self addUIBlock:^(HippyUIManager *uiManager, NSDictionary<NSNumber *,__kindof UIView *> *viewRegistry) {
UIView *view = [uiManager viewForComponentTag:@(componentTag) onRootTag:@(root_id)];
[view removeViewEvent:viewEventTypeFromName(name_.c_str())];
}];
} else if (eventName == kVSyncKey) {
if (eventName == kVSyncKey) {
std::string name_ = eventName;
[self domNodeForComponentTag:node_id onRootNode:rootNode resultNode:^(std::shared_ptr<DomNode> node) {
if (node) {
Expand Down Expand Up @@ -1396,7 +1359,7 @@ - (void)addPropertyEvent:(const std::string &)name forDomNode:(int32_t)node_id
return;
}
int32_t root_id = strongRootNode->GetId();
UIView *view = [self viewForComponentTag:@(node_id) onRootTag:@(root_id)];
UIView *view = [self viewForHippyTag:@(node_id) onRootTag:@(root_id)];
if (view) {
std::string name_ = name;
NSDictionary *componentDataByName = [_componentDataByName copy];
Expand Down Expand Up @@ -1521,6 +1484,15 @@ - (HippyUIManager *)uiManager {
return nil;
}
- (id<HippyCustomTouchHandlerProtocol>)customTouchHandler {
return objc_getAssociatedObject(self, @selector(customTouchHandler));
}
- (void)setCustomTouchHandler:(id<HippyCustomTouchHandlerProtocol>)customTouchHandler {
objc_setAssociatedObject(self, @selector(customTouchHandler), customTouchHandler, OBJC_ASSOCIATION_RETAIN);
}
@end
Loading

0 comments on commit 5050ebd

Please sign in to comment.