-
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
Add a method for setting preconfigured PINRemoteImageManager #1124
Add a method for setting preconfigured PINRemoteImageManager #1124
Conversation
…of using the self-created ASPINRemoteImageManager
@@ -155,9 +159,18 @@ + (PINRemoteImageManager *)sharedPINRemoteImageManagerWithConfiguration:(NSURLSe | |||
|
|||
- (PINRemoteImageManager *)sharedPINRemoteImageManager | |||
{ | |||
if (_preconfiguredPINRemoteImageManager) { |
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.
Is this thread safe? Do we have to lock this?
return [ASPINRemoteImageDownloader sharedPINRemoteImageManagerWithConfiguration:nil]; | ||
} | ||
|
||
- (PINRemoteImageManager *)setPreconfiguredPINRemoteImageManager:(PINRemoteImageManager *)preconfiguredPINRemoteImageManager | ||
{ | ||
_preconfiguredPINRemoteImageManager = preconfiguredPINRemoteImageManager; |
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.
I think we should add a lock here. Furthermore why do we return the same object here and od not make it a regular setter?
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.
Actually, I was going to make it return a void since it is setting.
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.
Let me make it thread safe.
It's a valid concern that the new addition should be thread-safe. However, I'm not sure about adding a lock around How about we use the same pattern as |
The suggestion from @nguyenhuy sounds good to me. |
🚫 CI failed with log |
@nguyenhuy Shouldn't Texture knows nothing about the custom image manager except it is a subclass of PINRemoteImageMager to keep the abstraction? The subclass is in a higher level app/library. |
@ernestmama Yes, and with the new API, it still wouldn't know anything, does it? |
@nguyenhuy How about this update? This will essentially change that the RemoteImageManager can only be set once (same as previous with configuration) instead of able to swapping it in runtime. It will need to be set before the first time ImageManager is being used. |
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.
Yeah, that's a better idea.
* Sets a custom perconconfigured PINRemoteImageManager that will be used by @c ASNetworkImageNodes and @c ASMultiplexImageNodes | ||
* while loading images off the network. This must be specified early in the application lifecycle before | ||
* `sharedDownloader` is accessed. If nil is passed in as the PINRemoteImageManager, it will call | ||
* setSharedImageManagerWithConfiguration with nil configuration. |
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.
it will call setSharedImageManagerWithConfiguration with nil configuration.
Does it? How about:
it will create a default image manager with a
nil
session configuration.
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.
You are rrright.
…image manager can be set at a time
…image manager can be set at a time
…image manager can be set at a time
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.
Nearly there.
Also, this diff is not trivial. It introduces a new API, please update changelog.
|
||
+ (PINRemoteImageManager *)sharedPINRemoteImageManagerWithConfiguration:(NSURLSessionConfiguration *)configuration preconfiguredPINRemoteImageManager:(PINRemoteImageManager *)preconfiguredPINRemoteImageManager | ||
{ | ||
NSAssert(configuration != nil && preconfiguredPINRemoteImageManager != nil, @"Either configuration or preconfigured image manager can be set at a time."); |
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 assertion means both configuration and preconfigured manager must not be nil. I don't think it's right.
dispatch_once(&onceToken, ^{ | ||
|
||
if (preconfiguredPINRemoteImageManager) { | ||
sharedPINRemoteImageManager = preconfiguredPINRemoteImageManager; | ||
} else { | ||
#if PIN_ANIMATED_AVAILABLE | ||
// Check that Carthage users have linked both PINRemoteImage & PINCache by testing for one file each | ||
if (!(NSClassFromString(@"PINRemoteImageManager"))) { |
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.
The indentation seems to be off. The whole else body here should be indented.
…RemoteImageManager (TextureGroup#1124) * add a method for setting preconfigured PINRemoteImageManager instead of using the self-created ASPINRemoteImageManager * update preconfigured image manager where it can only be set once * fix spacing in downloader * Fix doc/comments on new api * adding assertion to ensure either only configuration or preconfigure image manager can be set at a time * adding assertion to ensure either only configuration or preconfigure image manager can be set at a time * fix assertion condition * Update CHANGELOG.md * Remove unnecessary change
Add a method for setting preconfigured PINRemoteImageManager instead of using the self-created ASPINRemoteImageManager.
In this way, we can add custom configuration to the PINRemoteImageManager such as request configuration/url configuration.