[ASNetworkImageNode] Assert if both URL and image are set#2782
[ASNetworkImageNode] Assert if both URL and image are set#2782garrettmoon merged 4 commits intofacebookarchive:masterfrom
Conversation
| @property (nullable, nonatomic, strong) UIImage *ephemeralImage; | ||
|
|
||
| //Because this is ephemeral, you shouldn't rely on its contents | ||
| - (UIImage *)ephemeralImage NS_UNAVAILABLE; |
There was a problem hiding this comment.
Is this the cleanest way to make a write only property?
|
@maicki definitely want your feedback on this. |
|
I think it's an interesting idea, but I have the fear that this will add even more confusion. Now we have |
|
Here's my feedback, although I don't intend for it to be definitive — I'm interested in understanding what behavior @maicki would prefer we support. 1. The internal complexity of ASNetworkImageNode
2. There are exactly 3 cases to consider ASNetworkImageNode with:Note that in the last case (both are set), we must provide identical behavior regardless of call order — therefore, regardless of implementation complexity, the decision on API behavior is only for the "both" case and doesn't care about the order. a. Just .URLThis behavior is simple. It should not change from the prior implementation. If externally read, the .image property will become set after the URL has loaded. Likewise, the rendered version will be cleared when exiting the Display range, and the .image property itself will be cleared existing the Preload range. b. Just .imageThis behavior is also simple, but doesn't work correctly in 2.0. When just the .image is set and .URL is never set, the class should behave like ASImageNode. Why? Several reasons:
c. Both .URL and .image.The case of BOTH .URL and .image set is less clear. However, the case is clarified by seeing there are only two reasons a user would do this:
So lastly, this diff is a suggestion from @garrettmoon for how to make 2c. less ambiguous while still being VERY strict at preventing developers from mistakenly entering the "2c2" case. The idea is that this will behave functionally identical to "it's not allowed to set both URL and .image on a Network node", but provide users a technically-possible way to support the commonly-useful pattern of "priming" a network image node. 3. To make this call (which would increase impl. complexity), let's look at the use caseWhat's causing this to be so important? It's transitions that upscale photos, including the exact case @rcancro is working on right now with Pin Closeup's standard zoom-in. Por these, it is essential to support upscaling a low-res photo while immediately kicking off a new high-res download, as well as async-displaying the new version, as well as swapping in the high-res version as soon as it's done, in a seamless way. This behavior is super useful because it is so hard to handle at an application layer. This was a very, very key use case that AsyncDisplayKit was architected to excel at in the pre-1.0 days, with ASMultiplexImageNode bearing the complexity of the use case. However, Multiplex has fallen into non-maintenance, and so we have two paths to choose at this point:
Thanks for reading a long note, hope this was useful to the discussion :) |
|
As already discussed extensively with @garrettmoon my thoughts around the behavior of each of the cases for an a. Just .URLAgree with @appleguy ... no changes: This behavior is simple. It should not change from the prior implementation. If externally read, the .image property will become set after the URL has loaded. Likewise, the rendered version will be cleared when exiting the Display range, and the .image property itself will be cleared existing the Preload range. b. Just .imageAgree with @appleguy: This behavior is also simple, but doesn't work correctly in 2.0. When just the .image is set and .URL is never set, the class should behave like ASImageNode. c. Both .URL and .image will be setIn the case that a client set's an URL and an image it's less clear, but the thinking is to reduce the state and the side effects it can have it should actually work this:
Why this behavior?Imho, the behavior above is clear to describe as well hopefully reduces side effects for all kinds of quirks that can happen and added complexity we have to implement in case we want to support setting and SummaryTo summarize the states:
|
|
Awesome discussion! So it sounds like we're all in agreement on adding the assert. And I've done a bunch of cleanup in Pinterest and essentially added the feature on our side to mimic ephemeralImage. So I'm going to pull that bit out of this PR. Thank you both for your feedback! |
|
@garrettmoon Sorry to bother, but could you rebase this when you have time and we'll land it? |
5380fd6 to
dfbcd82
Compare
Here's one other idea for addressing this problem. Essentially, we assert if you've set both the URL and the image. I've played around with Pinterest and there's only one case where we hit this (the transition). So I've also added another method (which is a bummer, it's weird I know) but there's one good reason to add this method, ephemeralImage, which is the user doesn't have to manually clear it out like they would if they used defaultImage to save memory. Putting this up for discussion.
dfbcd82 to
d355539
Compare
Here's one other idea for addressing this problem. Essentially,
we assert if you've set both the URL and the image. I've played around
with Pinterest and there's only one case where we hit this (the transition).
So I've also added another method (which is a bummer, it's weird I know)
but there's one good reason to add this method, ephemeralImage, which is
the user doesn't have to manually clear it out like they would if they
used defaultImage to save memory.
Putting this up for discussion.