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

Question - How to set a component's controller as a delegate for a gesture created using view attributes CKComponentPanGestureAttribute #103

Closed
avnerbarr opened this issue Apr 12, 2015 · 3 comments
Labels

Comments

@avnerbarr
Copy link
Contributor

Reading up on component controllers -

It makes sense that any delegation related to the component should be handled in the component controller.
I would like to implement UIGestureRecognizerDelegate in the controller, but since I am creating the CKComponentPanGestureAttribute in the component +new method, how this is done isn't to obvious just by reading the documentation on component controllers.

For instance the following case creating a text component which has a pan attached to it:

CKTextComponent *text = [CKTextComponent newWithTextAttributes:{
        .attributedString = [attString copy],
        .truncationAttributedString = [NSAttributedString moreAttributedString],
        .maximumNumberOfLines = static_cast<NSUInteger>([state boolValue] ? 0 : 4)
    }viewAttributes:{
        {@selector(setBackgroundColor:),[UIColor clearColor]},
        {CKComponentActionAttribute(@selector(didTapContinueReading))},
        {CKComponentPanGestureAttribute(@selector(didPan:gesture:))} // I've implemented this method in the controller class
// How do I set the delegate of the yet to be created pan gesture?
    }accessibilityContext:{

    }];

Furthermore, since the components model should be immutable , it wouldn't make sense for the controller to "kidnap" the gesture recognizer in the lifecycle methods (such as - (void)didMount)

What am I missing?

@kastiglione
Copy link
Contributor

Some might consider this to be too much "magic", but perhaps when the component controller implements UIGestureRecognizer, the functions provided by CKComponentGestureActions.h could automatically assign the controller as the delegate.

For now though, I'm not sure if there's a better alternative besides ditching CKComponentPanGestureAttribute, and instead handling the construction and delegate assignment of the gesture recognizer inside a component controller.

- (void)componentDidAcquireView
{
  [super componentDidAcquireView];
  _panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(didPan:gesture:)];
  _panRecognizer.delegate = self;
  [self.view addGestureRecognizer:_panRecognizer];
}

- (void)componentWillRelinquishView
{
  [super componentWillRelinquishView];
  [self.view removeGestureRecognizer:_panRecognizer];
}

@darknoon
Copy link
Contributor

darknoon commented Aug 4, 2015

You should need to do nothing to make this work.

While the controller isn't the delegate of the gesture, it is on the responder chain for the gesture. So, you should just implement -didPan:gesture: in your controller and boom.

Re-open the issue if you still have questions.

@darknoon darknoon closed this as completed Aug 4, 2015
@ghost
Copy link

ghost commented Aug 4, 2015

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

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

No branches or pull requests

4 participants