HUBComponentLayoutManager

@protocol HUBComponentLayoutManager <NSObject>

Protocol implemented by an object that acts as a layout manager for components in an instance of the Hub Framework

You implement this protocol in a single custom object and inject it when setting up the application’s HUBManager. The responsibility of a component layout manager is to compute margins between various components and content edges.

A layout manager is always given a set of layout traits for the component(s) in question, to be able to make good decisions on what margins to use. For more information about layout traits; see HUBComponentLayoutTrait.

  • Return the margin to use between a component with a set of layout traits and a content edge

    This method will be called by the Hub Framework when a component is about to be placed close to a content edge. See HUBComponentLayoutTrait and HUBComponentLayoutContentEdge for more information.

    Declaration

    Objective-C

    - (CGFloat)marginBetweenComponentWithLayoutTraits:
                   (nonnull NSSet<HUBComponentLayoutTrait> *)layoutTraits
                                       andContentEdge:
                                           (HUBComponentLayoutContentEdge)
                                               contentEdge;

    Parameters

    layoutTraits

    The layout traits of the component to compute a margin for

    contentEdge

    The content edge to compute the margin to

  • Return the vertical margin to use between a body component and a header component

    This method will be called by the Hub Framework when a component is about to be placed on the first row below a header component. See HUBComponentLayoutTrait for more information.

    Declaration

    Objective-C

    - (CGFloat)verticalMarginBetweenComponentWithLayoutTraits:
                   (nonnull NSSet<HUBComponentLayoutTrait> *)layoutTraits
                           andHeaderComponentWithLayoutTraits:
                               (nonnull NSSet<HUBComponentLayoutTrait> *)
                                   headerLayoutTraits;

    Parameters

    layoutTraits

    The layout traits for the body component

    headerLayoutTraits

    The layout traits for the header component

  • Return the horizontal margin to use between two body components

    The Hub Framework will only call this method once for a given component pair, so the returned value should be the absolute margin between the components, rather than a half value. See HUBComponentLayoutTrait for more information.

    Declaration

    Objective-C

    - (CGFloat)horizontalMarginForComponentWithLayoutTraits:
                   (nonnull NSSet<HUBComponentLayoutTrait> *)layoutTraits
                             precedingComponentLayoutTraits:
                                 (nonnull NSSet<HUBComponentLayoutTrait> *)
                                     precedingComponentLayoutTraits;

    Parameters

    layoutTraits

    The layout traits for the component to determine the margin for

    precedingComponentLayoutTraits

    The layout traits for the component that precedes the current one horizontally

  • Return the vertical margin to use between two body components

    The Hub Framework will only call this method once for a given component pair, so the returned value should be the absolute margin between the components, rather than a half value. See HUBComponentLayoutTrait for more information.

    Declaration

    Objective-C

    - (CGFloat)verticalMarginForComponentWithLayoutTraits:
                   (nonnull NSSet<HUBComponentLayoutTrait> *)layoutTraits
                           precedingComponentLayoutTraits:
                               (nonnull NSSet<HUBComponentLayoutTrait> *)
                                   precedingComponentLayoutTraits;

    Parameters

    layoutTraits

    The layout traits for the compone to determine the margin for

    precedingComponentLayoutTraits

    The layout traits for the component that precedes the current one vertically

  • Calculate the horizontal offset for the provided components represented by their layout traits

    Declaration

    Objective-C

    - (CGFloat)horizontalOffsetForComponentsWithLayoutTraits:
                   (nonnull NSArray<NSSet<HUBComponentLayoutTrait> *> *)
                       componentsTraits
                       firstComponentLeadingHorizontalOffset:
                           (CGFloat)firstComponentLeadingOffsetX
                       lastComponentTrailingHorizontalOffset:
                           (CGFloat)lastComponentTrailingOffsetX;

    Parameters

    componentsTraits

    An array of the sets of layout traits for all components for which the horizontal adjustment should be calculated

    firstComponentLeadingOffsetX

    The leading horizontal offset of the first component in the sequence

    lastComponentTrailingOffsetX

    The trailing horizontal offset of the last component in the sequence

    Return Value

    The value by which the horizontal origins of all components should be adjusted