-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds support for having multiple interface state delegates. #979
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e8b8fd6
Adds support for having multiple interface state delegates.
garrettmoon 8c5981e
Switch to respondsToSelector for int del instead of separate object
garrettmoon 205f6d4
Add CHANGELOG
garrettmoon 0dcfaec
Make ASDisplayNode+InterfaceState.h public
garrettmoon 2a1c063
Huy's comments
garrettmoon 700d927
Don't even bother removing since it's a weak hash table.
garrettmoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// | ||
// ASDisplayNode+InterfaceState.h | ||
// Texture | ||
// | ||
// Copyright (c) 2017-present, Pinterest, Inc. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
/** | ||
* Interface state is available on ASDisplayNode and ASViewController, and | ||
* allows checking whether a node is in an interface situation where it is prudent to trigger certain | ||
* actions: measurement, data loading, display, and visibility (the latter for animations or other onscreen-only effects). | ||
* | ||
* The defualt state, ASInterfaceStateNone, means that the element is not predicted to be onscreen soon and | ||
* preloading should not be performed. Swift: use [] for the default behavior. | ||
*/ | ||
typedef NS_OPTIONS(NSUInteger, ASInterfaceState) | ||
{ | ||
/** The element is not predicted to be onscreen soon and preloading should not be performed */ | ||
ASInterfaceStateNone = 0, | ||
/** The element may be added to a view soon that could become visible. Measure the layout, including size calculation. */ | ||
ASInterfaceStateMeasureLayout = 1 << 0, | ||
/** The element is likely enough to come onscreen that disk and/or network data required for display should be fetched. */ | ||
ASInterfaceStatePreload = 1 << 1, | ||
/** The element is very likely to become visible, and concurrent rendering should be executed for any -setNeedsDisplay. */ | ||
ASInterfaceStateDisplay = 1 << 2, | ||
/** The element is physically onscreen by at least 1 pixel. | ||
In practice, all other bit fields should also be set when this flag is set. */ | ||
ASInterfaceStateVisible = 1 << 3, | ||
|
||
/** | ||
* The node is not contained in a cell but it is in a window. | ||
* | ||
* Currently we only set `interfaceState` to other values for | ||
* nodes contained in table views or collection views. | ||
*/ | ||
ASInterfaceStateInHierarchy = ASInterfaceStateMeasureLayout | ASInterfaceStatePreload | ASInterfaceStateDisplay | ASInterfaceStateVisible, | ||
}; | ||
|
||
@protocol ASInterfaceStateDelegate <NSObject> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only change here is that these are now all optional. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also added |
||
@optional | ||
|
||
/** | ||
* @abstract Called whenever any bit in the ASInterfaceState bitfield is changed. | ||
* @discussion Subclasses may use this to monitor when they become visible, should free cached data, and much more. | ||
* @see ASInterfaceState | ||
*/ | ||
- (void)interfaceStateDidChange:(ASInterfaceState)newState fromState:(ASInterfaceState)oldState; | ||
|
||
/** | ||
* @abstract Called whenever the node becomes visible. | ||
* @discussion Subclasses may use this to monitor when they become visible. | ||
* @note This method is guaranteed to be called on main. | ||
*/ | ||
- (void)didEnterVisibleState; | ||
|
||
/** | ||
* @abstract Called whenever the node is no longer visible. | ||
* @discussion Subclasses may use this to monitor when they are no longer visible. | ||
* @note This method is guaranteed to be called on main. | ||
*/ | ||
- (void)didExitVisibleState; | ||
|
||
/** | ||
* @abstract Called whenever the the node has entered the display state. | ||
* @discussion Subclasses may use this to monitor when a node should be rendering its content. | ||
* @note This method is guaranteed to be called on main. | ||
*/ | ||
- (void)didEnterDisplayState; | ||
|
||
/** | ||
* @abstract Called whenever the the node has exited the display state. | ||
* @discussion Subclasses may use this to monitor when a node should no longer be rendering its content. | ||
* @note This method is guaranteed to be called on main. | ||
*/ | ||
- (void)didExitDisplayState; | ||
|
||
/** | ||
* @abstract Called whenever the the node has entered the preload state. | ||
* @discussion Subclasses may use this to monitor data for a node should be preloaded, either from a local or remote source. | ||
* @note This method is guaranteed to be called on main. | ||
*/ | ||
- (void)didEnterPreloadState; | ||
|
||
/** | ||
* @abstract Called whenever the the node has exited the preload state. | ||
* @discussion Subclasses may use this to monitor whether preloading data for a node should be canceled. | ||
* @note This method is guaranteed to be called on main. | ||
*/ | ||
- (void)didExitPreloadState; | ||
|
||
/** | ||
* @abstract Called when the node has completed applying the layout. | ||
* @discussion Can be used for operations that are performed after layout has completed. | ||
* @note This method is guaranteed to be called on main. | ||
*/ | ||
- (void)nodeDidLayout; | ||
|
||
/** | ||
* @abstract Called when the node loads. | ||
* @discussion Can be used for operations that are performed after the node's view is available. | ||
* @note This method is guaranteed to be called on main. | ||
*/ | ||
- (void)nodeDidLoad; | ||
|
||
/** | ||
* @abstract Indicates that the receiver and all subnodes have finished displaying. | ||
* @discussion May be called more than once, for example if the receiver has a network image node. | ||
* This is called after the first display pass even if network image nodes have not downloaded anything | ||
* (text would be done, and other nodes that are ready to do their final display). Each render of | ||
* every progressive jpeg network node would cause this to be called, so this hook could be called up to | ||
* 1 + (pJPEGcount * pJPEGrenderCount) times. The render count depends on how many times the downloader calls | ||
* the progressImage block. | ||
* @note This method is guaranteed to be called on main. | ||
*/ | ||
- (void)hierarchyDisplayDidFinish; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just moved, no changes.