mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-04-11 17:44:12 +08:00
Support Forwarding Responder-Chain Actions to Node from its View
Summary: What it says on the tin. This allows Nodes to effectively participate in the responder chain. Caveat: see note in implementation below. Would have been nice to use `-targetForAction:withSender:` the way the docs imply you can, but alas. Test Plan: Observe a node in the responder chain get invoked to handle an action it implements. Reviewers: bcunning, zsh, sma, jpasqualini, suv, nyn531, b3ll, aaronpang, kimon, grp, jonathan, rnystrom, nadi Reviewed By: nadi Subscribers: trunkagent, rnystrom Differential Revision: https://phabricator.fb.com/D1894023 Signature: t1:1894023:1426026643:203945b6a7c318f6d2c9b94d876da61da31327bd
This commit is contained in:
@@ -236,4 +236,18 @@
|
||||
[_node tintColorDidChange];
|
||||
}
|
||||
|
||||
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
|
||||
{
|
||||
// We forward responder-chain actions to our node if we can't handle them ourselves. See -targetForAction:withSender:.
|
||||
return ([super canPerformAction:action withSender:sender] || [_node respondsToSelector:action]);
|
||||
}
|
||||
|
||||
- (id)forwardingTargetForSelector:(SEL)aSelector
|
||||
{
|
||||
// Ideally, we would implement -targetForAction:withSender: and simply return the node where we don't respond personally.
|
||||
// Unfortunately UIResponder's default implementation of -targetForAction:withSender: doesn't follow its own documentation. It doesn't call -targetForAction:withSender: up the responder chain when -canPerformAction:withSender: fails, but instead merely calls -canPerformAction:withSender: on itself and then up the chain. rdar://20111500.
|
||||
// Consequently, to forward responder-chain actions to our node, we override -canPerformAction:withSender: (used by the chain) to indicate support for responder chain-driven actions that our node supports, and then provide the node as a forwarding target here.
|
||||
return _node;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user