onVisibilityChanged method

void onVisibilityChanged(
  1. VisibilityInfo info
)

Implementation

void onVisibilityChanged(VisibilityInfo info)
{
  if (oldVisibility == (info.visibleFraction * 100)) return;

  visibleHeight = info.size.height > 0 ? ((info.visibleBounds.height / info.size.height) * 100) : 0.0;
  visibleWidth  = info.size.width  > 0 ? ((info.visibleBounds.width  / info.size.width)  * 100) : 0.0;
  visibleArea   = info.visibleFraction * 100;

  oldVisibility = visibleArea ?? 0.0;

  if (visibleArea! > 1 && !hasGoneOnscreen)
  {
    if (!S.isNullOrEmpty(_onscreen)) EventHandler(this).execute(_onscreen);
    hasGoneOnscreen = true;
  }
  else if (visibleArea! == 0 && hasGoneOnscreen)
  {
    if (!S.isNullOrEmpty(_offscreen)) EventHandler(this).execute(_offscreen);
    hasGoneOnscreen = false;
  }
}