-
Notifications
You must be signed in to change notification settings - Fork 728
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
Introduce partial impression visibility states #973
Conversation
@@ -82,6 +83,8 @@ private static void setTracker( | |||
|
|||
private boolean onChangedEnabled = true; | |||
|
|||
private int partialImpressionThresholdPercentage = 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.
should it default to something, or default to null in which case handlePartialImpressionVisible
is not called?
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.
Good point. Let's default to null
and not call the method as you described.
Only question is if there should be a separate method from setPartialImpressionThresholdPercentage
then to disable partial threshold (and internally set to null) or if setPartialImpressionThresholdPercentage
should accept a nullable Integer
instead of simple int
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 guess I see that it shortcircuits to doing nothing when set to 0, in which case the listeners are never called. i think this is a little confusing since a threshold of 0
seems like it would always trigger it to be called. maybe use -1 or null instead?
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 other idea is to just not call handlePartialImpressionVisible
in case of 0
Saw your update now. Good point about 0
as a threshold that should always trigger.
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 using -1 to disable the events, would you prefer a separate method to disable the events then in regards to public API? Or just annotate setPartialImpressionThresholdPercentage
's parameter with @IntRange(from = -1, to = 100) (seems a bit odd). I guess null
is better in that case.
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.
A value of 0
remains a special case, as it would have to fire if at least one pixel of the element is visible on the screen (would act the same as VISIBLE
).
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.
How about 0b6c6c2
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.
How about @IntRange(from = 1, to = 99)
, possible values would be null
or any int
from 1 to 99
Btw, if we have 100
we could use the full impression event so 100
is not really needed.
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 would leave this decision to you as the maintainers of the library as it is more about the public API and what is expected here.
for sure the extremes will basically duplicate existing events:
0
acts likeVISIBLE
100
acts likeFULL_IMPRESSION_VISIBLE
(with an added_INVISIBLE
state)
I think having the full range from 0 to 100 grew on me. I think of it this way: If other visibility events were to drop out and be removed, this one should still be fully functional and in that case 0 and 100 are valid use cases.
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 don't have a strong opinion on it and since you handle 0
and 100
having @IntRange(from = 0 to = 100)
is fine.
@@ -100,6 +103,19 @@ public void setOnChangedEnabled(boolean enabled) { | |||
onChangedEnabled = enabled; | |||
} | |||
|
|||
/** | |||
* Set the threshold of percentage visible area to identify the partial impression view state. |
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.
maybe note that the default makes partial impression events never called?
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.
adressed also in 0b6c6c2
b6d43a5
to
0b6c6c2
Compare
@@ -687,6 +882,7 @@ class EpoxyVisibilityTrackerTest { | |||
fun setup() { | |||
Robolectric.setupActivity(Activity::class.java).apply { | |||
setContentView(EpoxyRecyclerView(this).apply { | |||
epoxyVisibilityTracker.setPartialImpressionThresholdPercentage(50) |
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.
That's nice to update all the tests with a partialImpressionThresholdPercentage
value !
I would have let the existing tests as "it is" and added more test to validate the different partialImpressionThresholdPercentage
scenarios.
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 why I asked about the test matrix. If necessary, I can write some code to dupe the cases once with and once without partial imps.
As for tests, since setting the threshold will add a new dimension to the test matrix, I was not sure if I should adjust the whole testsuite to cope for this. Basically all of
testDataAttachedToRecyclerView, testScrollToPosition, testMoveDataDown, testInsertData, testScrollBy, testDeleteData, testMoveDataUp
could be tested once with a threshold set, and once without.
kotlinsample/src/main/java/com/airbnb/epoxy/kotlinsample/models/OnVisibilityEventDrawable.kt
Show resolved
Hide resolved
* {@link VisibilityState#PARTIAL_IMPRESSION_VISIBLE} events. | ||
*/ | ||
public void setPartialImpressionThresholdPercentage( | ||
@IntRange(from = 0, to = 100) int thresholdPercentage |
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 am wondering if 0
should be considered as null
. Is it even a valid threshold for this use case?
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.
See this discussion
#973 (comment)
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.
Looks good to me, 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.
great, thanks for this addition :) I'll make a release with it soon
fixes #838
PARTIAL_IMPRESSION_VISIBLE
andPARTIAL_IMPRESSION_INVISIBLE
visibility statesEpoxyVisibilityTracker#setPartialImpressionThresholdPercentage
FULL_IMPRESSION_VISIBLE
:kotlinsample
to reflect the additionTests
<
instead of<=
As for tests, since setting the threshold will add a new dimension to the test matrix, I was not sure if I should adjust the whole testsuite to cope for this. Basically all of
testDataAttachedToRecyclerView, testScrollToPosition, testMoveDataDown, testInsertData, testScrollBy, testDeleteData, testMoveDataUp
could be tested once with a threshold set, and once without.
Please let me know if I should cope for this.
Wiki Content Suggestion
Visibility Events
at least the specified threshold. This threshold can be set via
EpoxyVisibilityTracker#setPartialImpressionThresholdPercentage
. This event does not fire if the threshold is set tonull
or if the threshold cannot be met due to the element being larger than the viewport and the set threshold too high.no longer at least the specified threshold. Also see Partial Impression Visible.