CKComponent() Category Reference
Declared in | CKComponentInternal.h CKComponentSubclass.h |
---|
Overview
A constant that indicates that the parent’s size is not yet determined in either dimension.
Other Methods
– mountInContext:size:children:supercomponent:
Mounts the component in the given context: - Stores references to the supercomponent and superview for -nextResponder and -viewConfiguration. - Creates or updates a controller for this component, if one should exist. - If this component has a view, creates or recycles a view by fetching one from the given MountContext, and: - Unmounts the view’s previous component (if any). - Applies attributes to the view. - Stores a reference to the view in _mountedView (for -viewContext, transient view state, and -unmount). - Stores a reference back to this component in view.ck_component. (This sets up a retain cycle which must be torn down in -unmount.)
- (CK : : Component : : MountResult)mountInContext:(const CK : : Component : : MountContext &)context size:(const CGSize)size children:(std : : shared_ptr<conststd::vector<CKComponentLayoutChild> >)children supercomponent:(CKComponent *)supercomponent
Parameters
context |
The component’s content should be positioned within the given view at the given position. |
---|---|
size |
The size for this component |
children |
The positioned children for this component. Normally this parameter is ignored. |
supercomponent |
This component’s parent component |
Return Value
An updated mount context. In most cases, this is just be the passed-in context. If a view was created, this is used to specify that subcomponents should be mounted inside the view.
Discussion
Override this if your component wants to perform a custom mounting action, but this should be very rare!
Declared In
CKComponentInternal.h
– unmount
Unmounts the component: - Clears the references to supercomponent and superview. - If the component has a mountedView: - Calls the unapplicator for any attributes that have one. - Clears the view’s reference back to this component in ck_component. - Clears mountedView.
- (void)unmount
Declared In
CKComponentInternal.h
– childrenDidMount
Called by the CKComponentLifecycleManager when the component and all its children have been mounted.
- (void)childrenDidMount
Declared In
CKComponentInternal.h
– viewForAnimation
Called by the animation machinery. Do not access this externally.
- (UIView *)viewForAnimation
Declared In
CKComponentInternal.h
rootComponentMountedView
Used by CKComponentLifecycleManager to get the root component in the responder chain; don’t touch this.
@property (nonatomic, weak) UIView *rootComponentMountedView
Declared In
CKComponentInternal.h
scopeFrameToken
For internal use only; don’t touch this.
@property (nonatomic, strong, readonly) id scopeFrameToken
Declared In
CKComponentInternal.h
Other Methods
+ initialState
Called to get the component’s initial state; the default implementation returns nil.
+ (id)initialState
Declared In
CKComponentSubclass.h
– layoutThatFits:parentSize:
Call this on children components to compute their layouts within your implementation of -computeLayoutThatFits:.
- (CKComponentLayout)layoutThatFits:(CKSizeRange)constrainedSize parentSize:(CGSize)parentSize
Parameters
constrainedSize |
Specifies a minimum and maximum size. The receiver must choose a size that is in this range. |
---|---|
parentSize |
The parent component’s size. If the parent component does not have a final size in a given dimension, then it should be passed as kCKComponentParentDimensionUndefined (for example, if the parent’s width depends on the child’s size). |
Return Value
A struct defining the layout of the receiver and its children.
Discussion
Warning: You may not override this method. Override -computeLayoutThatFits: instead.
Declared In
CKComponentSubclass.h
– computeLayoutThatFits:
Override this method to compute your component’s layout.
- (CKComponentLayout)computeLayoutThatFits:(CKSizeRange)constrainedSize
Parameters
constrainedSize |
A min and max size. This is computed as described in the description. The CKComponentLayout you return MUST have a size between these two sizes. This is enforced by assertion. |
---|
Discussion
Why do you need to override -computeLayoutThatFits: instead of -layoutThatFits:parentSize:? The base implementation of -layoutThatFits:parentSize: does the following for you: 1. First, it uses the parentSize parameter to resolve the component’s size (the one passed into -initWithView:size:). 2. Then, it intersects the resolved size with the constrainedSize parameter. If the two don’t intersect, constrainedSize wins. This allows a component to always override its childrens' sizes when computing its layout. (The analogy for UIView: you might return a certain size from -sizeThatFits:, but a parent view can always override that size and set your frame to any size.)
Declared In
CKComponentSubclass.h
– computeLayoutThatFits:restrictedToSize:relativeToParentSize:
CKComponent’s implementation of -layoutThatFits:parentSize: calls this method to resolve the component’s size against parentSize, intersect it with constrainedSize, and call -computeLayoutThatFits: with the result.
- (CKComponentLayout)computeLayoutThatFits:(CKSizeRange)constrainedSize restrictedToSize:(const CKComponentSize &)size relativeToParentSize:(CGSize)parentSize
Discussion
In certain advanced cases, you may want to customize this logic. Overriding this method allows you to receive all three parameters and do the computation yourself.
Warning: Overriding this method should be done VERY rarely.
Declared In
CKComponentSubclass.h
– updateState:mode:
Enqueue a change to the state.
- (void)updateState:(id ( ^ ) ( id ))updateBlock mode:(CKUpdateMode)mode
Parameters
updateBlock |
A block that takes the current state as a parameter and returns an instance of the new state. The state must be immutable since components themselves are. A possible use might be: [self updateState:^MyState (MyState currentState) { MyMutableState *nextState = [currentState mutableCopy]; [nextState setFoo:[nextState bar] * 2]; return [nextState copy]; // immutable! :D }]; |
---|---|
mode |
@see CKUpdateMode |
Declared In
CKComponentSubclass.h
– targetForAction:withSender:
Allows an action to be forwarded to another target. By default, returns the receiver if it implements action, and proceeds up the responder chain otherwise.
- (id)targetForAction:(SEL)action withSender:(id)sender
Declared In
CKComponentSubclass.h
– canPerformAction:withSender:
When an action is triggered, a component may use this method to either capture or ignore the given action. The default implementation simply uses respondsToSelector: to determine if the component can perform the given action.
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
Discussion
In practice, this is useful only for integrations with UIMenuController whose API walks the UIResponder chain to determine which menu items to display. You should not override this method for standard component actions.
Declared In
CKComponentSubclass.h
– animationsOnInitialMount
Override to return a list of animations that will be applied to the component when it is first mounted.
- (std : : vector<CKComponentAnimation>)animationsOnInitialMount
Discussion
Warning: If you override this method, your component MUST declare a scope (see CKComponentScope). This is used to identify equivalent components between trees.
Declared In
CKComponentSubclass.h
– animationsFromPreviousComponent:
Override to return a list of animations from the previous version of the same component.
- (std : : vector<CKComponentAnimation>)animationsFromPreviousComponent:(CKComponent *)previousComponent
Discussion
Warning: If you override this method, your component MUST declare a scope (see CKComponentScope). This is used to identify equivalent components between trees.
Declared In
CKComponentSubclass.h
– boundsAnimationFromPreviousComponent:
Override to return how the change to the bounds of the root component should be animated when updating the hierarchy.
- (CKComponentBoundsAnimation)boundsAnimationFromPreviousComponent:(CKComponent *)previousComponent
Discussion
Warning: If you override this method, your component MUST declare a scope (see CKComponentScope). This is used to identify equivalent components between trees.
Declared In
CKComponentSubclass.h
– controller
Returns the component’s controller, if any.
- (CKComponentController *)controller
Declared In
CKComponentSubclass.h