1818#import < RenderCore/RCAssert.h>
1919#import < ComponentKit/RCAssociatedObject.h>
2020#import < ComponentKit/CKCollection.h>
21+ #import < ComponentKit/CKGlobalConfig.h>
2122#import < ComponentKit/CKMutex.h>
2223
2324#import " CKComponent+UIView.h"
@@ -36,8 +37,10 @@ void CKConfigureInvocationWithArguments(NSInvocation *invocation, NSInteger inde
3637 // If we are using a scoped action, we are only concerned that the selector and the
3738 // responder unique identifier matches.
3839 && _scopedResponderAndKey.responder == rhs._scopedResponderAndKey .responder
39- && _selector == rhs._selector
40- && _block == rhs._block );
40+ && _selectorOrIdentifier == rhs._selectorOrIdentifier
41+ && ((CKReadGlobalConfig ().actionShouldCompareCustomIdentifier
42+ && _variant == CKActionVariant::BlockWithIdentifier)
43+ || _block == rhs._block ));
4144}
4245
4346CKActionSendBehavior CKActionBase::defaultBehavior () const
@@ -59,6 +62,9 @@ void CKConfigureInvocationWithArguments(NSInvocation *invocation, NSInteger inde
5962 case CKActionVariant::Block:
6063 RCCFailAssert (@" Should not be asking for target for block action." );
6164 return nil ;
65+ case CKActionVariant::BlockWithIdentifier:
66+ RCCFailAssert (@" Should not be asking for target for block action." );
67+ return nil ;
6268 }
6369}
6470
@@ -67,7 +73,7 @@ void CKConfigureInvocationWithArguments(NSInvocation *invocation, NSInteger inde
6773 _scopedResponderAndKey({}),
6874 _block(NULL ),
6975 _variant(CKActionVariant::RawSelector),
70- _selector (nullptr ) {}
76+ _selectorOrIdentifier (nullptr ) {}
7177
7278CKActionBase::CKActionBase (const CKActionBase&) = default;
7379
@@ -76,7 +82,7 @@ void CKConfigureInvocationWithArguments(NSInvocation *invocation, NSInteger inde
7682 _scopedResponderAndKey({}),
7783 _block(NULL ),
7884 _variant(CKActionVariant::TargetSelector),
79- _selector (selector) {}
85+ _selectorOrIdentifier (selector) {}
8086
8187CKActionBase::CKActionBase (const CKComponentScope &scope, SEL selector) noexcept
8288 : CKActionBase(selector, scope.node()) { }
@@ -87,7 +93,7 @@ void CKConfigureInvocationWithArguments(NSInvocation *invocation, NSInteger inde
8793 _block (NULL ),
8894
8995 _variant(CKActionVariant::Responder),
90- _selector (selector)
96+ _selectorOrIdentifier (selector)
9197{
9298 RCCAssertNotNil (node.scopeHandle , @" You are creating an action that will not fire because you have an invalid scope handle." );
9399}
@@ -97,36 +103,54 @@ void CKConfigureInvocationWithArguments(NSInvocation *invocation, NSInteger inde
97103 _scopedResponderAndKey({}),
98104 _block(NULL ),
99105 _variant(CKActionVariant::RawSelector),
100- _selector (selector) {}
106+ _selectorOrIdentifier (selector) {}
101107
102108CKActionBase::CKActionBase (dispatch_block_t block) noexcept
103109 : _target(nil ),
104110 _scopedResponderAndKey({}),
105111 _block(block),
106112 _variant(CKActionVariant::Block),
107- _selector(NULL ) {}
113+ _selectorOrIdentifier(NULL ) {}
114+
115+ CKActionBase::CKActionBase (dispatch_block_t block, void *functionPointer, CKScopedResponder *responder, CKScopedResponderKey key) noexcept
116+ : _target(nil ),
117+ _scopedResponderAndKey(CKActionBase::ScopedResponderAndKey{responder, key}),
118+ _block(block),
119+ _variant(CKActionVariant::BlockWithIdentifier),
120+ _selectorOrIdentifier(functionPointer) {};
108121
109122CKActionBase::operator bool () const noexcept {
110- return _selector != NULL || _block != NULL || _scopedResponderAndKey.responder != nil ;
123+ return _block != NULL || _selectorOrIdentifier != NULL || _scopedResponderAndKey.responder != nil ;
111124}
112125
113126CKActionBase::~CKActionBase () {}
114127
115128SEL CKActionBase::selector () const noexcept {
116- return _selector;
129+ if (_variant == CKActionVariant::BlockWithIdentifier || _variant == CKActionVariant::Block) {
130+ return nil ;
131+ }
132+ return (SEL )_selectorOrIdentifier;
117133}
118134
119135std::string CKActionBase::identifier () const noexcept
120136{
121137 switch (_variant) {
122138 case CKActionVariant::RawSelector:
123- return std::string (sel_getName (_selector )) + " -Selector" ;
139+ return std::string (sel_getName (( SEL )_selectorOrIdentifier )) + " -Selector" ;
124140 case CKActionVariant::TargetSelector:
125- return std::string (sel_getName (_selector )) + " -TargetSelector-" + std::to_string ((long )_target);
141+ return std::string (sel_getName (( SEL )_selectorOrIdentifier )) + " -TargetSelector-" + std::to_string ((long )_target);
126142 case CKActionVariant::Responder:
127- return std::string (sel_getName (_selector )) + " -Responder-" + std::to_string ((long )_scopedResponderAndKey.responder );
143+ return std::string (sel_getName (( SEL )_selectorOrIdentifier )) + " -Responder-" + std::to_string ((long )_scopedResponderAndKey.responder );
128144 case CKActionVariant::Block:
129- return std::string (sel_getName (_selector)) + " -Block-" + std::to_string ((long )_block);
145+ return " Block-" + std::to_string ((long )_block);
146+ case CKActionVariant::BlockWithIdentifier:
147+ if (CKReadGlobalConfig ().actionShouldUseCustomIdentifierInIdentifierString ) {
148+ return std::string (" BlockWithIdentifier-" ) + std::to_string ((long )_scopedResponderAndKey.responder ) +
149+ " -" + std::to_string ((long )_selectorOrIdentifier);
150+ } else {
151+ return std::string (" BlockWithIdentifier-" ) + std::to_string ((long )_scopedResponderAndKey.responder ) +
152+ " -" + std::to_string ((long )_block);
153+ }
130154 }
131155}
132156
0 commit comments