Swiftgram/Source/ASVisibilityProtocols.h
appleguy 465abb1ded [License] Simplify the Texture license to be pure Apache 2 (removing ASDK-Licenses). (#1077)
* [License] Simplify the Texture license to be pure Apache 2 (removing ASDK-Licenses)

With permission of the Facebook Open Source team, we are simplifying the Texture
license so that clients can rely on the Apache 2 terms that most of Texture is
already covered by. This means that code originally forked from AsyncDisplayKit
will be re-licensed from "BSD 3-clause + PATENTS v2" to Apache 2 without a
PATENTS file.

After getting confirmation that the updates to these core files look good, we'll
propagate this new license header to all files (in this same PR) and get sign-off
from all parties before landing.

* [License] Update all Texture source files to be pure Apache 2.

* Changelog entry for Apache 2 license update.

* Revert "[License] Update all Texture source files to be pure Apache 2."

This reverts commit ffa0fbbba9717d871dd16c4b07539f2f8208fc2b.

* [License] Update all Texture source files to be pure Apache 2, maintaining copyrights.

* [License] Update CONTRIBUTING, README, Podspec & Dangerfile.
2018-08-28 07:39:18 -07:00

146 lines
4.9 KiB
Objective-C

//
// ASVisibilityProtocols.h
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import <AsyncDisplayKit/ASBaseDefines.h>
#import <AsyncDisplayKit/ASLayoutRangeType.h>
NS_ASSUME_NONNULL_BEGIN
@class UIViewController;
AS_EXTERN ASLayoutRangeMode ASLayoutRangeModeForVisibilityDepth(NSUInteger visibilityDepth);
/**
* ASVisibilityDepth
*
* @discussion "Visibility Depth" represents the number of user actions required to make an ASDisplayNode or
* ASViewController visibile. AsyncDisplayKit uses this information to intelligently manage memory and focus
* resources where they are most visible to the user.
*
* The ASVisibilityDepth protocol describes how custom view controllers can integrate with this system.
*
* Parent view controllers should also implement @c ASManagesChildVisibilityDepth
*
* @see ASManagesChildVisibilityDepth
*/
@protocol ASVisibilityDepth <NSObject>
/**
* Visibility depth
*
* @discussion Represents the number of user actions necessary to reach the view controller. An increased visibility
* depth indicates a higher number of user interactions for the view controller to be visible again. For example,
* an onscreen navigation controller's top view controller should have a visibility depth of 0. The view controller
* one from the top should have a visibility deptch of 1 as should the root view controller in the stack (because
* the user can hold the back button to pop to the root view controller).
*
* Visibility depth is used to automatically adjust ranges on range controllers (and thus free up memory) and can
* be used to reduce memory usage of other items as well.
*/
- (NSInteger)visibilityDepth;
/**
* Called when visibility depth changes
*
* @discussion @c visibilityDepthDidChange is called whenever the visibility depth of the represented view controller
* has changed.
*
* If implemented by a view controller container, use this method to notify child view controllers that their view
* depth has changed @see ASNavigationController.m
*
* If implemented on an ASViewController, use this method to reduce or increase the resources that your
* view controller uses. A higher visibility depth view controller should decrease it's resource usage, a lower
* visibility depth controller should pre-warm resources in preperation for a display at 0 depth.
*
* ASViewController implements this method and reduces / increases range mode of supporting nodes (such as ASCollectionNode
* and ASTableNode).
*
* @see visibilityDepth
*/
- (void)visibilityDepthDidChange;
@end
/**
* ASManagesChildVisibilityDepth
*
* @discussion A protocol which should be implemented by container view controllers to allow proper
* propagation of visibility depth
*
* @see ASVisibilityDepth
*/
@protocol ASManagesChildVisibilityDepth <ASVisibilityDepth>
/**
* @abstract Container view controllers should adopt this protocol to indicate that they will manage their child's
* visibilityDepth. For example, ASNavigationController adopts this protocol and manages its childrens visibility
* depth.
*
* If you adopt this protocol, you *must* also emit visibilityDepthDidChange messages to child view controllers.
*
* @param childViewController Expected to return the visibility depth of the child view controller.
*/
- (NSInteger)visibilityDepthOfChildViewController:(UIViewController *)childViewController;
@end
#define ASVisibilitySetVisibilityDepth \
- (void)setVisibilityDepth:(NSUInteger)visibilityDepth \
{ \
if (_visibilityDepth == visibilityDepth) { \
return; \
} \
_visibilityDepth = visibilityDepth; \
[self visibilityDepthDidChange]; \
}
#define ASVisibilityDepthImplementation \
- (NSInteger)visibilityDepth \
{ \
if (self.parentViewController && _parentManagesVisibilityDepth == NO) { \
_parentManagesVisibilityDepth = [self.parentViewController conformsToProtocol:@protocol(ASManagesChildVisibilityDepth)]; \
} \
\
if (_parentManagesVisibilityDepth) { \
return [(id <ASManagesChildVisibilityDepth>)self.parentViewController visibilityDepthOfChildViewController:self]; \
} \
return _visibilityDepth; \
}
#define ASVisibilityViewDidDisappearImplementation \
- (void)viewDidDisappear:(BOOL)animated \
{ \
[super viewDidDisappear:animated]; \
\
if (_parentManagesVisibilityDepth == NO) { \
[self setVisibilityDepth:1]; \
} \
}
#define ASVisibilityViewWillAppear \
- (void)viewWillAppear:(BOOL)animated \
{ \
[super viewWillAppear:animated]; \
\
if (_parentManagesVisibilityDepth == NO) { \
[self setVisibilityDepth:0]; \
} \
}
#define ASVisibilityDidMoveToParentViewController \
- (void)didMoveToParentViewController:(UIViewController *)parent \
{ \
[super didMoveToParentViewController:parent]; \
_parentManagesVisibilityDepth = NO; \
[self visibilityDepthDidChange]; \
}
NS_ASSUME_NONNULL_END