Interface VisibilityTracker
-
- All Implemented Interfaces:
public interface VisibilityTrackerInterface for tracking the visibility status of views or UI elements.
This interface provides a contract for implementing visibility tracking systems that can monitor when views become visible or hidden within the viewport. It supports reactive visibility monitoring through Flow-based event emission and provides lifecycle management for efficient resource usage.
The interface follows a standard tracking lifecycle pattern: start → pause/resume → stop, enabling battery optimization and resource management for long-running visibility monitoring operations.
Implementations should handle visibility calculations based on criteria such as viewport intersection, occlusion detection, and minimum visibility thresholds according to specific tracking requirements.
-
-
Method Summary
Modifier and Type Method Description abstract Flow<VisibilityStatus>startTracking()Starts visibility tracking and returns a flow of visibility status events. abstract Unitpause()Pauses visibility tracking while maintaining the current tracking state. abstract Unitresume()Resumes visibility tracking from a paused state. abstract Unitstop()Stops visibility tracking and releases all associated resources. -
-
Method Detail
-
startTracking
abstract Flow<VisibilityStatus> startTracking()
Starts visibility tracking and returns a flow of visibility status events.
This method initiates the visibility tracking process and returns a Flow that emits VisibilityStatus events when the tracked element's visibility state changes. The flow provides a reactive way to respond to visibility changes throughout the tracking lifecycle.
- Returns:
A Flow that emits VisibilityStatus events indicating visibility changes
-
pause
abstract Unit pause()
Pauses visibility tracking while maintaining the current tracking state.
This method temporarily suspends visibility monitoring without losing the current tracking context. It's useful for scenarios where tracking should be temporarily disabled (e.g., app backgrounding) but may be resumed later without restarting the entire tracking process.
-
resume
abstract Unit resume()
Resumes visibility tracking from a paused state.
This method restarts visibility monitoring after it has been paused, continuing from the previous tracking state. The tracking process should seamlessly continue without losing accumulated visibility data or context.
-
stop
abstract Unit stop()
Stops visibility tracking and releases all associated resources.
This method terminates the visibility tracking process completely and should clean up all resources including observers, timers, and background tasks. After calling stop, the tracker should not emit any further events and startTracking should be called to begin tracking again.
-
-
-
-