diff options
author | NicoleYarroch <nicole@livio.io> | 2019-04-02 11:24:08 -0400 |
---|---|---|
committer | NicoleYarroch <nicole@livio.io> | 2019-04-02 11:24:08 -0400 |
commit | 04fd7bbf73ed09019c03f19d2ea5bfdb08810e17 (patch) | |
tree | d0057d255623c354d17ed0707787cb05f809d704 | |
parent | be232a4bec911f9d33b01885c368b27b5d574bf3 (diff) | |
download | sdl_ios-04fd7bbf73ed09019c03f19d2ea5bfdb08810e17.tar.gz |
Single tap hit view now checked on main thread
-rw-r--r-- | SmartDeviceLink/SDLFocusableItemHitTester.h | 4 | ||||
-rw-r--r-- | SmartDeviceLink/SDLFocusableItemLocator.m | 44 | ||||
-rw-r--r-- | SmartDeviceLink/SDLTouchManager.m | 99 | ||||
-rw-r--r-- | SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m | 167 |
4 files changed, 112 insertions, 202 deletions
diff --git a/SmartDeviceLink/SDLFocusableItemHitTester.h b/SmartDeviceLink/SDLFocusableItemHitTester.h index 8a94f3714..7dd7662b4 100644 --- a/SmartDeviceLink/SDLFocusableItemHitTester.h +++ b/SmartDeviceLink/SDLFocusableItemHitTester.h @@ -11,8 +11,6 @@ NS_ASSUME_NONNULL_BEGIN -typedef void (^SDLFocusableItemHitTesterSelectedViewHandler)(UIView * __nullable selectedView); - @protocol SDLFocusableItemHitTester <NSObject> /** @@ -21,7 +19,7 @@ typedef void (^SDLFocusableItemHitTesterSelectedViewHandler)(UIView * __nullable @param point Point to check for a view @return point UIView object or nil */ -- (void)viewForPoint:(CGPoint)point selectedViewHandler:(nullable SDLFocusableItemHitTesterSelectedViewHandler)selectedViewHandler; +- (nullable UIView *)viewForPoint:(CGPoint)point; @end diff --git a/SmartDeviceLink/SDLFocusableItemLocator.m b/SmartDeviceLink/SDLFocusableItemLocator.m index 7cfe90d07..e3fb4d451 100644 --- a/SmartDeviceLink/SDLFocusableItemLocator.m +++ b/SmartDeviceLink/SDLFocusableItemLocator.m @@ -105,7 +105,7 @@ NS_ASSUME_NONNULL_BEGIN } NSMutableArray<SDLHapticRect *> *hapticRects = [[NSMutableArray alloc] init]; - + for (UIView *view in self.focusableViews) { CGPoint originOnScreen = [self.viewController.view convertPoint:view.frame.origin toView:nil]; CGRect convertedRect = {originOnScreen, view.bounds.size}; @@ -115,42 +115,30 @@ NS_ASSUME_NONNULL_BEGIN SDLHapticRect *hapticRect = [[SDLHapticRect alloc] initWithId:(UInt32)rectId rect:rect]; [hapticRects addObject:hapticRect]; } - + SDLSendHapticData* hapticRPC = [[SDLSendHapticData alloc] initWithHapticRectData:hapticRects]; [self.connectionManager sendConnectionManagerRequest:hapticRPC withResponseHandler:nil]; } #pragma mark SDLFocusableItemHitTester functions -- (void)viewForPoint:(CGPoint)point selectedViewHandler:(nullable void (^)(UIView * _Nullable))selectedViewHandler { - if (NSThread.currentThread.isMainThread) { - return [self sdl_viewForPoint:point selectedViewHandler:selectedViewHandler]; - } +- (nullable UIView *)viewForPoint:(CGPoint)point { + UIView *selectedView = nil; - dispatch_async(dispatch_get_main_queue(), ^{ - return [self sdl_viewForPoint:point selectedViewHandler:selectedViewHandler]; - }); -} - -- (void)sdl_viewForPoint:(CGPoint)point selectedViewHandler:(nullable void (^)(UIView * _Nullable))selectedViewHandler { - dispatch_async(dispatch_get_main_queue(), ^{ - UIView *selectedView = nil; - - for (UIView *view in self.focusableViews) { - //Convert the absolute location to local location and check if that falls within view boundary - CGPoint localPoint = [view convertPoint:point fromView:self.viewController.view]; - if ([view pointInside:localPoint withEvent:nil]) { - if (selectedView != nil) { - selectedView = nil; - break; - //the point has been indentified in two views. We cannot identify which with confidence. - } else { - selectedView = view; - } + for (UIView *view in self.focusableViews) { + //Convert the absolute location to local location and check if that falls within view boundary + CGPoint localPoint = [view convertPoint:point fromView:self.viewController.view]; + if ([view pointInside:localPoint withEvent:nil]) { + if (selectedView != nil) { + selectedView = nil; + break; + //the point has been indentified in two views. We cannot identify which with confidence. + } else { + selectedView = view; } } + } - return selectedViewHandler(selectedView); - }); + return selectedView; } #pragma mark notifications diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index 03c78f9c1..4788ab03a 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -227,22 +227,13 @@ static NSUInteger const MaximumNumberOfTouches = 2; self.currentPinchGesture = [[SDLPinchGesture alloc] initWithFirstTouch:self.previousTouch secondTouch:touch]; self.previousPinchDistance = self.currentPinchGesture.distance; if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:pinchDidStartInView:atCenterPoint:)]) { - if (self.hitTester) { - NSOperationQueue *currentQueue = NSOperationQueue.currentQueue; - [self.hitTester viewForPoint:self.currentPinchGesture.center selectedViewHandler:^(UIView * _Nullable selectedView) { - dispatch_async(currentQueue.underlyingQueue, ^{ - [self sdl_notifyDelegatePinchBeganAtCenterPoint:self.currentPinchGesture.center view:selectedView]; - }); - }]; - } else { - [self sdl_notifyDelegatePinchBeganAtCenterPoint:self.currentPinchGesture.center view:nil]; - } + UIView *hitView = (self.hitTester != nil) ? [self.hitTester viewForPoint:self.currentPinchGesture.center] : nil; + [self.touchEventDelegate touchManager:self pinchDidStartInView:hitView atCenterPoint:self.currentPinchGesture.center]; } } break; } } - /** * Handles a MOVE touch event sent by Core * @@ -284,16 +275,8 @@ static NSUInteger const MaximumNumberOfTouches = 2; _performingTouchType = SDLPerformingTouchTypePanningTouch; if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:panningDidStartInView:atPoint:)]) { - if (self.hitTester) { - NSOperationQueue *currentQueue = NSOperationQueue.currentQueue; - [self.hitTester viewForPoint:touch.location selectedViewHandler:^(UIView * _Nullable selectedView) { - dispatch_async(currentQueue.underlyingQueue, ^{ - [self sdl_notifyDelegatePanningDidStartInView:selectedView point:touch.location]; - }); - }]; - } else { - [self sdl_notifyDelegatePanningDidStartInView:nil point:touch.location]; - } + UIView *hitView = (self.hitTester != nil) ? [self.hitTester viewForPoint:touch.location] : nil; + [self.touchEventDelegate touchManager:self panningDidStartInView:hitView atPoint:touch.location]; } } break; case SDLPerformingTouchTypePanningTouch: { @@ -319,18 +302,9 @@ static NSUInteger const MaximumNumberOfTouches = 2; [self sdl_setMultiTouchFingerTouchForTouch:touch]; if (self.currentPinchGesture.isValid) { if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:pinchDidEndInView:atCenterPoint:)]) { - if (self.hitTester) { - NSOperationQueue *currentQueue = NSOperationQueue.currentQueue; - [self.hitTester viewForPoint:self.currentPinchGesture.center selectedViewHandler:^(UIView * _Nullable selectedView) { - dispatch_async(currentQueue.underlyingQueue, ^{ - [self sdl_notifyDelegatePinchDidEndInView:selectedView centerPoint:self.currentPinchGesture.center]; - self.currentPinchGesture = nil; - }); - }]; - } else { - [self sdl_notifyDelegatePinchDidEndInView:nil centerPoint:self.currentPinchGesture.center]; - self.currentPinchGesture = nil; - } + UIView *hitView = (self.hitTester != nil) ? [self.hitTester viewForPoint:self.currentPinchGesture.center] : nil; + [self.touchEventDelegate touchManager:self pinchDidEndInView:hitView atCenterPoint:self.currentPinchGesture.center]; + self.currentPinchGesture = nil; } else { self.currentPinchGesture = nil; } @@ -338,16 +312,8 @@ static NSUInteger const MaximumNumberOfTouches = 2; } break; case SDLPerformingTouchTypePanningTouch: { if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:panningDidEndInView:atPoint:)]) { - if (self.hitTester) { - NSOperationQueue *currentQueue = NSOperationQueue.currentQueue; - [self.hitTester viewForPoint:touch.location selectedViewHandler:^(UIView * _Nullable selectedView) { - dispatch_async(currentQueue.underlyingQueue, ^{ - [self sdl_notifyDelegatePanningDidEndInView:selectedView point:touch.location]; - }); - }]; - } else { - [self sdl_notifyDelegatePanningDidEndInView:nil point:touch.location]; - } + UIView *hitView = (self.hitTester != nil) ? [self.hitTester viewForPoint:touch.location] : nil; + [self.touchEventDelegate touchManager:self panningDidEndInView:hitView atPoint:touch.location]; } } break; case SDLPerformingTouchTypeSingleTouch: { @@ -367,16 +333,8 @@ static NSUInteger const MaximumNumberOfTouches = 2; CGPoint centerPoint = CGPointCenterOfPoints(touch.location, self.singleTapTouch.location); if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:didReceiveDoubleTapForView:atPoint:)]) { - if (self.hitTester) { - NSOperationQueue *currentQueue = NSOperationQueue.currentQueue; - [self.hitTester viewForPoint:centerPoint selectedViewHandler:^(UIView * _Nullable selectedView) { - dispatch_async(currentQueue.underlyingQueue, ^{ - [self sdl_notifyDelegateDoubleTapForView:selectedView point:centerPoint]; - }); - }]; - } else { - [self sdl_notifyDelegateDoubleTapForView:nil point:centerPoint]; - } + UIView *hitView = (self.hitTester != nil) ? [self.hitTester viewForPoint:centerPoint] : nil; + [self.touchEventDelegate touchManager:self didReceiveDoubleTapForView:hitView atPoint:centerPoint]; } } @@ -462,15 +420,8 @@ static NSUInteger const MaximumNumberOfTouches = 2; strongSelf.singleTapTouch = nil; [strongSelf sdl_cancelSingleTapTimer]; if ([strongSelf.touchEventDelegate respondsToSelector:@selector(touchManager:didReceiveSingleTapForView:atPoint:)]) { - if (strongSelf.hitTester) { - [strongSelf.hitTester viewForPoint:point selectedViewHandler:^(UIView * _Nullable selectedView) { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - [self sdl_notifyDelegateSingleTapForView:selectedView point:point]; - }); - }]; - } else { - [self sdl_notifyDelegateSingleTapForView:nil point:point]; - } + UIView *hitView = (self.hitTester != nil) ? [self.hitTester viewForPoint:point] : nil; + [strongSelf.touchEventDelegate touchManager:strongSelf didReceiveSingleTapForView:hitView atPoint:point]; } }); } @@ -486,30 +437,6 @@ static NSUInteger const MaximumNumberOfTouches = 2; self.singleTapTimer = NULL; } -- (void)sdl_notifyDelegateSingleTapForView:(nullable UIView *)view point:(CGPoint)point { - [self.touchEventDelegate touchManager:self didReceiveSingleTapForView:view atPoint:point]; -} - -- (void)sdl_notifyDelegateDoubleTapForView:(nullable UIView *)view point:(CGPoint)point { - [self.touchEventDelegate touchManager:self didReceiveDoubleTapForView:view atPoint:point]; -} - -- (void)sdl_notifyDelegatePanningDidStartInView:(nullable UIView *)view point:(CGPoint)point { - [self.touchEventDelegate touchManager:self panningDidStartInView:view atPoint:point]; -} - -- (void)sdl_notifyDelegatePanningDidEndInView:(nullable UIView *)view point:(CGPoint)point { - [self.touchEventDelegate touchManager:self panningDidEndInView:view atPoint:point]; -} - -- (void)sdl_notifyDelegatePinchBeganAtCenterPoint:(CGPoint)centerPoint view:(nullable UIView *)view { - [self.touchEventDelegate touchManager:self pinchDidStartInView:view atCenterPoint:centerPoint]; -} - -- (void)sdl_notifyDelegatePinchDidEndInView:(nullable UIView *)view centerPoint:(CGPoint)centerPoint { - [self.touchEventDelegate touchManager:self pinchDidEndInView:view atCenterPoint:centerPoint]; -} - @end NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m b/SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m index 70612c854..497870b9d 100644 --- a/SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m +++ b/SmartDeviceLinkTests/ProxySpecs/SDLHapticManagerSpec.m @@ -32,23 +32,23 @@ QuickSpecBegin(SDLHapticManagerSpec) describe(@"the haptic manager", ^{ __block UIWindow *uiWindow; __block UIViewController *uiViewController; - + __block SDLFocusableItemLocator *hapticManager; __block SDLSendHapticData* sentHapticRequest; - + __block id sdlLifecycleManager = OCMClassMock([SDLLifecycleManager class]); __block CGRect viewRect1; __block CGRect viewRect2; - + beforeEach(^{ hapticManager = nil; sentHapticRequest = nil; - + uiWindow = [[UIWindow alloc] init]; uiViewController = [[UIViewController alloc] init]; uiWindow.rootViewController = uiViewController; - + OCMExpect([[sdlLifecycleManager stub] sendConnectionManagerRequest:[OCMArg checkWithBlock:^BOOL(id value){ BOOL isFirstArg = [value isKindOfClass:[SDLSendHapticData class]]; if(isFirstArg) { @@ -75,216 +75,216 @@ describe(@"the haptic manager", ^{ expect(sentHapticRequest).to(beNil()); }); }); - + context(@"when initialized with no focusable view", ^{ beforeEach(^{ hapticManager = [[SDLFocusableItemLocator alloc] initWithViewController:uiViewController connectionManager:sdlLifecycleManager]; [hapticManager updateInterfaceLayout]; }); - + it(@"should have no focusable view", ^{ OCMVerify(sdlLifecycleManager); expect(sentHapticRequest.hapticRectData.count).to(equal(0)); }); }); - + context(@"when initialized with single view", ^{ beforeEach(^{ viewRect1 = CGRectMake(101, 101, 50, 50); UITextField *textField1 = [[UITextField alloc] initWithFrame:viewRect1]; [uiViewController.view addSubview:textField1]; - + hapticManager = [[SDLFocusableItemLocator alloc] initWithViewController:uiViewController connectionManager:sdlLifecycleManager]; hapticManager.enableHapticDataRequests = YES; [hapticManager updateInterfaceLayout]; }); - + it(@"should have one view", ^{ OCMVerify(sdlLifecycleManager); - + int expectedCount = 1; expect(sentHapticRequest.hapticRectData.count).to(equal(expectedCount)); - + if(sentHapticRequest.hapticRectData.count == expectedCount) { NSArray<SDLHapticRect *> *hapticRectData = sentHapticRequest.hapticRectData; SDLHapticRect *sdlhapticRect = hapticRectData[0]; SDLRectangle *sdlRect = sdlhapticRect.rect; - + compareRectangle(sdlRect, viewRect1); } }); }); - + context(@"when initialized with single button view", ^{ beforeEach(^{ viewRect1 = CGRectMake(101, 101, 50, 50); UIButton *button = [[UIButton alloc] initWithFrame:viewRect1]; [uiViewController.view addSubview:button]; - + hapticManager = [[SDLFocusableItemLocator alloc] initWithViewController:uiViewController connectionManager:sdlLifecycleManager]; hapticManager.enableHapticDataRequests = YES; [hapticManager updateInterfaceLayout]; }); - + it(@"should have one view", ^{ OCMVerify(sdlLifecycleManager); - + int expectedCount = 1; expect(sentHapticRequest.hapticRectData.count).to(equal(expectedCount)); - + if(sentHapticRequest.hapticRectData.count == expectedCount) { NSArray<SDLHapticRect *> *hapticRectData = sentHapticRequest.hapticRectData; SDLHapticRect *sdlhapticRect = hapticRectData[0]; SDLRectangle *sdlRect = sdlhapticRect.rect; - + compareRectangle(sdlRect, viewRect1); } }); }); - + context(@"when initialized with no views and then updated with two additional views", ^{ beforeEach(^{ hapticManager = [[SDLFocusableItemLocator alloc] initWithViewController:uiViewController connectionManager:sdlLifecycleManager]; hapticManager.enableHapticDataRequests = YES; [hapticManager updateInterfaceLayout]; - + viewRect1 = CGRectMake(101, 101, 50, 50); UITextField *textField1 = [[UITextField alloc] initWithFrame:viewRect1]; [uiViewController.view addSubview:textField1]; - + viewRect2 = CGRectMake(201, 201, 50, 50); UITextField *textField2 = [[UITextField alloc] initWithFrame:viewRect2]; [uiViewController.view addSubview:textField2]; - + [hapticManager updateInterfaceLayout]; }); - + it(@"should have two views", ^{ OCMVerify(sdlLifecycleManager); - + int expectedCount = 2; expect(sentHapticRequest.hapticRectData.count).to(equal(expectedCount)); - + if(sentHapticRequest.hapticRectData.count == expectedCount) { NSArray<SDLHapticRect *> *hapticRectData = sentHapticRequest.hapticRectData; SDLHapticRect *sdlhapticRect1 = hapticRectData[0]; SDLRectangle *sdlRect1 = sdlhapticRect1.rect; - + SDLHapticRect *sdlhapticRect2 = hapticRectData[1]; SDLRectangle *sdlRect2 = sdlhapticRect2.rect; - + compareRectangle(sdlRect1, viewRect2); compareRectangle(sdlRect2, viewRect1); } }); }); - + context(@"when initialized with nested views", ^{ beforeEach(^{ UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(101, 101, 50, 50)]; [uiViewController.view addSubview:textField]; - + viewRect1 = CGRectMake(110, 110, 10, 10); UITextField *textField1 = [[UITextField alloc] initWithFrame:viewRect1]; [textField addSubview:textField1]; - + viewRect2 = CGRectMake(130, 130, 10, 10); UITextField *textField2 = [[UITextField alloc] initWithFrame:viewRect2]; [textField addSubview:textField2]; - + hapticManager = [[SDLFocusableItemLocator alloc] initWithViewController:uiViewController connectionManager:sdlLifecycleManager]; hapticManager.enableHapticDataRequests = YES; [hapticManager updateInterfaceLayout]; }); - + it(@"should have only leaf views added", ^{ OCMVerify(sdlLifecycleManager); - + int expectedCount = 2; expect(sentHapticRequest.hapticRectData.count).to(equal(expectedCount)); - + if(sentHapticRequest.hapticRectData.count == expectedCount) { NSArray<SDLHapticRect *> *hapticRectData = sentHapticRequest.hapticRectData; SDLHapticRect *sdlhapticRect1 = hapticRectData[0]; SDLRectangle *sdlRect1 = sdlhapticRect1.rect; - + SDLHapticRect *sdlhapticRect2 = hapticRectData[1]; SDLRectangle *sdlRect2 = sdlhapticRect2.rect; - + compareRectangle(sdlRect1, viewRect1); compareRectangle(sdlRect2, viewRect2); } }); }); - + context(@"when initialized with nested button views", ^{ beforeEach(^{ UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(101, 101, 50, 50)]; [uiViewController.view addSubview:button]; - + viewRect1 = CGRectMake(110, 110, 10, 10); UIButton *button1 = [[UIButton alloc] initWithFrame:viewRect1]; [button addSubview:button1]; - + viewRect2 = CGRectMake(130, 130, 10, 10); UITextField *textField2 = [[UITextField alloc] initWithFrame:viewRect2]; [button addSubview:textField2]; - + hapticManager = [[SDLFocusableItemLocator alloc] initWithViewController:uiViewController connectionManager:sdlLifecycleManager]; hapticManager.enableHapticDataRequests = YES; [hapticManager updateInterfaceLayout]; }); - + it(@"should have only leaf views added", ^{ OCMVerify(sdlLifecycleManager); - + int expectedCount = 2; expect(sentHapticRequest.hapticRectData.count).to(equal(expectedCount)); - + if(sentHapticRequest.hapticRectData.count == expectedCount) { NSArray<SDLHapticRect *> *hapticRectData = sentHapticRequest.hapticRectData; SDLHapticRect *sdlhapticRect1 = hapticRectData[0]; SDLRectangle *sdlRect1 = sdlhapticRect1.rect; - + SDLHapticRect *sdlhapticRect2 = hapticRectData[1]; SDLRectangle *sdlRect2 = sdlhapticRect2.rect; - + compareRectangle(sdlRect1, viewRect1); compareRectangle(sdlRect2, viewRect2); } }); }); - + context(@"when initialized with two views and then updated with one view removed", ^{ beforeEach(^{ viewRect1 = CGRectMake(101, 101, 50, 50); UITextField *textField1 = [[UITextField alloc] initWithFrame:viewRect1]; [uiViewController.view addSubview:textField1]; - + viewRect2 = CGRectMake(201, 201, 50, 50); UITextField *textField2 = [[UITextField alloc] initWithFrame:viewRect2]; [uiViewController.view addSubview:textField2]; - + hapticManager = [[SDLFocusableItemLocator alloc] initWithViewController:uiViewController connectionManager:sdlLifecycleManager]; hapticManager.enableHapticDataRequests = YES; [hapticManager updateInterfaceLayout]; - + [textField2 removeFromSuperview]; - + [hapticManager updateInterfaceLayout]; }); - + it(@"should have one view", ^{ OCMVerify(sdlLifecycleManager); - + int expectedCount = 1; expect(sentHapticRequest.hapticRectData.count).to(equal(expectedCount)); - + if(sentHapticRequest.hapticRectData.count == expectedCount) { NSArray<SDLHapticRect *> *hapticRectData = sentHapticRequest.hapticRectData; SDLHapticRect *sdlhapticRect = hapticRectData[0]; SDLRectangle *sdlRect = sdlhapticRect.rect; - + compareRectangle(sdlRect, viewRect1); } }); @@ -295,96 +295,93 @@ describe(@"the haptic manager", ^{ viewRect1 = CGRectMake(101, 101, 50, 50); UITextField *textField1 = [[UITextField alloc] initWithFrame:viewRect1]; [uiViewController.view addSubview:textField1]; - + hapticManager = [[SDLFocusableItemLocator alloc] initWithViewController:uiViewController connectionManager:sdlLifecycleManager]; hapticManager.enableHapticDataRequests = YES; [hapticManager updateInterfaceLayout]; - + viewRect2 = CGRectMake(201, 201, 50, 50); UITextField *textField2 = [[UITextField alloc] initWithFrame:viewRect2]; [uiViewController.view addSubview:textField2]; - + [[NSNotificationCenter defaultCenter] postNotificationName:SDLDidUpdateProjectionView object:nil]; }); - + it(@"should have two views", ^{ OCMVerify(sdlLifecycleManager); - + int expectedCount = 2; expect(sentHapticRequest.hapticRectData.count).to(equal(expectedCount)); - + if(sentHapticRequest.hapticRectData.count == expectedCount) { NSArray<SDLHapticRect *> *hapticRectData = sentHapticRequest.hapticRectData; SDLHapticRect *sdlhapticRect1 = hapticRectData[0]; SDLRectangle *sdlRect1 = sdlhapticRect1.rect; - + SDLHapticRect *sdlhapticRect2 = hapticRectData[1]; SDLRectangle *sdlRect2 = sdlhapticRect2.rect; - + compareRectangle(sdlRect1, viewRect2); compareRectangle(sdlRect2, viewRect1); } }); }); - + context(@"when touched inside a view", ^{ beforeEach(^{ UITextField *textField1 = [[UITextField alloc] initWithFrame:CGRectMake(101, 101, 50, 50)]; [uiViewController.view addSubview:textField1]; - + UITextField *textField2 = [[UITextField alloc] initWithFrame:CGRectMake(201, 201, 50, 50)]; [uiViewController.view addSubview:textField2]; - + hapticManager = [[SDLFocusableItemLocator alloc] initWithViewController:uiViewController connectionManager:sdlLifecycleManager]; hapticManager.enableHapticDataRequests = YES; [hapticManager updateInterfaceLayout]; }); - + it(@"should return a view object", ^{ - [hapticManager viewForPoint:CGPointMake(125, 120) selectedViewHandler:^(UIView * _Nullable selectedView) { - expect(selectedView).toNot(beNil()); - }]; + UIView *view1 = [hapticManager viewForPoint:CGPointMake(125, 120)]; + expect(view1).toNot(beNil()); - [hapticManager viewForPoint:CGPointMake(202, 249) selectedViewHandler:^(UIView * _Nullable selectedView) { - expect(selectedView).toNot(beNil()); - }]; + UIView* view2 = [hapticManager viewForPoint:CGPointMake(202, 249)]; + expect(view2).toNot(beNil()); }); }); - + context(@"when touched in overlapping views' area", ^{ beforeEach(^{ UITextField *textField1 = [[UITextField alloc] initWithFrame:CGRectMake(101, 101, 50, 50)]; [uiViewController.view addSubview:textField1]; - + UITextField *textField2 = [[UITextField alloc] initWithFrame:CGRectMake(126, 126, 50, 50)]; [uiViewController.view addSubview:textField2]; - + hapticManager = [[SDLFocusableItemLocator alloc] initWithViewController:uiViewController connectionManager:sdlLifecycleManager]; hapticManager.enableHapticDataRequests = YES; [hapticManager updateInterfaceLayout]; }); - + it(@"should return no view object", ^{ - [hapticManager viewForPoint:CGPointMake(130, 130) selectedViewHandler:^(UIView * _Nullable selectedView) { - expect(selectedView).to(beNil()); - }]; + UIView* view = [hapticManager viewForPoint:CGPointMake(130, 130)]; + expect(view).to(beNil()); }); }); - + context(@"when touched outside view boundary", ^{ beforeEach(^{ UITextField *textField1 = [[UITextField alloc] initWithFrame:CGRectMake(101, 101, 50, 50)]; [uiWindow insertSubview:textField1 aboveSubview:uiWindow]; - + hapticManager = [[SDLFocusableItemLocator alloc] initWithViewController:uiViewController connectionManager:sdlLifecycleManager]; hapticManager.enableHapticDataRequests = YES; [hapticManager updateInterfaceLayout]; }); it(@"should return nil", ^{ - [hapticManager viewForPoint:CGPointMake(0, 228) selectedViewHandler:^(UIView * _Nullable selectedView) { - expect(selectedView).to(beNil()); - }]; + UIView* view = [hapticManager viewForPoint:CGPointMake(0, 228)]; + expect(view).to(beNil()); }); + }); }); |