Getting Started
Texture’s basic unit is the node
. ASDisplayNode
is an abstraction
over UIView
, which in turn is an abstraction over CALayer
. Unlike views, which
can only be used on the main thread, nodes are thread-safe: you can
instantiate and configure entire hierarchies of them in parallel on background
threads.
To keep its user interface smooth and responsive, your app should render at 60 frames per second — the gold standard on iOS. This means the main thread has one-sixtieth of a second to push each frame. That’s 16 milliseconds to execute all layout and drawing code! And because of system overhead, your code usually has less than ten milliseconds to run before it causes a frame drop.
Texture lets you move image decoding, text sizing and rendering, and other expensive UI operations off the main thread, to keep the main thread available to respond to user interaction. Texture has other tricks up its sleeve too… but we’ll get to that later.
Nodes
If you’re used to working with views, you already know how to use nodes. Most methods have a node equivalent and most UIView
and CALayer
properties are available as well. In any case where there is a naming discrepancy (such as .clipsToBounds
vs .masksToBounds
), nodes will default to the UIView
name. The only exception is that nodes use position instead of center.
Of course, you can always access the underlying view or layer directly via node.view
or node.layer
, just make sure to do it on the main thread!
Texture offers a variety of nodes to replace the majority of the UIKit components that you are used to. Large scale apps have been able to completely write their UI using just Texture nodes.
Node Containers
When converting an app to use Texture, a common mistake is to add nodes directly to an existing view hierarchy. Doing this will virtually guarantee that your nodes will flash as they are rendered.
Instead, you should add nodes as subnodes of one of the many node container classes. These containers are in charge of telling contained nodes what state they’re currently in so that data can be loaded and nodes can be rendered as efficiently as possible. You should think of these classes as the integration point between UIKit and Texture.
Layout Engine
Texture’s layout engine is both one of its most powerful and one of its most unique features. Based on the CSS FlexBox model, it provides a declarative way of specifying a custom node’s size and layout of its subnodes. While all nodes are concurrently rendered by default, asynchronous measurement and layout are performed by providing an ASLayoutSpec
for each node.
Advanced Developer Features
Texture offers a variety of advanced developer features that cannot be found in UIKit or Foundation. Our developers have found that Texture allows simplifications in their architecture and improves developer velocity.
(Full list coming soon!)
Adding Texture to your App
If you are new to Texture, we recommend that you check out our ASDKgram example app. We’ve created a handy guide (coming soon!) with step-by-step directions and a follow along example on how to add Texture to an app.
If you run into any problems along the way, reach out to us GitHub or the Texture Slack community for help.