Open skylinezum opened 9 years ago
Yeah, would love that, but not should what it would take ..
I modified TLYShyNavBarManager and was able to make it work. First I changed from CocoaPods to adding the library manually.
I added the ASTableView to TLYShyNavBarManager.m
#import <AsyncDisplayKit/ASTableView.h>
I then modified setScrollView method as follows:
- (void)setScrollView:(UIScrollView *)scrollView
{
NSLog(@"class: %@", NSStringFromClass([scrollView class]));
// account for ASTableView
if ([scrollView isKindOfClass:[UITableView class]] || [scrollView isKindOfClass:[UIScrollView class]]) {
[_scrollView removeObserver:self forKeyPath:@"contentSize" context:kTLYShyNavBarManagerKVOContext];
if (_scrollView.delegate == self.delegateProxy) {
_scrollView.delegate = self.delegateProxy.originalDelegate;
}
_scrollView = scrollView;
self.scrollViewController.scrollView = scrollView;
NSUInteger index = [scrollView.subviews indexOfObjectPassingTest:^BOOL (id obj, NSUInteger idx, BOOL *stop) {
return [obj isKindOfClass:[UIRefreshControl class]];
}];
if (index != NSNotFound) {
self.scrollViewController.refreshControl = [scrollView.subviews objectAtIndex:index];
}
if (_scrollView.delegate != self.delegateProxy)
{
self.delegateProxy.originalDelegate = _scrollView.delegate;
_scrollView.delegate = (id)self.delegateProxy;
}
[self cleanup];
[self layoutViews];
[_scrollView addObserver:self forKeyPath:@"contentSize" options:0 context:kTLYShyNavBarManagerKVOContext];
} else if ([scrollView isKindOfClass:[ASTableView class]]) {
[_tableView removeObserver:self forKeyPath:@"contentSize" context:kTLYShyNavBarManagerKVOContext];
ASTableView *tableView = (ASTableView *)scrollView;
if (_tableView.asyncDelegate == self.delegateProxy) {
_tableView.asyncDelegate = self.delegateProxy.originalDelegate;
}
_tableView = tableView;
self.scrollViewController.scrollView = tableView;
NSUInteger index = [tableView.subviews indexOfObjectPassingTest:^BOOL (id obj, NSUInteger idx, BOOL *stop) {
return [obj isKindOfClass:[UIRefreshControl class]];
}];
if (index != NSNotFound) {
self.scrollViewController.refreshControl = [tableView.subviews objectAtIndex:index];
}
if (_tableView.asyncDelegate != self.delegateProxy)
{
self.delegateProxy.originalDelegate = _tableView.asyncDelegate;
_tableView.asyncDelegate = (id)self.delegateProxy;
}
[self cleanup];
[self layoutViews];
[_tableView addObserver:self forKeyPath:@"contentSize" options:0 context:kTLYShyNavBarManagerKVOContext];
_scrollView = (UIScrollView *)_tableView;
}
}
Then in my ViewController class with an ASTableView, I configured and instantiated the ASTableView as follows:
- (void)configureTableView {
headerBannerHeight = self.view.bounds.size.width * aspectRatio;
self.shyNavBarManager.scrollView = (UIScrollView *)self.tableView;
self.shyNavBarManager.stickyNavigationBar = YES;
// add nodes in background thread
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
self.tableHeaderImageNode = [[ASImageNode alloc] init];
self.tableHeaderImageNode.image = [UIImage imageNamed:kImagesVideoBanner];
self.tableHeaderImageNode.backgroundColor = [UIColor clearColor];
self.tableHeaderImageNode.contentMode = UIViewContentModeScaleAspectFill;
self.tableHeaderImageNode.frame = CGRectMake(0, 0, self.view.frame.size.width, headerBannerHeight);
dispatch_async(dispatch_get_main_queue(), ^{
[self.shyNavBarManager setExtensionView:self.tableHeaderImageNode.view];
});
});
}
- (ASTableView *)tableView {
if (!_tableView) {
self.tableView = [[ASTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.asyncDataSource = self;
self.tableView.asyncDelegate = self;
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.tableFooterView = [UIView new];
[self.view addSubview:self.tableView];
}
return _tableView;
}
It seems to be working well enough - I hope this helps someone out. Let me know if something like this merged because I prefer to have CocoaPods version installed. Thank you for a great library
Hi from ASDK! We can't promise to provide support for interop with TLYShyNavBar but it will work for the time being with the linked ASDK PR. Note: don't call manager.scrollView = tableView
more than once per table view or you'll get an infinite loop!
Is it possible to make this work with AsyncDisplayKit?