-
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
[feat] Added download progress for NetworkImageNode #1489
[feat] Added download progress for NetworkImageNode #1489
Conversation
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.
Agree that this can come in handy in many cases. Let's work together to get this through!
Source/ASNetworkImageNode.h
Outdated
@@ -133,6 +133,13 @@ NS_ASSUME_NONNULL_BEGIN | |||
*/ | |||
@property (readonly) CGFloat renderedImageQuality; | |||
|
|||
/** | |||
* Loading progress of the current image. |
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's call it "download progress" to be a bit clearer and consistent with PINRemoteImage.
* Loading progress of the current image. | |
* Download progress of the current image. |
Source/ASNetworkImageNode.h
Outdated
@@ -133,6 +133,13 @@ NS_ASSUME_NONNULL_BEGIN | |||
*/ | |||
@property (readonly) CGFloat renderedImageQuality; | |||
|
|||
/** | |||
* Loading progress of the current image. | |||
* When downloading a network image, this value would be updated to track downloading progress. ( number between 0.0 and 1.0 ) |
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.
* When downloading a network image, this value would be updated to track downloading progress. ( number between 0.0 and 1.0 ) | |
* When downloading a network image, this value would be updated to track download progress (value between 0 and 1) |
Source/ASNetworkImageNode.h
Outdated
/** | ||
* Loading progress of the current image. | ||
* When downloading a network image, this value would be updated to track downloading progress. ( number between 0.0 and 1.0 ) | ||
* If the URL is unset, this is 1.0 if defaultImage or image is set to non-nil. |
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.
* If the URL is unset, this is 1.0 if defaultImage or image is set to non-nil. | |
* If the URL is unset, this is 1 if defaultImage or image is set to non-nil. |
Source/ASNetworkImageNode.mm
Outdated
return ASLockedSelf(_loadingProgress); | ||
} | ||
|
||
- (void)_locked_setLoadingProgress:(CGFloat)loadingProgress |
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's add an explanation why we're dispatching to the main queue here. Something similar to what _setCurrentImageQuality
has.
Source/ASNetworkImageNode.mm
Outdated
return ASLockedSelf(_loadingProgress); | ||
} | ||
|
||
- (void)_locked_setLoadingProgress:(CGFloat)loadingProgress |
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.
- (void)_locked_setLoadingProgress:(CGFloat)loadingProgress | |
- (void)_setDownloadProgress:(CGFloat)downloadProgress |
Source/ASNetworkImageNode.h
Outdated
* When downloading a network image, this value would be updated to track downloading progress. ( number between 0.0 and 1.0 ) | ||
* If the URL is unset, this is 1.0 if defaultImage or image is set to non-nil. | ||
*/ | ||
@property (readonly) CGFloat loadingProgress; |
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.
@property (readonly) CGFloat loadingProgress; | |
@property (readonly) CGFloat downloadProgress; |
@nguyenhuy I renamed to |
Source/ASNetworkImageNode.mm
Outdated
if (strongSelf == nil) { | ||
return; | ||
} | ||
[strongSelf _updateDownloadedProgress:progress downloadIdentifier:downloadIdentifier]; |
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 this is a bit more concise.
if (strongSelf != nil) {
[strongSelf _updateDownloadedProgress:progress downloadIdentifier:downloadIdentifier];
}
Source/ASNetworkImageNode.mm
Outdated
@@ -768,6 +817,7 @@ - (void)_lazilyLoadImageIfNecessary | |||
UIImage *newImage; | |||
if (imageContainer != nil) { | |||
[strongSelf _setCurrentImageQuality:1.0]; | |||
[self _setDownloadProgress:1.0]; |
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 the only remaining blocker for this PR!
[self _setDownloadProgress:1.0]; | |
[strongSelf _setDownloadProgress:1.0]; |
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.
😢 Seems I just do the copied. Thanks! 👍
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.
LGTM now. Thanks for the contribution!
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.
Will land as soon as you address these last nits.
Source/ASNetworkImageNode.h
Outdated
/** | ||
* Download progress of the current image. | ||
* When downloading a network image, this value would be updated to track download progress (value between 0 and 1) | ||
* If the URL is unset, this is 1 if defaultImage or image is set to non-nil. |
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.
If the URL is unset, this is 1 if defaultImage or image is set to non-nil.
This line is not true for download progress because the progress should be 0 (set here).
Source/ASNetworkImageNode.mm
Outdated
} | ||
|
||
/** | ||
* Always use these methods internally to update the current image quality |
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.
* Always use these methods internally to update the current image quality | |
* Always use these methods internally to update the current download progress |
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.
Nice catch! Thanks! 👍
@nguyenhuy Done. |
Currently, seems we don't have any property to observe download progress, it's useful for user who can handle progress things(like progress indicator) by observing download progress.