mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-08 05:30:47 +00:00
This adds support for the concept of visibility depth. Visibility essentially defines the number of user actions it would take a user to have a view controller visible. Knowing a view controllers visibility depth allows view controllers to take action such as clearing out memory that can be restored at a later date. This patch also add two new view controller subclasses which adopt the ASManagesChildVisibilityDepth protocol. Any view controller that has child view controllers can adopt this protocol to indicate to the child what they're visibility is. For example, ASNavigationController will return a visibility depth of it's own visibilityDepth + 1 for a view controller that would be revealed by tapping the back button.
99 lines
2.4 KiB
Objective-C
99 lines
2.4 KiB
Objective-C
//
|
|
// ASTabBarController.m
|
|
// AsyncDisplayKit
|
|
//
|
|
// Created by Garrett Moon on 5/10/16.
|
|
// Copyright © 2016 Facebook. All rights reserved.
|
|
//
|
|
|
|
#import "ASTabBarController.h"
|
|
|
|
@implementation ASTabBarController
|
|
{
|
|
BOOL _parentManagesVisibilityDepth;
|
|
NSInteger _visibilityDepth;
|
|
}
|
|
|
|
- (void)didMoveToParentViewController:(UIViewController *)parent
|
|
{
|
|
[super didMoveToParentViewController:parent];
|
|
[self visibilityDepthDidChange];
|
|
}
|
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
{
|
|
[super viewWillAppear:animated];
|
|
|
|
if (_parentManagesVisibilityDepth == NO) {
|
|
_visibilityDepth = 0;
|
|
[self visibilityDepthDidChange];
|
|
}
|
|
}
|
|
|
|
- (void)viewDidDisappear:(BOOL)animated
|
|
{
|
|
[super viewDidDisappear:animated];
|
|
|
|
if (_parentManagesVisibilityDepth == NO) {
|
|
_visibilityDepth = 1;
|
|
[self visibilityDepthDidChange];
|
|
}
|
|
}
|
|
|
|
- (NSInteger)visibilityDepth
|
|
{
|
|
if (self.parentViewController && _parentManagesVisibilityDepth == NO) {
|
|
_parentManagesVisibilityDepth = [self.parentViewController conformsToProtocol:@protocol(ASManagesChildVisibilityDepth)];
|
|
}
|
|
|
|
if (_parentManagesVisibilityDepth) {
|
|
return [(id <ASManagesChildVisibilityDepth>)self.parentViewController visibilityDepthOfChildViewController:self];
|
|
}
|
|
return _visibilityDepth;
|
|
}
|
|
|
|
- (void)visibilityDepthDidChange
|
|
{
|
|
for (UIViewController *viewController in self.viewControllers) {
|
|
if ([viewController conformsToProtocol:@protocol(ASVisibilityDepth)]) {
|
|
[(id <ASVisibilityDepth>)viewController visibilityDepthDidChange];
|
|
}
|
|
}
|
|
}
|
|
|
|
- (NSInteger)visibilityDepthOfChildViewController:(UIViewController *)childViewController
|
|
{
|
|
if (self.selectedViewController == childViewController) {
|
|
return [self visibilityDepth];
|
|
}
|
|
return [self visibilityDepth] + 1;
|
|
}
|
|
|
|
#pragma mark - UIKit overrides
|
|
|
|
- (void)setViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers
|
|
{
|
|
[super setViewControllers:viewControllers];
|
|
[self visibilityDepthDidChange];
|
|
}
|
|
|
|
- (void)setViewControllers:(NSArray<__kindof UIViewController *> *)viewControllers animated:(BOOL)animated
|
|
{
|
|
[super setViewControllers:viewControllers animated:animated];
|
|
[self visibilityDepthDidChange];
|
|
}
|
|
|
|
- (void)setSelectedIndex:(NSUInteger)selectedIndex
|
|
{
|
|
[super setSelectedIndex:selectedIndex];
|
|
[self visibilityDepthDidChange];
|
|
}
|
|
|
|
- (void)setSelectedViewController:(__kindof UIViewController *)selectedViewController
|
|
{
|
|
[super setSelectedViewController:selectedViewController];
|
|
[self visibilityDepthDidChange];
|
|
}
|
|
|
|
@end
|