ARC doesn't play nicely with structs that contain references to
Objective-C objects, which causes breakage when using AsyncDisplayKit as
a dynamic framework (e.g., with CocoaPods 0.36+). Fixes#198.
Closes#99. This is a quick sketch -- room for improvement includes
considering a less-questionable class name, potentially exposing
additional UIScrollView functionality directly on the node, and using it
in a sample project.
These have been superseded by -[ASDisplayNode initWithViewBlock:] and
-[ASDisplayNode initWithLayerBlock:], respectively -- the new API allows
for custom initialisers, but does not support asynchronous display.
The old initialisers are still available in ASDisplayNodeInternal.h, for
internal subclasses and daring adventurers.
This adds new initializer methods to ASDisplayNode:
```objc
initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock
initWithLayerBlock:(ASDisplayNodeLayerBlock)layerBlock
```
Sometimes a view can't be constructed with `-[initWithViewClass:]` but you want to use it with ASDK, so these new methods provide a way to wrap an existing view in a node.
The API is meant to preserve ASDisplayNode's behavior, so you can still construct and set properties on the node on a background queue before its view is loaded; even though the view was created a priori, it is not considered to be loaded until `node.view` is accessed.
Using the API looks like this:
dispatch_async(backgroundQueue, ^{
ASDisplayNode *node = [ASDisplayNode alloc] initWithViewBlock:^{
// Guaranteed to run on the main queue
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
[button sizeToFit];
node.frame = button.frame;
return button;
}];
// Use `node` as you normally would...
node.backgroundColor = [UIColor redColor];
});
The main thing this bridging API doesn't do (can't do?) is layout. Methods like `-[ASDisplayNode calculateSizeThatFits:]` and `-[ASDisplayNode layout]` cannot delegate to `[UIView sizeThatFits:]` and `[UIView layoutSubviews]` since the UIView methods must run on the main thread. If ASDK were internally asynchronous and could dispatch its layout methods to different threads (sort of like how ASTableView computes its cells' layouts) then we could mark nodes with externally provided views/layers as having "main-queue affinity" and delegate its layout to UIKit.
Test cases are included and all existing tests pass.
Currently we miss calling `-[super touches*]` on `_ASDisplayView` touch events. We delegate handling to the node which then forwards all touch events to the *superview*, skipping the current view. This seems to have some side effects with `UITableView` and it's cells/content views.
fixes#188