-
Notifications
You must be signed in to change notification settings - Fork 728
Visibility Events
Eli Hart edited this page Oct 12, 2018
·
7 revisions
Since 2.19.0
Epoxy supports notifying callbacks when views scroll on and off of the screen. Visibility state is defined with these terms.
- Visible: Triggered when at least one pixel of the view is visible.
- Invisible: Triggered when the view no longer has any pixels on the screen.
- Focused: Event: Triggered when either the view occupies at least half of the viewport, or, if the view is smaller than half the viewport, when it is fully visible.
- Unfocused Visible: Triggered when the view is no longer focused, i.e. it is not fully visible and does not occupy at least half the viewport.
- Full Impression Visible: Triggered when the entire view has passed through the viewport at some point.
There are two ways to register visibility listeners.
OnModelVisibilityStateChangedListener - This notifies you when the visibility state of the view changes, such as going from invisible to visible.
OnModelVisibilityChangedListener - This is a more granular callback that tells you exactly how much of the view is visible on screen.
There are several ways to register callbacks for the two visibility interfaces.
When you instantiate a generated model and set your data on it you can register visibility listeners for that specific model instance
new MyModel_()
.id("my id")
.onVisibilityChanged { model, view, visibilityState ->
// Do something with the new visibility state
}
.onVisibilityStateChanged { model, view, percentVisibleHeight, percentVisibleWidth, visibleHeight, visibleWidth ,view ->
// Do something with the visibility information
}