Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Adds support for better gesture recognizer mocking #208

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

younata
Copy link
Contributor

@younata younata commented Sep 6, 2018

  • Can specify the state of the gesture recognizer when it's recognized
  • Can specify what the location in the given view being recognized is
    This requires that the recognizer be enabled for view mocking, due to method swizzling on subclasses

- Can specify the state of the gesture recognizer when it's recognized
- Can specify what the location in the given view being recognized is
  This requires that the recognizer be enabled for view mocking, due to method swizzling on subclasses
[[recognizer valueForKey:@"state"] integerValue] should equal(UIGestureRecognizerStatePossible);
context(@"with location mocking enabled", ^{
beforeEach(^{
[recognizer enableLocationInViewMocking];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not sure I like this interface. Still debating whether to do this, or to dynamically find all subclasses of UIGestureRecognizer and swizzle out their -locationInView: method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... still think it might be best to do this dynamically.

@@ -5,6 +5,11 @@ NS_ASSUME_NONNULL_BEGIN
@interface UIGestureRecognizer (Spec)

- (void)recognize;
- (void)recognizeWithState:(UIGestureRecognizerState)state NS_SWIFT_NAME(recognize(with:));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to better understand the language and DSL we're building up here, because I think this could be a really neat addition to the testing DSL that PCK exposes.

It seems like the intent of -recognizeWithState: is to say that we want to trigger -recognize, then to have our intermediate state be the one that is specified, effectively making -recognize an alias for recognizeWithState: sharedRecognitionWithState:UIGestureRecognizerStateEnded.

It sounds like that's particularly helpful with one or more unique UIGestureRecognizer subclasses. Could you share a bit more of the context so I can better understand how we can merge this into PCK ?

Also happy to carry on a conversation privately, since we're often doing that anyway outside github, you and me @younata.

It looks good I'm just trying to understand the implications of UIGestureRecognizer subclasses and this method and wondering if there are any other ways forward that might be more maintainable.

I need some more time to understand what's going on with -setLocationInView: and the enable and disable friends for this, since I've only read through the changes for -recognize so far.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. My understanding is that these UIGestureRecognizer stubs were made only with UITapGestureRecognizer in mind.

My current use case is UILongPressGestureRecognizer, which you can move around after it's recognized (hence what's going on with -setLocationInView). I had in mind the workflow of testing on UIGestureRecognizerStateBegan, then UIGestureRecognizerStateChanged, then on UIGestureRecognizerStateEnded, and/or UIGestureRecognizerStateCancelled.

But, similar deal with UISwipeGestureRecognizer, UIPanGestureRecognizer, etc. Though, for swiping, you might want to stub out -velocityInView:.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants