-
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
Allow to add interface state delegate in background. #1090
Merged
nguyenhuy
merged 29 commits into
TextureGroup:master
from
wsdwsd0829:add-interfacestate-delegate-in-background
Aug 31, 2018
Merged
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
929d118
fix SIMULATE_WEB_RESPONSE not imported #449
wsdwsd0829 dd24d8f
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 b8eaffa
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 2918ea0
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 9c42266
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 329f35f
Fix to make rangeMode update in right time
wsdwsd0829 5f8b7ec
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 d87bb11
merge master from upstream
wsdwsd0829 269c2ab
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 24c1ce8
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 233169e
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 b19f90d
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 b50cec4
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 b75a5f3
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 64b46e0
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 5fabc1e
remove uncessary assert
wsdwsd0829 3d5b84b
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 098b978
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 77eefd6
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 0310ed7
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 0b886de
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 a63d438
Merge branch 'master' of github.com:TextureGroup/Texture
wsdwsd0829 24af857
Allow to add interface state delegate in background threads.
wsdwsd0829 49e1337
Allow to add interface state delegate in background threads.
wsdwsd0829 ee88e85
lock around _interfaceStateDelegates
wsdwsd0829 1b605f4
lock _interfaceStateDelegates to local variable
wsdwsd0829 dfbd03b
Fix comments
wsdwsd0829 ec3542a
remove extra spaces
wsdwsd0829 7721b95
Merge branch 'master' into add-interfacestate-delegate-in-background
wsdwsd0829 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -460,6 +460,16 @@ - (void)dealloc | |
|
||
#pragma mark - Loading | ||
|
||
#define ASDisplayNodeCallInterfaceStateDelegates(method, __lock) \ | ||
__lock.lock(); \ | ||
NSHashTable *delegates = _interfaceStateDelegates; \ | ||
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. Don't we need to copy the hash table? Same for a couple of other places. 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. Good Point. Thanks. |
||
__lock.unlock(); \ | ||
for (id <ASInterfaceStateDelegate> delegate in delegates) { \ | ||
if ([delegate respondsToSelector:@selector(method)]) { \ | ||
[delegate method]; \ | ||
} \ | ||
} | ||
|
||
- (BOOL)_locked_shouldLoadViewOrLayer | ||
{ | ||
ASAssertLocked(__instanceLock__); | ||
|
@@ -572,12 +582,7 @@ - (void)_didLoad | |
for (ASDisplayNodeDidLoadBlock block in onDidLoadBlocks) { | ||
block(self); | ||
} | ||
|
||
for (id <ASInterfaceStateDelegate> delegate in _interfaceStateDelegates) { | ||
if ([delegate respondsToSelector:@selector(nodeDidLoad)]) { | ||
[delegate nodeDidLoad]; | ||
} | ||
} | ||
ASDisplayNodeCallInterfaceStateDelegates(nodeDidLoad, __instanceLock__); | ||
} | ||
|
||
- (void)didLoad | ||
|
@@ -1278,15 +1283,12 @@ - (ASLayoutSpec *)layoutSpecThatFits:(ASSizeRange)constrainedSize | |
|
||
- (void)layout | ||
{ | ||
|
||
// Hook for subclasses | ||
ASDisplayNodeAssertMainThread(); | ||
ASAssertUnlocked(__instanceLock__); | ||
ASDisplayNodeAssertTrue(self.isNodeLoaded); | ||
for (id <ASInterfaceStateDelegate> delegate in _interfaceStateDelegates) { | ||
if ([delegate respondsToSelector:@selector(nodeDidLayout)]) { | ||
[delegate nodeDidLayout]; | ||
} | ||
} | ||
ASDisplayNodeCallInterfaceStateDelegates(nodeDidLayout, __instanceLock__); | ||
} | ||
|
||
#pragma mark Layout Transition | ||
|
@@ -1509,12 +1511,7 @@ - (void)_pendingNodeDidDisplay:(ASDisplayNode *)node | |
if (_pendingDisplayNodes.isEmpty) { | ||
|
||
[self hierarchyDisplayDidFinish]; | ||
|
||
for (id <ASInterfaceStateDelegate> delegate in _interfaceStateDelegates) { | ||
if ([delegate respondsToSelector:@selector(hierarchyDisplayDidFinish)]) { | ||
[delegate hierarchyDisplayDidFinish]; | ||
} | ||
} | ||
ASDisplayNodeCallInterfaceStateDelegates(hierarchyDisplayDidFinish, __instanceLock__); | ||
|
||
BOOL placeholderShouldPersist = [self placeholderShouldPersist]; | ||
|
||
|
@@ -3017,6 +3014,8 @@ - (void)didExitHierarchy | |
|
||
#pragma mark - Interface State | ||
|
||
|
||
|
||
/** | ||
* We currently only set interface state on nodes in table/collection views. For other nodes, if they are | ||
* in the hierarchy we enable all ASInterfaceState types with `ASInterfaceStateInHierarchy`, otherwise `None`. | ||
|
@@ -3225,7 +3224,10 @@ - (void)interfaceStateDidChange:(ASInterfaceState)newState fromState:(ASInterfac | |
// Subclass hook | ||
ASAssertUnlocked(__instanceLock__); | ||
ASDisplayNodeAssertMainThread(); | ||
for (id <ASInterfaceStateDelegate> delegate in _interfaceStateDelegates) { | ||
__instanceLock__.lock(); | ||
NSHashTable *delegates = _interfaceStateDelegates; | ||
__instanceLock__.unlock(); | ||
for (id <ASInterfaceStateDelegate> delegate in delegates) { | ||
if ([delegate respondsToSelector:@selector(interfaceStateDidChange:fromState:)]) { | ||
[delegate interfaceStateDidChange:newState fromState:oldState]; | ||
} | ||
|
@@ -3241,8 +3243,7 @@ - (BOOL)shouldScheduleDisplayWithNewInterfaceState:(ASInterfaceState)newInterfac | |
|
||
- (void)addInterfaceStateDelegate:(id <ASInterfaceStateDelegate>)interfaceStateDelegate | ||
{ | ||
ASDisplayNodeAssertMainThread(); | ||
|
||
ASDN::MutexLocker l(__instanceLock__); | ||
// Not a fan of lazy loading, but this method won't get called very often and avoiding | ||
// the overhead of creating this is probably worth it. | ||
if (_interfaceStateDelegates == nil) { | ||
|
@@ -3253,7 +3254,7 @@ - (void)addInterfaceStateDelegate:(id <ASInterfaceStateDelegate>)interfaceStateD | |
|
||
- (void)removeInterfaceStateDelegate:(id <ASInterfaceStateDelegate>)interfaceStateDelegate | ||
{ | ||
ASDisplayNodeAssertMainThread(); | ||
ASDN::MutexLocker l(__instanceLock__); | ||
[_interfaceStateDelegates removeObject:interfaceStateDelegate]; | ||
} | ||
|
||
|
@@ -3268,11 +3269,7 @@ - (void)didEnterVisibleState | |
// subclass override | ||
ASDisplayNodeAssertMainThread(); | ||
ASAssertUnlocked(__instanceLock__); | ||
for (id <ASInterfaceStateDelegate> delegate in _interfaceStateDelegates) { | ||
if ([delegate respondsToSelector:@selector(didEnterVisibleState)]) { | ||
[delegate didEnterVisibleState]; | ||
} | ||
} | ||
ASDisplayNodeCallInterfaceStateDelegates(didEnterVisibleState, __instanceLock__); | ||
#if AS_ENABLE_TIPS | ||
[ASTipsController.shared nodeDidAppear:self]; | ||
#endif | ||
|
@@ -3283,11 +3280,7 @@ - (void)didExitVisibleState | |
// subclass override | ||
ASDisplayNodeAssertMainThread(); | ||
ASAssertUnlocked(__instanceLock__); | ||
for (id <ASInterfaceStateDelegate> delegate in _interfaceStateDelegates) { | ||
if ([delegate respondsToSelector:@selector(didExitVisibleState)]) { | ||
[delegate didExitVisibleState]; | ||
} | ||
} | ||
ASDisplayNodeCallInterfaceStateDelegates(didExitVisibleState, __instanceLock__); | ||
} | ||
|
||
- (BOOL)isInDisplayState | ||
|
@@ -3301,23 +3294,15 @@ - (void)didEnterDisplayState | |
// subclass override | ||
ASDisplayNodeAssertMainThread(); | ||
ASAssertUnlocked(__instanceLock__); | ||
for (id <ASInterfaceStateDelegate> delegate in _interfaceStateDelegates) { | ||
if ([delegate respondsToSelector:@selector(didEnterDisplayState)]) { | ||
[delegate didEnterDisplayState]; | ||
} | ||
} | ||
ASDisplayNodeCallInterfaceStateDelegates(didEnterDisplayState, __instanceLock__); | ||
} | ||
|
||
- (void)didExitDisplayState | ||
{ | ||
// subclass override | ||
ASDisplayNodeAssertMainThread(); | ||
ASAssertUnlocked(__instanceLock__); | ||
for (id <ASInterfaceStateDelegate> delegate in _interfaceStateDelegates) { | ||
if ([delegate respondsToSelector:@selector(didExitDisplayState)]) { | ||
[delegate didExitDisplayState]; | ||
} | ||
} | ||
ASDisplayNodeCallInterfaceStateDelegates(didExitDisplayState, __instanceLock__); | ||
} | ||
|
||
- (BOOL)isInPreloadState | ||
|
@@ -3367,23 +3352,15 @@ - (void)didEnterPreloadState | |
if (self.automaticallyManagesSubnodes) { | ||
[self layoutIfNeeded]; | ||
} | ||
|
||
for (id <ASInterfaceStateDelegate> delegate in _interfaceStateDelegates) { | ||
if ([delegate respondsToSelector:@selector(didEnterPreloadState)]) { | ||
[delegate didEnterPreloadState]; | ||
} | ||
} | ||
ASDisplayNodeCallInterfaceStateDelegates(didEnterPreloadState, __instanceLock__); | ||
} | ||
|
||
- (void)didExitPreloadState | ||
{ | ||
ASDisplayNodeAssertMainThread(); | ||
ASAssertUnlocked(__instanceLock__); | ||
for (id <ASInterfaceStateDelegate> delegate in _interfaceStateDelegates) { | ||
if ([delegate respondsToSelector:@selector(didExitPreloadState)]) { | ||
[delegate didExitPreloadState]; | ||
} | ||
} | ||
ASDisplayNodeCallInterfaceStateDelegates(didExitPreloadState, __instanceLock__); | ||
|
||
} | ||
|
||
- (void)clearContents | ||
|
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.
Since
__lock
is always the same (i.e__instanceLock__
), should we just remove the param entirely?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.
Done.