Skip to content

Architecture

Naveen Chaudhary edited this page Sep 22, 2020 · 1 revision

Each view decides whether it should be tracked and can set different viewability conditions to listen to.

There is a single API exposed to track any view. So when you call trackView() from any view, a ViewTracker is attached to the view which keeps a track of the current viewability percentage of the view

Whenever there is a change in viewability percentage, the ViewTracker asks all the ViewConditions attached to the view to evaluate() themselves.


Architecture


The view tracker creates a graph structure of all the trackable views and uses it to update the viewability of children when there is a change in the parent.

To calculate and update the percentage viewability of a view, the ViewTracker relies on KVO on its frame and the contentOffset of the parent scroll view.

The tracker also gets notified by some swizzled lifecycle events of UIView and UIViewController to effectively manage and update the viewability percentage.

Clone this wiki locally