diff --git a/_docs/cell-node.md b/_docs/cell-node.md index 6faa4a08..07d09c6d 100755 --- a/_docs/cell-node.md +++ b/_docs/cell-node.md @@ -5,9 +5,138 @@ permalink: /docs/cell-node.html next: text-cell-node.html --- -ASCellNode is maybe the most commonly subclassed node. It can be used as the cell for both ASTableNodes and ASCollectionNodes. +ASCellNode, as you may have guessed, is the cell class of ASDK. Unlike the various cells in UIKit, ASCellNode can be used with ASTableNodes, ASCollectionNodes and ASPagerNodes, making it incredibly flexible. -That being said, subclassing it is largely the same as subclassing a regular ASDisplayNode. Most importantly, you'll write an -init method, a -layoutSpecThatFits: method for measurement and layout, and, if necessary, a -didLoad method for adding extra gesture recognizers and a -layout method for any extra layout needs. +### 3 Ways to Party -If you don't feel like subclassing you're also free to use the `-initWithView:` or `-initWithViewController:` methods to return nodes with backing views created from an existing view or view controller you already have. +There are three ways in which you can implement the cells you'll use in your ASDK app: subclassing ASCellNode, initializing with an existing ASViewController or using an existing UIView or CALayer. + +#### Subclassing + +Subclassing an ASCellNode is pretty much the same as subclassing a regular ASDisplayNode. + +Most likely, you'll write a few of the following: +
-init -- Thread safe initialization
+-layoutSpecThatFits: -- Return a layout spec that defines the layout of your cell.
+-didLoad -- Called on the main thread. Good place to add gesture recognizers, etc.
+-layout -- Also called on the main thread. Layout is complete after the call to super which means you can do any extra tweaking you need to do.
+
+- (ASCellNode *)pagerNode:(ASPagerNode *)pagerNode nodeAtIndex:(NSInteger)index
+{
+ NSArray *animals = self.allAnimals[index];
+
+ ASCellNode *node = [[ASCellNode alloc] initWithViewControllerBlock:^UIViewController * _Nonnull{
+ return [[AnimalTableNodeController alloc] initWithAnimals:animals];
+ } didLoadBlock:nil];
+
+ node.preferredFrameSize = pagerNode.bounds.size;
+
+ return node;
+}
+
+
+
+- (ASCellNode *)pagerNode:(ASPagerNode *)pagerNode nodeAtIndex:(NSInteger)index
+{
+ NSArray *animal = self.animals[index];
+
+ ASCellNode *node = [[ASCellNode alloc] initWithViewBlock:^UIView * _Nonnull{
+ return [[SomeAnimalView alloc] initWithAnimal:animal];
+ }];
+
+ node.preferredFrameSize = pagerNode.bounds.size;
+
+ return node;
+}
+
+
+
+node.neverShowPlaceholders = YES;
+
+
+
+typedef NS_OPTIONS(NSUInteger, ASControlState) {
+ ASControlStateNormal = 0,
+ ASControlStateHighlighted = 1 << 0, // used when isHighlighted is set
+ ASControlStateDisabled = 1 << 1,
+ ASControlStateSelected = 1 << 2, // used when isSelected is set
+ ...
+};
+
+
+typedef NS_OPTIONS(NSUInteger, ASControlNodeEvent)
+{
+ /** A touch-down event in the control node. */
+ ASControlNodeEventTouchDown = 1 << 0,
+ /** A repeated touch-down event in the control node; for this event the value of the UITouch tapCount method is greater than one. */
+ ASControlNodeEventTouchDownRepeat = 1 << 1,
+ /** An event where a finger is dragged inside the bounds of the control node. */
+ ASControlNodeEventTouchDragInside = 1 << 2,
+ /** An event where a finger is dragged just outside the bounds of the control. */
+ ASControlNodeEventTouchDragOutside = 1 << 3,
+ /** A touch-up event in the control node where the finger is inside the bounds of the node. */
+ ASControlNodeEventTouchUpInside = 1 << 4,
+ /** A touch-up event in the control node where the finger is outside the bounds of the node. */
+ ASControlNodeEventTouchUpOutside = 1 << 5,
+ /** A system event canceling the current touches for the control node. */
+ ASControlNodeEventTouchCancel = 1 << 6,
+ /** All events, including system events. */
+ ASControlNodeEventAllEvents = 0xFFFFFFFF
+};
+
+
+CGFloat horizontalDiff = (bounds.size.width - _playButton.bounds.size.width)/2;
+CGFloat verticalDiff = (bounds.size.height - _playButton.bounds.size.height)/2;
+
+_playButton.hitTestSlop = UIEdgeInsetsMake(-verticalDiff, -horizontalDiff, -verticalDiff, -horizontalDiff);
+
+
+
ASDisplayNode *node = [[ASDisplayNode alloc] init];
-node.clipsToBounds = YES; // not .masksToBounds
+node.clipsToBounds = YES; // not .masksToBounds
node.borderColor = [UIColor blueColor]; //layer name when there is no UIView equivalent
NSLog(@"Backing layer: %@", node.layer);
@@ -49,7 +49,7 @@ NSLog(@"Backing layer: %@", node.layer);