mirror of
https://github.com/Tencent/Hippy.git
synced 2026-10-24 10:10:02 +08:00
fix(ios): fix pressin and pressout bugs
This commit is contained in:
@@ -14,6 +14,8 @@ constexpr char kLongClickEvent[] = "longclick";
|
||||
constexpr char kTouchStartEvent[] = "touchstart";
|
||||
constexpr char kTouchMoveEvent[] = "tourchmove";
|
||||
constexpr char kTouchEndEvent[] = "touchend";
|
||||
constexpr char kPressIn[] = "pressin";
|
||||
constexpr char kPressOut[] = "pressout";
|
||||
constexpr char kTouchCancelEvent[] = "touchcancel";
|
||||
constexpr char kLayoutEvent[] = "layout";
|
||||
constexpr char kShowEvent[] = "show";
|
||||
|
||||
@@ -79,6 +79,8 @@ typedef NS_ENUM(NSUInteger, HippyBridgeFields) {
|
||||
HippyDisplayLink *_displayLink;
|
||||
NSDictionary *_dimDic;
|
||||
HippyDevManager *_devManager;
|
||||
std::shared_ptr<hippy::DomManager> _domManager;
|
||||
std::shared_ptr<NativeRenderManager> _nativeRenderManager;
|
||||
}
|
||||
|
||||
@synthesize flowID = _flowID;
|
||||
@@ -755,11 +757,11 @@ HIPPY_NOT_IMPLEMENTED(-(instancetype)initWithBundleURL
|
||||
HippyUIManager *uiManager = [self moduleForName:@"UIManager"];
|
||||
UIView *rootView = [[notification userInfo] objectForKey:HippyUIManagerRootViewKey];
|
||||
int32_t rootTag = [[rootView hippyTag] intValue];
|
||||
std::shared_ptr<hippy::DomManager> domManager = std::make_shared<hippy::DomManager>(rootTag);
|
||||
domManager->SetRootSize(CGRectGetWidth(rootView.bounds), CGRectGetHeight(rootView.bounds));
|
||||
std::shared_ptr<NativeRenderManager> nativeRenderManager = std::make_shared<NativeRenderManager>(uiManager);
|
||||
domManager->SetRenderManager(nativeRenderManager);
|
||||
self.javaScriptExecutor.pScope->SetDomManager(domManager);
|
||||
_domManager = std::make_shared<hippy::DomManager>(rootTag);
|
||||
_domManager->SetRootSize(CGRectGetWidth(rootView.bounds), CGRectGetHeight(rootView.bounds));
|
||||
_nativeRenderManager = std::make_shared<NativeRenderManager>(uiManager);
|
||||
_domManager->SetRenderManager(_nativeRenderManager);
|
||||
self.javaScriptExecutor.pScope->SetDomManager(_domManager);
|
||||
}
|
||||
|
||||
#pragma mark - HippyInvalidating
|
||||
|
||||
@@ -212,9 +212,11 @@ typedef void (^ViewBlock)(UIView *view, BOOL *stop);
|
||||
|
||||
if (result[@"onPressOut"][@"view"]) {
|
||||
UIView *pressOutView = result[@"onPressOut"][@"view"];
|
||||
if (pressOutView == _onPressInView && pressOutView.onPressOut) {
|
||||
onTouchEventListener listener = [_onLongClickView eventListenerForEventType:HippyViewEventTypePressOut];
|
||||
if (pressOutView == _onPressInView && listener) {
|
||||
if ([self checkViewBelongToTouchHandler:pressOutView]) {
|
||||
pressOutView.onPressOut(@{});
|
||||
// pressOutView.onPressOut(@{});
|
||||
listener(CGPointZero);
|
||||
_onPressInView = nil;
|
||||
_bPressIn = NO;
|
||||
}
|
||||
@@ -279,9 +281,11 @@ typedef void (^ViewBlock)(UIView *view, BOOL *stop);
|
||||
|
||||
if (result[@"onPressOut"][@"view"]) {
|
||||
UIView *pressOutView = result[@"onPressOut"][@"view"];
|
||||
if (pressOutView == _onPressInView && pressOutView.onPressOut) {
|
||||
onTouchEventListener listener = [_onLongClickView eventListenerForEventType:HippyViewEventTypePressOut];
|
||||
if (pressOutView == _onPressInView && listener) {
|
||||
if ([self checkViewBelongToTouchHandler:pressOutView]) {
|
||||
pressOutView.onPressOut(@{});
|
||||
// pressOutView.onPressOut(@{});
|
||||
listener(CGPointZero);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -384,9 +388,11 @@ typedef void (^ViewBlock)(UIView *view, BOOL *stop);
|
||||
|
||||
- (void)scheduleTimer:(__unused NSTimer *)timer {
|
||||
if (!_bPressIn) {
|
||||
onTouchEventListener listener = [_onLongClickView eventListenerForEventType:HippyViewEventTypePressIn];
|
||||
if (_onPressInView && _onPressInView.onPressIn) {
|
||||
if ([self checkViewBelongToTouchHandler:_onPressInView]) {
|
||||
_onPressInView.onPressIn(@{});
|
||||
// _onPressInView.onPressIn(@{});
|
||||
listener(CGPointZero);
|
||||
}
|
||||
}
|
||||
_bPressIn = YES;
|
||||
@@ -453,19 +459,19 @@ typedef void (^ViewBlock)(UIView *view, BOOL *stop);
|
||||
if ((touchInterceptEvent && findActions.count == 0) || [view isKindOfClass:NSClassFromString(@"HippyRootContentView")]) {
|
||||
break;
|
||||
} else {
|
||||
|
||||
if ([findActions containsObject:@"onPressIn"] && view.onPressIn) {
|
||||
onTouchEventListener listener = [view eventListenerForEventType:HippyViewEventTypePressIn];
|
||||
if ([findActions containsObject:@"onPressIn"] && listener) {
|
||||
if (!result[@"onClick"]) {
|
||||
[result setValue:@{ @"view": view, @"index": @(index) } forKey:@"onPressIn"];
|
||||
}
|
||||
[findActions removeObject:@"onPressIn"];
|
||||
}
|
||||
|
||||
if ([findActions containsObject:@"onPressOut"] && view.onPressOut) {
|
||||
listener = [view eventListenerForEventType:HippyViewEventTypePressOut];
|
||||
if ([findActions containsObject:@"onPressOut"] && listener) {
|
||||
[result setValue:@{ @"view": view, @"index": @(index) } forKey:@"onPressOut"];
|
||||
[findActions removeObject:@"onPressOut"];
|
||||
}
|
||||
onTouchEventListener listener = [view eventListenerForEventType:HippyViewEventTypeClick];
|
||||
listener = [view eventListenerForEventType:HippyViewEventTypeClick];
|
||||
if ([findActions containsObject:@"onClick"] && listener) {
|
||||
if (![view interceptTouchEvent]) {
|
||||
[result setValue:@{ @"view": view, @"index": @(index) } forKey:@"onClick"];
|
||||
@@ -555,9 +561,11 @@ typedef void (^ViewBlock)(UIView *view, BOOL *stop);
|
||||
- (void)cancelTouch {
|
||||
if (_onPressInView) {
|
||||
_bPressIn = NO;
|
||||
if (_onPressInView.onPressOut) {
|
||||
onTouchEventListener listener = [_onLongClickView eventListenerForEventType:HippyViewEventTypePressOut];
|
||||
if (listener) {
|
||||
if ([self checkViewBelongToTouchHandler:_onPressInView]) {
|
||||
_onPressInView.onPressOut(@{});
|
||||
// _onPressInView.onPressOut(@{});
|
||||
listener(CGPointZero);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -578,9 +586,11 @@ typedef void (^ViewBlock)(UIView *view, BOOL *stop);
|
||||
|
||||
if (_onPressInView) {
|
||||
_bPressIn = NO;
|
||||
if (_onPressInView.onPressOut) {
|
||||
onTouchEventListener listener = [_onLongClickView eventListenerForEventType:HippyViewEventTypePressOut];
|
||||
if (listener) {
|
||||
if ([self checkViewBelongToTouchHandler:_onPressInView]) {
|
||||
_onPressInView.onPressOut(@{});
|
||||
// _onPressInView.onPressOut(@{});
|
||||
listener(CGPointZero);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,6 +141,9 @@ typedef NS_ENUM(NSInteger, HippyViewEventType) {
|
||||
HippyViewEventTypeTouchEnd,
|
||||
HippyViewEventTypeTouchCancel,
|
||||
|
||||
HippyViewEventTypePressIn,
|
||||
HippyViewEventTypePressOut,
|
||||
|
||||
HippyViewEventTypeLayout,
|
||||
|
||||
//show event
|
||||
|
||||
@@ -1789,6 +1789,21 @@ static UIView *_jsResponder;
|
||||
}
|
||||
}
|
||||
|
||||
- (void) addPressEventListenerforNode:(std::weak_ptr<DomNode>)weak_node
|
||||
forType:(std::string)type
|
||||
forView:(int32_t)hippyTag {
|
||||
UIView *view = [self viewForHippyTag:@(hippyTag)];
|
||||
HippyViewEventType eventType = hippy::kPressIn == type ? HippyViewEventType::HippyViewEventTypePressIn : HippyViewEventType::HippyViewEventTypePressOut;
|
||||
if (view) {
|
||||
[view addViewEvent:eventType eventListener:^(CGPoint) {
|
||||
std::shared_ptr<DomNode> node = weak_node.lock();
|
||||
if (node) {
|
||||
node->HandleEvent(std::make_shared<hippy::DomEvent>(hippy::kClickEvent, weak_node, nullptr));
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) addTouchEventListenerforNode:(std::weak_ptr<DomNode>)weak_node
|
||||
forType:(std::string)type
|
||||
forView:(int32_t)hippyTag {
|
||||
|
||||
Reference in New Issue
Block a user