Lifecycle Methods Edit on GitHub
Component controllers expose lifecycle methods that allow you to perform custom operations as components mount, unmount, update, and acquire views.
Whenever possible, avoid using lifecycle methods. Think of them as an emergency escape hatch for integrating with stateful code.
Lifecycle methods have the following defined ordering.
componentDidAcquireViewif the controller’s component has a view
didMountafter the component and all of its children are mounted
Remounting occurs when the controller’s component is already mounted and either the component is being updated or the root component is being attached to a different view.
- If the controller’s component creates a view and its previous view cannot be recycled:
componentWillRelinquishViewif the controller’s component has a view
There are no guarantees that the component's children or parents are mounted in
componentWillRelinquishView. You must not use
CKComponentActionSend or any other method that assumes the component's parents are mounted.
The controller’s component can be updated to a new version of the component as part of the mounting or remounting process. In this case, you’ll receive the following callbacks:
Mutating the View
Generally views are a hidden implementation detail of ComponentKit, but you may need to break that abstraction:
- Animations that cannot be implemented using
animationsFromPreviousComponent:. Be sure you remove all animations in
- Interfacing with views that only expose event callbacks via a delegate API. Make the component controller the view’s delegate in
componentDidAcquireViewand nil out the view’s delegate in
componentWillRelinquishView implementations you may only reference the view via the component controller's `view` property. Remember, these lifecycle methods are called before the component has finished being mounted. Trying to use the component's view context will not work until the component has been mounted.