BlueprintView

public final class BlueprintView : UIView

A view that is responsible for displaying an Element hierarchy.

A view controller that renders content via Blueprint might look something like this:

final class HelloWorldViewController: UIViewController {

   private var blueprintView = BlueprintView(element: nil)

   override func viewDidLoad() {
       super.viewDidLoad()

       let rootElement = Label(text: "Hello, world!")
       blueprintView.element = rootElement
       view.addSubview(blueprintView)
    }

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        blueprintView.frame = view.bounds
    }

}
  • A base environment used when laying out and rendering the element tree.

    Some keys will be overridden with the traits from the view itself. Eg, windowSize, safeAreaInsets, etc.

    If this blueprint view is within another blueprint view, the environment of the parent view will be inherited by this view if automaticallyInheritsEnvironmentFromContainingBlueprintViews is enabled. In the case of matching keys in both the inherited environment and the provided environment, the values from this environment will take priority over the inherited environment.

    Declaration

    Swift

    public var environment: Environment { get set }
  • If true, then Blueprint will automatically inherit the Environment from the nearest parent BlueprintView in the view hierarchy.

    If false, then only the values from environment will be used to seed the environment passed to the element hierarchy.

    This property is recursive – if the nearest parent BlueprintView also sets this property to true, then you will inherit the Environment from that view’s parent BlueprintView, and so on.

    Defaults to true.

    Declaration

    Swift

    public var automaticallyInheritsEnvironmentFromContainingBlueprintViews: Bool { get set }
  • The root element that is displayed within the view.

    Declaration

    Swift

    public var element: Element? { get set }
  • We need to invalidateIntrinsicContentSize when bound.size changes for Auto Layout to work correctly.

    Declaration

    Swift

    public override var bounds: CGRect { get set }
  • An optional explicit layout mode for this view. If nil, this view will inherit the layout mode of its nearest ancestor or use default if it has no ancestor.

    Declaration

    Swift

    public var layoutMode: LayoutMode? { get set }
  • An optional name to help identify this view

    Declaration

    Swift

    public var name: String?
  • Provides performance metrics about the duration of layouts, updates, etc.

    Declaration

    Swift

    public weak var metricsDelegate: BlueprintViewMetricsDelegate?
  • Instantiates a view with the given element

    Declaration

    Swift

    public required init(element: Element?, environment: Environment = .empty)

    Parameters

    element

    The root element that will be displayed in the view.

    environment

    A base environment to render elements with. Defaults to .empty.

  • Declaration

    Swift

    public convenience override init(frame: CGRect)
  • Measures the size needed to display the view within the given constraining size, by measuring the current element of the BlueprintView.

    If you would like to not constrain the measurement in a given axis, pass 0.0 or .greatestFiniteMagnitude for that axis, eg:

    // Measures with a width of 100, and no height constraint.
    blueprintView.sizeThatFits(CGSize(width: 100.0, height: 0.0))
    
    // Measures with a height of 100, and no width constraint.
    blueprintView.sizeThatFits(CGSize(width: 0.0, height: 100.0))
    
    // Measures unconstrained in both axes.
    blueprintView.sizeThatFits(.zero)
    

    Declaration

    Swift

    public override func sizeThatFits(_ fittingSize: CGSize) -> CGSize
  • Measures the size needed to display the view within the given SizeConstraint. by measuring the current element of the BlueprintView.

    Declaration

    Swift

    public func sizeThatFits(_ constraint: SizeConstraint) -> CGSize
  • Measures the size needed to display the view within then given constraining size, by measuring the current element of the BlueprintView.

    If you would like to not constrain the measurement in a given axis, pass 0.0 or .greatestFiniteMagnitude for that axis.

    Declaration

    Swift

    public override func systemLayoutSizeFitting(
        _ targetSize: CGSize
    ) -> CGSize
  • Measures the size needed to display the view within then given constraining size, by measuring the current element of the BlueprintView.

    If you would like to not constrain the measurement in a given axis, pass 0.0 or .greatestFiniteMagnitude for that axis.

    Declaration

    Swift

    public override func systemLayoutSizeFitting(
        _ targetSize: CGSize,
        withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority,
        verticalFittingPriority: UILayoutPriority
    ) -> CGSize
  • For us, this is the same as sizeThatFits, since blueprint does not contain the same concept of constraints as Autolayout.

    Declaration

    Swift

    public override var intrinsicContentSize: CGSize { get }
  • Declaration

    Swift

    public override var semanticContentAttribute: UISemanticContentAttribute { get set }
  • Declaration

    Swift

    public override func safeAreaInsetsDidChange()
  • Declaration

    Swift

    public override func layoutSubviews()
  • Declaration

    Swift

    public override func didMoveToWindow()