Empty screens: Implement empty view management in RecentsViewController.

This commit is contained in:
SBiOSoftWhare
2020-11-26 11:02:42 +01:00
parent ec43f572eb
commit a8427c433e
2 changed files with 114 additions and 0 deletions
@@ -184,6 +184,8 @@
// Force table refresh
[self cancelEditionMode:YES];
}
[self.emptyView updateWithTheme:ThemeService.shared.theme];
[self setNeedsStatusBarAppearanceUpdate];
}
@@ -848,6 +850,13 @@
}
}
- (void)dataSource:(MXKDataSource *)dataSource didCellChange:(id)changes
{
[super dataSource:dataSource didCellChange:changes];
[self showEmptyViewIfNeeded];
}
#pragma mark - Swipe actions
- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
@@ -1871,4 +1880,90 @@
coordinatorBridgePresenter = nil;
}
#pragma mark - Empty view management
- (void)showEmptyViewIfNeeded
{
[self showEmptyView:[self shouldShowEmptyView]];
}
- (void)showEmptyView:(BOOL)show
{
if (!self.viewIfLoaded)
{
return;
}
if (show && !self.emptyView)
{
RootTabEmptyView *emptyView = [RootTabEmptyView instantiate];
[emptyView updateWithTheme:ThemeService.shared.theme];
[self addEmptyView:emptyView];
self.emptyView = emptyView;
[self updateEmptyView];
}
else if (!show)
{
[self.emptyView removeFromSuperview];
}
self.recentsTableView.hidden = show;
self.stickyHeadersTopContainer.hidden = show;
self.stickyHeadersBottomContainer.hidden = show;
}
- (void)updateEmptyView
{
}
- (void)addEmptyView:(RootTabEmptyView*)emptyView
{
if (!self.isViewLoaded)
{
return;
}
NSLayoutConstraint *emptyViewBottomConstraint;
NSLayoutConstraint *contentViewBottomConstraint;
if (plusButtonImageView && plusButtonImageView.isHidden == NO)
{
[self.view insertSubview:emptyView belowSubview:plusButtonImageView];
contentViewBottomConstraint = [NSLayoutConstraint constraintWithItem:emptyView.contentView
attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationLessThanOrEqual toItem:plusButtonImageView
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:0];
}
else
{
[self.view addSubview:emptyView];
}
emptyViewBottomConstraint = [emptyView.bottomAnchor constraintEqualToAnchor:emptyView.superview.bottomAnchor];
emptyView.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[
[emptyView.topAnchor constraintEqualToAnchor:emptyView.superview.topAnchor],
[emptyView.leftAnchor constraintEqualToAnchor:emptyView.superview.leftAnchor],
[emptyView.rightAnchor constraintEqualToAnchor:emptyView.superview.rightAnchor],
emptyViewBottomConstraint
]];
if (contentViewBottomConstraint)
{
contentViewBottomConstraint.active = YES;
}
}
- (BOOL)shouldShowEmptyView
{
return NO;
}
@end