-
public final class EpoxyVisibilityTrackerA simple way to track visibility events on com.airbnb.epoxy.EpoxyModel.
EpoxyVisibilityTracker works with any androidx.recyclerview.widget.RecyclerView backed by an Epoxy controller. Once attached the events will be forwarded to the Epoxy model (or to the Epoxy view when using annotations).
Note that support for visibility events on an EpoxyModelGroup is somewhat limited. Only model additions will receive visibility events. Models that are removed from the group will not receive events (e.g. VisibilityState.INVISIBLE) because the model group does not keep a reference, nor does it get notified of model removals.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classEpoxyVisibilityTracker.Companion
-
Field Summary
Fields Modifier and Type Field Description private BooleanonChangedEnabledprivate IntegerpartialImpressionThresholdPercentage
-
Constructor Summary
Constructors Constructor Description EpoxyVisibilityTracker()
-
Method Summary
Modifier and Type Method Description final BooleangetOnChangedEnabled()Enable or disable visibility changed event. final UnitsetOnChangedEnabled(Boolean onChangedEnabled)Enable or disable visibility changed event. final IntegergetPartialImpressionThresholdPercentage()Set the threshold of percentage visible area to identify the partial impression view state. final UnitsetPartialImpressionThresholdPercentage(@IntRange(from = 0.toLong(), to = 100.toLong()) Integer partialImpressionThresholdPercentage)Set the threshold of percentage visible area to identify the partial impression view state. final Unitattach(RecyclerView recyclerView)Attach the tracker. final Unitdetach(RecyclerView recyclerView)Detach the tracker final UnitclearVisibilityStates()The tracker is storing visibility states internally and is using if to send events, only the difference is sent. final UnitrequestVisibilityCheck()Calling this method will make the visibility tracking check and trigger events if necessary. -
-
Method Detail
-
getOnChangedEnabled
final Boolean getOnChangedEnabled()
Enable or disable visibility changed event. Default is
true, disable it if you don't need (triggered by every pixel scrolled).
-
setOnChangedEnabled
final Unit setOnChangedEnabled(Boolean onChangedEnabled)
Enable or disable visibility changed event. Default is
true, disable it if you don't need (triggered by every pixel scrolled).
-
getPartialImpressionThresholdPercentage
final Integer getPartialImpressionThresholdPercentage()
Set the threshold of percentage visible area to identify the partial impression view state.
-
setPartialImpressionThresholdPercentage
final Unit setPartialImpressionThresholdPercentage(@IntRange(from = 0.toLong(), to = 100.toLong()) Integer partialImpressionThresholdPercentage)
Set the threshold of percentage visible area to identify the partial impression view state.
- Parameters:
partialImpressionThresholdPercentage- Percentage of visible area of an element in the range 0..
-
attach
final Unit attach(RecyclerView recyclerView)
Attach the tracker.
- Parameters:
recyclerView- The recyclerview that the EpoxyController has its adapter added to.
-
detach
final Unit detach(RecyclerView recyclerView)
Detach the tracker
- Parameters:
recyclerView- The recycler view that the EpoxyController has its adapter added to.
-
clearVisibilityStates
final Unit clearVisibilityStates()
The tracker is storing visibility states internally and is using if to send events, only the difference is sent. Use this method to clear the states and thus regenerate the visibility events. This may be useful when you change the adapter on the RecyclerView.
-
requestVisibilityCheck
final Unit requestVisibilityCheck()
Calling this method will make the visibility tracking check and trigger events if necessary. It is particularly useful when the visibility of an Epoxy model is changed outside of an Epoxy RecyclerView.
An example is when you nest an horizontal Epoxy backed RecyclerView in a non Epoxy vertical RecyclerView. When the vertical RecyclerView scroll you want to notify the visibility tracker attached on the horizontal RecyclerView.
-
-
-
-