From 9019233c68540cbd54a6d82ee0771f8efeaf6ca9 Mon Sep 17 00:00:00 2001 From: Brian Amerige Date: Tue, 10 Mar 2015 20:15:46 -0700 Subject: [PATCH] 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 --- AsyncDisplayKit/Details/_ASDisplayView.mm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/AsyncDisplayKit/Details/_ASDisplayView.mm b/AsyncDisplayKit/Details/_ASDisplayView.mm index f5bdb7b9..9add41a5 100644 --- a/AsyncDisplayKit/Details/_ASDisplayView.mm +++ b/AsyncDisplayKit/Details/_ASDisplayView.mm @@ -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