in ComponentKit/Core/ComponentBuilder.h [35:131]
class __attribute__((__may_alias__)) BuilderBase {
CK::ComponentSpecContext _context;
id _key;
NS_RETURNS_RETAINED auto _buildComponentWithTransitionsIfNeeded() noexcept -> CKComponent *
{
const auto component = static_cast<Derived<PropsBitmap> &>(*this)._build();
if (PropBitmap::isSet(PropsBitmap, BuilderBasePropId::transitions)) {
return CKComponentWithTransitions(component, _transitions);
} else {
return component;
}
}
protected:
BuilderBase() = default;
BuilderBase(const CK::ComponentSpecContext& context) : _context(context) { }
public:
BuilderBase(const BuilderBase&) = default;
/**
Creates a new component instance and optionally wrap it with an animation component.
@note This method must @b not be called more than once on a given component builder instance.
*/
NS_RETURNS_RETAINED auto build() noexcept -> CKComponent *
{
const auto component = _buildComponentWithTransitionsIfNeeded();
if (PropBitmap::isSet(PropsBitmap, BuilderBasePropId::key)) {
_context.declareKey(_key, component);
}
if (_aggregatedAttributes != CKAccessibilityAggregatedAttributeNone) {
return CKComponentWithAccessibilityAggregationWrapper(component, _aggregatedAttributes);
}
return component;
}
/**
Specifies the key for the component. This key is only meant to be used from specs.
@note Calling this method on a builder that wasn't created with a context will trigger a compilation error.
@param key The key to reference the component built.
*/
auto &key(CK::RelaxedNonNull<id> key)
{
constexpr auto contextIsSet =
PropBitmap::isSet(PropsBitmap, BuilderBasePropId::context);
static_assert(contextIsSet, "Cannot set 'key' without specifying 'context'");
_key = key;
// `this` pointer needs adjustment since `BuilderBase` is not the first base class of `ComponentBuilderBase`
return reinterpret_cast<Derived<PropsBitmap | BuilderBasePropId::key> &>(*static_cast<Derived<PropsBitmap> *>(this));
}
/**
Specifies the animation on initial mount.
@param animationInitial The animation to trigger on initial mount.
*/
auto &animationInitial(CK::Animation::Initial animationInitial)
{
_transitions.onInitialMount = std::move(animationInitial);
// `this` pointer needs adjustment since `BuilderBase` is not the first base class of `ComponentBuilderBase`
return reinterpret_cast<Derived<PropsBitmap | BuilderBasePropId::transitions> &>(*static_cast<Derived<PropsBitmap> *>(this));
}
/**
Specifies the animation on final unmount.
@param animationFinal The animation to trigger on final unmount.
*/
auto &animationFinal(CK::Animation::Final animationFinal)
{
_transitions.onFinalUnmount = std::move(animationFinal);
// `this` pointer needs adjustment since `BuilderBase` is not the first base class of `ComponentBuilderBase`
return reinterpret_cast<Derived<PropsBitmap | BuilderBasePropId::transitions> &>(*static_cast<Derived<PropsBitmap> *>(this));
}
/**
Specifies what accessibility attributes will be aggregated.
@param attributes A OR-ed list of attributes that will be aggregated by this component.
*/
auto &accessibilityAggregateAttributes(CKAccessibilityAggregatedAttributes attributes = CKAccessibilityAggregatedAttributesAll)
{
_aggregatedAttributes = attributes;
return reinterpret_cast<Derived<PropsBitmap> &>(*this);
}
private:
CKTransitions _transitions;
CKAccessibilityAggregatedAttributes _aggregatedAttributes = CKAccessibilityAggregatedAttributeNone;
};