mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
view controller node is resized to match layoutspec for cells
This commit is contained in:
@@ -93,6 +93,15 @@ typedef NSUInteger ASCellNodeAnimation;
|
|||||||
*/
|
*/
|
||||||
- (void)setNeedsLayout;
|
- (void)setNeedsLayout;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* TODO: WRITE DOCUMENTATION */
|
||||||
|
|
||||||
|
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock;
|
||||||
|
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,13 @@
|
|||||||
#pragma mark -
|
#pragma mark -
|
||||||
#pragma mark ASCellNode
|
#pragma mark ASCellNode
|
||||||
|
|
||||||
|
@interface ASCellNode (){
|
||||||
|
ASDisplayNodeDidLoadBlock _nodeLoadedBlock;
|
||||||
|
ASDisplayNode *_viewControllerNode;
|
||||||
|
UIViewController *_viewController;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation ASCellNode
|
@implementation ASCellNode
|
||||||
|
|
||||||
- (instancetype)init
|
- (instancetype)init
|
||||||
@@ -32,6 +39,35 @@
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock
|
||||||
|
{
|
||||||
|
return [self initWithViewControllerBlock:viewControllerBlock didLoadBlock:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (instancetype)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
|
||||||
|
{
|
||||||
|
if (!(self = [super init]))
|
||||||
|
return nil;
|
||||||
|
|
||||||
|
ASDisplayNodeAssertNotNil(viewControllerBlock, @"should initialize with a valid block that returns a UIViewController");
|
||||||
|
|
||||||
|
_viewController = viewControllerBlock();
|
||||||
|
_viewControllerNode = [[ASDisplayNode alloc] initWithViewBlock:^UIView *{
|
||||||
|
return _viewController.view;
|
||||||
|
} didLoadBlock:didLoadBlock];
|
||||||
|
|
||||||
|
[self addSubnode:_viewControllerNode];
|
||||||
|
|
||||||
|
_nodeLoadedBlock = didLoadBlock; //not sure where i should plug in to call this...
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize {
|
||||||
|
_viewControllerNode.frame = (CGRect){{0,0}, constrainedSize.max};
|
||||||
|
|
||||||
|
return [super layoutSpecThatFits:constrainedSize];
|
||||||
|
}
|
||||||
|
|
||||||
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
|
- (instancetype)initWithLayerBlock:(ASDisplayNodeLayerBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
|
||||||
{
|
{
|
||||||
ASDisplayNodeAssertNotSupported();
|
ASDisplayNodeAssertNotSupported();
|
||||||
@@ -40,9 +76,8 @@
|
|||||||
|
|
||||||
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
|
- (instancetype)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
|
||||||
{
|
{
|
||||||
return [super initWithViewBlock:viewBlock didLoadBlock:didLoadBlock];
|
ASDisplayNodeAssertNotSupported();
|
||||||
// ASDisplayNodeAssertNotSupported();
|
return nil;
|
||||||
// return nil;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setLayerBacked:(BOOL)layerBacked
|
- (void)setLayerBacked:(BOOL)layerBacked
|
||||||
@@ -70,6 +105,9 @@
|
|||||||
ASDisplayNodeAssertMainThread();
|
ASDisplayNodeAssertMainThread();
|
||||||
ASDisplayNodeAssert([self.view isKindOfClass:_ASDisplayView.class], @"ASCellNode views must be of type _ASDisplayView");
|
ASDisplayNodeAssert([self.view isKindOfClass:_ASDisplayView.class], @"ASCellNode views must be of type _ASDisplayView");
|
||||||
[(_ASDisplayView *)self.view __forwardTouchesBegan:touches withEvent:event];
|
[(_ASDisplayView *)self.view __forwardTouchesBegan:touches withEvent:event];
|
||||||
|
// if (_viewController) {
|
||||||
|
// [_viewController touchesBegan:touches withEvent:event];
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
|
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
|
||||||
@@ -77,6 +115,9 @@
|
|||||||
ASDisplayNodeAssertMainThread();
|
ASDisplayNodeAssertMainThread();
|
||||||
ASDisplayNodeAssert([self.view isKindOfClass:_ASDisplayView.class], @"ASCellNode views must be of type _ASDisplayView");
|
ASDisplayNodeAssert([self.view isKindOfClass:_ASDisplayView.class], @"ASCellNode views must be of type _ASDisplayView");
|
||||||
[(_ASDisplayView *)self.view __forwardTouchesMoved:touches withEvent:event];
|
[(_ASDisplayView *)self.view __forwardTouchesMoved:touches withEvent:event];
|
||||||
|
// if (_viewController) {
|
||||||
|
// [_viewController touchesMoved:touches withEvent:event];
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
|
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
|
||||||
@@ -84,6 +125,9 @@
|
|||||||
ASDisplayNodeAssertMainThread();
|
ASDisplayNodeAssertMainThread();
|
||||||
ASDisplayNodeAssert([self.view isKindOfClass:_ASDisplayView.class], @"ASCellNode views must be of type _ASDisplayView");
|
ASDisplayNodeAssert([self.view isKindOfClass:_ASDisplayView.class], @"ASCellNode views must be of type _ASDisplayView");
|
||||||
[(_ASDisplayView *)self.view __forwardTouchesEnded:touches withEvent:event];
|
[(_ASDisplayView *)self.view __forwardTouchesEnded:touches withEvent:event];
|
||||||
|
// if (_viewController) {
|
||||||
|
// [_viewController touchesEnded:touches withEvent:event];
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
|
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
|
||||||
@@ -91,6 +135,9 @@
|
|||||||
ASDisplayNodeAssertMainThread();
|
ASDisplayNodeAssertMainThread();
|
||||||
ASDisplayNodeAssert([self.view isKindOfClass:_ASDisplayView.class], @"ASCellNode views must be of type _ASDisplayView");
|
ASDisplayNodeAssert([self.view isKindOfClass:_ASDisplayView.class], @"ASCellNode views must be of type _ASDisplayView");
|
||||||
[(_ASDisplayView *)self.view __forwardTouchesCancelled:touches withEvent:event];
|
[(_ASDisplayView *)self.view __forwardTouchesCancelled:touches withEvent:event];
|
||||||
|
// if (_viewController) {
|
||||||
|
// [_viewController touchesCancelled:touches withEvent:event];
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -98,10 +98,6 @@ typedef NS_OPTIONS(NSUInteger, ASInterfaceState)
|
|||||||
*/
|
*/
|
||||||
- (id)init;
|
- (id)init;
|
||||||
|
|
||||||
|
|
||||||
- (id)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock;
|
|
||||||
- (id)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @abstract Alternative initializer with a block to create the backing view.
|
* @abstract Alternative initializer with a block to create the backing view.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -251,25 +251,6 @@ static ASDisplayNodeMethodOverrides GetASDisplayNodeMethodOverrides(Class c)
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock
|
|
||||||
{
|
|
||||||
return [self initWithViewControllerBlock:viewControllerBlock didLoadBlock:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id)initWithViewControllerBlock:(ASDisplayNodeViewControllerBlock)viewControllerBlock didLoadBlock:(ASDisplayNodeDidLoadBlock)didLoadBlock
|
|
||||||
{
|
|
||||||
if (!(self = [super init]))
|
|
||||||
return nil;
|
|
||||||
|
|
||||||
ASDisplayNodeAssertNotNil(viewControllerBlock, @"should initialize with a valid block that returns a UIViewController");
|
|
||||||
|
|
||||||
return [self initWithViewBlock:^UIView *{
|
|
||||||
UIViewController *vc = viewControllerBlock();
|
|
||||||
vc.view.clipsToBounds = YES; // not sure this is the way to go, doesn't really make it better per se
|
|
||||||
return vc.view;
|
|
||||||
} didLoadBlock:didLoadBlock];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock
|
- (id)initWithViewBlock:(ASDisplayNodeViewBlock)viewBlock
|
||||||
{
|
{
|
||||||
return [self initWithViewBlock:viewBlock didLoadBlock:nil];
|
return [self initWithViewBlock:viewBlock didLoadBlock:nil];
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
#import <AsyncDisplayKit/AsyncDisplayKit.h>
|
#import <AsyncDisplayKit/AsyncDisplayKit.h>
|
||||||
#import "MosaicCollectionViewLayout.h"
|
#import "MosaicCollectionViewLayout.h"
|
||||||
#import "SupplementaryNode.h"
|
#import "SupplementaryNode.h"
|
||||||
#import "ImageCellNode.h"
|
#import "ImageViewController.h"
|
||||||
|
|
||||||
static NSUInteger kNumberOfImages = 14;
|
static NSUInteger kNumberOfImages = 14;
|
||||||
|
|
||||||
@@ -92,7 +92,13 @@ static NSUInteger kNumberOfImages = 14;
|
|||||||
|
|
||||||
- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath
|
- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForItemAtIndexPath:(NSIndexPath *)indexPath
|
||||||
{
|
{
|
||||||
return [[ImageCellNode alloc] initWithImage:_sections[indexPath.section][indexPath.item]];
|
ASCellNode *node = [[ASCellNode alloc] initWithViewControllerBlock:^UIViewController *{
|
||||||
|
return [[ImageViewController alloc] initWithImage:_sections[indexPath.section][indexPath.item]];
|
||||||
|
}];
|
||||||
|
|
||||||
|
return node;
|
||||||
|
|
||||||
|
//[[ImageCellNode alloc] initWithImage:_sections[indexPath.section][indexPath.item]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
|
- (ASCellNode *)collectionView:(ASCollectionView *)collectionView nodeForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
|
||||||
|
|||||||
Reference in New Issue
Block a user