ViewFactory

@objcMembers open class ViewFactory: NSObject

Handles the creation of recyclable views.

  • Initializes the view factory, and registers the default Layout/View relationships

    Declaration

    Swift

    public override init()
  • Returns a recycled or new LayoutView instance assigned to the given layout.

    Throws

    BlocklyError: Thrown if no LayoutView could be retrieved for the given layout.

    Declaration

    Swift

    open func makeView(layout: Layout) throws -> LayoutView

    Return Value

    A LayoutView with the given layout assigned to it

  • Registers the type of LayoutView instances that should be created when requesting a specific Layout type.

    Declaration

    Swift

    open func registerLayoutType(_ layoutType: Layout.Type, withViewType viewType: LayoutView.Type)
  • If a recycled view is available for re-use, that view is returned. If not, a new view of the given type is instantiated.

    Note

    Views obtained through this method should be recycled through recycleView(:) or recycleViewTree(:).

    Declaration

    Swift

    open func view<T>(forType type: T.Type) -> T where T: UIView

    Return Value

    An object of the given type.

  • If the view conforms to the protocol Recyclable, calls recycle() on the view and stores it for re-use later. Otherwise, nothing happens.

    Declaration

    Swift

    open func recycleView(_ view: UIView)
  • For every UIView in a view hierarchy rooted by a given UIView, recycles those that conform to the protocol Recyclable and stores them for re-use later.

    Declaration

    Swift

    open func recycleViewTree(_ rootView: UIView)