Comments (4)
I have got the the answer, but i don't know if it's the best practice.
while the ParentComponent can reference the ChildComponent by the property nextResponder of sender. sender.nextResponder just point the ChildComponent
- (void)someAction:(CKComponent *)sender
{
[sender.nextResponder updateState:^id(id) {
return newState;
}];
}
from componentkit.
Use two different actions:
@implementation ParentComponent
+ (instancetype)new
{
return [super newWithComponent:
[ChildComponent
newWithAction:@selector(someAction:)]];
}
- (void)someAction:(CKComponent *)sender
{
// Do something
}
@end
@implementation ChildComponent
{
CKComponentAction _action;
}
+ (instancetype)newWithAction:(CKComponentAction)action
{
ChildComponent *c =
[super newWithComponent:
[CKButtonComponent
newWithAction:@selector(buttonAction)]];
if (c) {
c->_action = action;
}
return c;
}
- (void)buttonAction
{
CKComponentActionSend(_action, self);
}
@end
from componentkit.
Since I just spent some time figuring this out, I might as well share the insight: This only seems to work if the child component has a custom ComponentController
implementation (which can be completely empty!). Otherwise, I get an exception:
'NSInternalInconsistencyException', reason: 'Unhandled component action myAction: following responder chain <MyComponent: 0x7feeab1e81e0> -> nil'
I can't judge if this is a bug or as designed ;)
Edit: it turns out, this is only the case if you do an updateState
before calling the passed action.
from componentkit.
@leoschweizer It works ok for me . By the way do your child component hold it's own state? if the component has no state, but you call the [childComponent updateState]. It will crash . You can review the doc http://componentkit.org/docs/state.html
from componentkit.
Related Issues (20)
- Component not release
- [Documentation] Views path is not render HOT 3
- Delete 'Carthage/Checkouts' directory
- question - docs (docusaurus) repo? HOT 2
- Xcode not building ComponentKit checked out via cocoapods HOT 2
- Docusaurus source code
- question: My component is not getting full width in screen landscape mode. HOT 1
- Not Support Incremental mount
- Build Error with "RenderCoreLayoutCaching" HOT 1
- ComponentKit does not compile with Xcode 12.5 HOT 1
- Compile Error: Block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior HOT 1
- How do I pass multiple arguments
- Unsupported Swift Version: “FBSnapshotTestCase iOS” contains source code developed with Swift 3.x.
- [Question]How to unmount components from HostingView?
- How to make children component height equal to Scroll component's content view height but Scroll component's height HOT 2
- Yoga-internal.h:135:11: error: definition of implicit copy constructor for 'Values<9>' is deprecated
- CKNonNull.h:47:33 No member named 'move' in namespace 'std'; did you mean 'modf'?
- Abandoned?
- ComponentKit/ComponentKit.xcconfig is compiled as source code
- Unable to compile example project
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from componentkit.