Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIPanGestureRecognizer in Texture/AsyncDisplayKit's ASCellNode prevents the table from scrolling when implementing swipe to perform action type behaviour #2074

Open
Pranoy1c opened this issue Jan 19, 2023 · 1 comment

Comments

@Pranoy1c
Copy link

I am using the Texture/AsyncDisplayKit library:

https://github.com/texturegroup/texture

I am trying to implement "swipe to perform action" in a ASCellNode. The problem is that the UIPanGestureRecognizer prevents the table from scrolling.

I am able to successfully get this to work in UIKit using UITableViewCell but for some reason it's not working when using Texture's ASCellNode. I can demonstrate the issue easily with the ASDKgram example provided with this library which has both a UIKit example in one tab and Texture example in another tab:

https://github.com/TextureGroup/Texture/tree/master/examples/ASDKgram

For the UIKit example, all I had to do was:

Add <UIGestureRecognizerDelegate> to PhotoTableViewCell.h

Add UIPanGestureRecognizer *_panGestureRecognizer; in the @implementation PhotoTableViewCell

Add following to the - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier:

_panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panned:)];
_panGestureRecognizer.delegate = self;
[self.contentView addGestureRecognizer:_panGestureRecognizer];

Add following:

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
  if (gestureRecognizer == _panGestureRecognizer) {
    CGPoint v = [_panGestureRecognizer velocityInView:_panGestureRecognizer.view];
    return fabs(v.x) > fabs(v.y);
  }
  return false;
}

-(void)panned:(UIPanGestureRecognizer *)sender{
  NSLog(@"Panned!");
}

This was enough to get it to print Panned! when panning horizontally and also let the UITableView scroll when it's vertical direction.

The same does not work for the PhotoCellNode. I did the following:

Add <UIGestureRecognizerDelegate> to PhotoCellNode.h

Add UIPanGestureRecognizer *_panGestureRecognizer; in the @implementation PhotoCellNode

Add following to the PhotoCellNode.m:

- (void)didLoad {
  [super didLoad];
  _panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panned:)];
  _panGestureRecognizer.delegate = self;
  [self.view addGestureRecognizer:_panGestureRecognizer];
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
  if (gestureRecognizer == _panGestureRecognizer) {
    CGPoint v = [_panGestureRecognizer velocityInView:_panGestureRecognizer.view];
    return fabs(v.x) > fabs(v.y);
  }
  return false;
}

-(void)panned:(UIPanGestureRecognizer *)sender{
  NSLog(@"Panned!");
}

This allows Panned! to print when panning horizontally but the table does not scroll at all. Why are they working differently? How can I make the table scroll when the touches are vertical?

@Pranoy1c Pranoy1c changed the title UIPanGestureRecognizer in Texture/AsyncDisplayKit's ASCellNode prevents the table from scrolling UIPanGestureRecognizer in Texture/AsyncDisplayKit's ASCellNode prevents the table from scrolling when implementing swipe to perform action type behaviour Jan 20, 2023
@Pranoy1c
Copy link
Author

I was able to solve it. Though I am not sure why the behavior is different between the UITableViewCell and ASCellNode. @appleguy can you help point out why the difference?

In the PhotoCellNode.m, I returned [super gestureRecognizerShouldBegin:gestureRecognizer] in gestureRecognizerShouldBegin and I also added the shouldRecognizeSimultaneouslyWithGestureRecognizer function:

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
  if (gestureRecognizer == _panGestureRecognizer) {
    CGPoint v = [_panGestureRecognizer velocityInView:_panGestureRecognizer.view];
    return fabs(v.x) > fabs(v.y);
  }
  return [super gestureRecognizerShouldBegin:gestureRecognizer];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
  return false;
}

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

No branches or pull requests

1 participant