HUBViewController

@interface HUBViewController : UIViewController

View controller used to render a Hub Framework-powered view

You don’t create instances of this class directly. Instead, you use HUBViewControllerFactory to do so.

This view controller renders HUBComponent instances using a collection view. What components that are rendered are determined by HUBContentOperations that build a HUBViewModel.

  • The view controller’s delegate. See HUBViewControllerDelegate for more information.

    Declaration

    Objective-C

    @property (readwrite, nonatomic, nullable) id<HUBViewControllerDelegate>
        delegate;
  • The identifier of the feature that this view controller belongs to

    Declaration

    Objective-C

    @property (readonly, copy, nonatomic) NSString *_Nonnull featureIdentifier;
  • The URI that this view controller was resolved from

    Declaration

    Objective-C

    @property (readonly, copy, nonatomic) NSURL *_Nonnull viewURI;
  • The current view model that the view controller is using

    To observe whenever the view model will be updated, use the -viewController:willUpdateWithViewModel: delegate method. You can also use -viewControllerDidUpdate, which gets called once a new view model has been assigned.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable) id<HUBViewModel> viewModel;
  • Whether the view controller’s content view is currently being scrolled

    Declaration

    Objective-C

    @property (readonly, assign, nonatomic) BOOL isViewScrolling;
  • Return the frame used to render a body component at a given index

    This method guards against out of bound indexes, so it’s safe to call it with whatever index. If an out-of-bounds index was given, CGRectZero is returned.

    Declaration

    Objective-C

    - (CGRect)frameForBodyComponentAtIndex:(NSUInteger)index;

    Parameters

    index

    The index of the body component to get the frame for

  • Return the index of a body component being rendered at a given point

    Declaration

    Objective-C

    - (NSUInteger)indexOfBodyComponentAtPoint:(CGPoint)point;

    Parameters

    point

    The point of the body component to get the index of (in the view controller’s coordinate system)

    Return Value

    An index, if a body component was found at the given point, or NSNotFound.

  • Scroll to a desired content offset.

    Declaration

    Objective-C

    - (void)scrollToContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;

    Parameters

    contentOffset

    The offset which to scroll to.

    animated

    Defines if scrolling should be animated.

  • Scroll to a desired component. Each index in the index path refers to one level of children. For example, in order to scroll to a root component at an index, you would provide an index path with that single index. If that component in turn has children, you can scroll between those by providing an index path with two index, starting with the root index, and so on.

    In order for child components to support nested scrolling, they must implement @c HUBComponentWithScrolling.

    @seealso HUBComponentWithScrolling

    Declaration

    Objective-C

    - (void)scrollToComponentOfType:(HUBComponentType)componentType
                          indexPath:(nonnull NSIndexPath *)indexPath
                     scrollPosition:(HUBScrollPosition)scrollPosition
                           animated:(BOOL)animated
                         completion:
                             (void (^_Nullable)(NSIndexPath *_Nonnull))completion;

    Parameters

    componentType

    The type of component you want to scroll to.

    indexPath

    The index path of the component to scroll to.

    scrollPosition

    The preferred position of the component after scrolling.

    animated

    Whether or not the scrolling should be animated.

    completion

    A block that is called for each step of the scrolling, providing the index path of the component that became visible.

  • Returns the views of the components of the given type that are currently visible on screen, keyed by their index path

    The index paths used for keys contains the indexes for the components’ views, starting from the root. For example, a root body component at index 4 will have an index path with just the index 4, while the child at index 2 of that component will have an index path with the indexes 4 and 2.

    Note that if you are only interested in a single component’s visible view, use the API that only returns a single view instead, since it has a lot faster lookup time.

    Declaration

    Objective-C

    - (nonnull NSDictionary<NSIndexPath *, UIView *> *)
    visibleComponentViewsForComponentType:(HUBComponentType)componentType;

    Parameters

    componentType

    The type of component to check for visiblilty.

    Return Value

    A dictionary of index paths and visible views at that index path.

  • Return any currently visible view of a single component

    This method provides a fast way of looking up just a single component’s visible view, but if you’re interested in getting all currently visible component views - use visibleComponentViewsForComponentType: instead.

    Declaration

    Objective-C

    - (nullable UIView *)
    visibleViewForComponentOfType:(HUBComponentType)componentType
                        indexPath:(nonnull NSIndexPath *)indexPath;

    Parameters

    componentType

    The type of component to check for visibility.

    indexPath

    The index path of the component to check for visibility.

  • Perform a programmatic selection of a component with a given model

    Note that this method won’t actually simulate a user interaction on a component view, but rather run the exact same code that gets run whenever that happens.

    Declaration

    Objective-C

    - (BOOL)selectComponentWithModel:(nonnull id<HUBComponentModel>)componentModel
                          customData:
                              (nullable NSDictionary<NSString *, id> *)customData;

    Parameters

    componentModel

    The model of the component to select

    customData

    Any custom data to use when the selection is handled. Will be available on the HUBActionContext passed to any actions handling the selection.

    Return Value

    A boolean indicating whether selection handling was performed, that is if any target URI or action was executed as a result of the selection.

  • Cancel any ongoing component selection - including both highlights & selection

    If no component is currently being selected, this method does nothing.

    Declaration

    Objective-C

    - (void)cancelComponentSelection;
  • Reload the view model of the view controller.

    Declaration

    Objective-C

    - (void)reload;