Skip to content
This repository has been archived by the owner on Jun 5, 2019. It is now read-only.

Documentation

Sahand Nayebaziz edited this page Apr 27, 2016 · 8 revisions

This document lists and describe the objects and methods you can use with StateView.

For a general introduction to StateView, including how to initialize a StateView, add subviews, and use state and props, take a look at the getting started guide.

Contents

StateView

A UIView subclass that uses a ShadowView and a collection of methods, including its own render() and resolveProps() to update its subviews when its state property is set to a new value.

StateView class
A subclass of UIView.

shadow property
An instance of ShadowView that is initialized automatically. shadow keeps an always up-to-date record of views that have been added to this instance of StateView and orchestrates the addition, removal, and updating of subviews in an instance of StateView.

props property
An array with type [StateViewProp] that contains any values passed in from the parent view of this instance of StateView.

For a general discussion of props, take a look at the getting started guide.

state property
A dictionary with type [String: Any] that contains values set by this instance of StateView. Values saved in state should describe the current state of this view as completely as possible and be used in the render() method of this instance of StateView to influence the content and inclusion of subviews.

For a general discussion of state, take a look at the getting started guide.

parentViewController property
The UIViewController that is displaying the hierarchy of views containing this instance of StateView. Use this property to make calls to methods like presentViewController().

getInitialState method
Returns a dictionary with type [String: Any] that can be used in place of the default empty dictionary used as initial state. Use this method to set values in state that are inherently true of the state of view until something changes, or values that describe the initial state of a view well and will be changed throughout the view's lifetime.

renderDeep method
An internal method that calls render() and then shadow once render() has completed. Call this method once on an instance of StateView if you are adding a StateView to a UIView.

render method
A method that is called anytime there is a change to state. Override this method to place subviews in this instance of StateView. You are encouraged to include conditional statements and calls to your own synchronous functions to decide which views to place as subviews each time render() is called.

For a general discussion of render(), take a look at the getting started guide.

resolveProps method
An internal method that resolves any StateViewPropWithStateLink that came from a call to prop(forKey: StateKey, isLinkedToKeyInState: String) into a StateViewProp with a value by getting the value in state for the linked key.

place method
A method that includes a subview to be added (or kept, if placed in the previous run of render()) after the current run of render() is completed.

This method differs slightly depending on whether you would like to place a StateView or a UIView. If you are placing a StateView, this method is place(type: StateView.Type, key: String, constraints: ((make: ConstraintMaker -> Void)) -> ShadowViewElement). If you are placing a UIView, initialize the UIView first and then use place(view: UIView, key: String, constraints: ((make: ConstraintMaker) -> Void)) -> ShadowViewElement).

For a general discussion of place(), take a look at the getting started guide.

More coming soon.

Contents

Clone this wiki locally