Layout

@objcMembers open class Layout: NSObject

Abstract base class that defines a node in a tree-hierarchy. It is used for storing layout information on how to render and position itself relative to other nodes in this hierarchy. Nodes can represent fields, blocks, or a workspace (which are always root nodes).

The coordinate system used inside a Layout object is in the Workspace coordinate system. There are many properties inside a Layout object that should not be accessed or modified by UI views during rendering (eg. relativePosition, size, absolutePosition). Instead, a UI view can simply access the property viewFrame to determine its UIView coordinate system position and size.

  • Flag that should be used when the layout’s entire display needs to be updated from the UI side

    Declaration

    Swift

    open static let Flag_NeedsDisplay = LayoutFlag(highestOrderBitIndex: 0)
  • Flag that should be used when self.viewFrame has been updated

    Declaration

    Swift

    open static let Flag_UpdateViewFrame = LayoutFlag(highestOrderBitIndex: 1)
  • A unique identifier used to identify this layout for its lifetime

    Declaration

    Swift

    public final let uuid: String
  • The LayoutEngine used for layout related functions such as unit scaling and UI configuration.

    Declaration

    Swift

    public final let engine: LayoutEngine
  • Convenience property for accessing self.engine.config

    Declaration

    Swift

    open var config: LayoutConfig
  • The parent node of this layout. If this value is nil, this layout is the root node.

    Declaration

    Swift

    public fileprivate(set) final weak var parentLayout: Layout?
  • Layouts whose parentLayout is set to this layout

    Declaration

    Swift

    public fileprivate(set) final var childLayouts = Set<Layout>()
  • UIView frame for this layout relative to its parent view node’s layout. For example, the parent view node layout for a Field is a Block, while the parent view node for a Block is a Workspace.

    Declaration

    Swift

    public internal(set) final var viewFrame: CGRect = CGRect.zero
  • The delegate for events that occur on this instance

    Declaration

    Swift

    public final weak var delegate: LayoutDelegate?
  • A set of Layout hierarchy listeners on this instance

    Declaration

    Swift

    public final var hierarchyListeners = WeakSet<LayoutHierarchyListener>()
  • This method repositions its children and recalculates its contentSize based on the positions of its children.

    Note

    This method needs to be implemented by a subclass of Layout.

    Declaration

    Swift

    open func performLayout(includeChildren: Bool)
  • For every Layout in its tree hierarchy (including itself), this method recalculates its contentSize, relativePosition, absolutePosition, and viewFrame, based on the current state of self.parentLayout.

    Declaration

    Swift

    open func updateLayoutDownTree()
  • Performs the layout of its direct children (and not of its grandchildren) and repeats this for every parent up the tree. When the top is reached, the absolutePosition and viewFrame for each layout in the tree is re-calculated.

    Declaration

    Swift

    public final func updateLayoutUpTree()
  • Sends a layout change event to self.delegate with a given set of flags.

    Declaration

    Swift

    public final func sendChangeEvent(withFlags flags: LayoutFlag)
  • Returns an array of Layout instances for the tree headed by this Layout instance, in no particular order.

    Declaration

    Swift

    public final func flattenedLayoutTree<T>(ofType type: T.Type? = nil) -> [T] where T: Layout

    Return Value

    An array of all Layout instances.

  • Returns whether this layout is a descendant of a given layout.

    Declaration

    Swift

    public final func isDescendant(of layout: Layout) -> Bool

    Return Value

    true if the given layout is a grandparent of this layout. false otherwise.

  • Executes a given code block, where layout changes made inside this code block are animated.

    Note

    If there is an inner call to Layout.doNotAnimate(:) inside the given code block, that call will not animate its layout changes.

    Declaration

    Swift

    public static func animate(code: () throws -> Void) rethrows
  • Executes a given code block, where layout changes made inside this code block are not animated.

    Note

    If there is an inner call to Layout.animate(:) inside the given code block, that call will animate its layout changes.

    Declaration

    Swift

    public static func doNotAnimate(code: () throws -> Void) rethrows
  • Property indicating whether the next change event that is sent out via sendChangeEvent(:) should be animated or not.

    Declaration

    Swift

    public var animateChangeEvent: Bool