Search code examples
androidiosdelphifiremonkeydelphi-10.2-tokyo

VertScrollBox Detect when bottom reached android and IOS


I have GridLayout1 on a VertScrollBox1. The vertical scroll box scrolls through the content of the grid layout. I need to detect when the Vertical scroll box reach the bottom so I get to load more content to the grid layout. And do it again whenever bottom is reached again.

How can I achieve this?


Solution

  • Use the OnViewportPositionChange() of the VertScrollBox1. Then some simple arithmetics tell you when you are at the bottom:

    uses Math, ...;
    // ...
    
    procedure TForm1.VertScrollBox1ViewportPositionChange(Sender: TObject;
      const OldViewportPosition, NewViewportPosition: TPointF;
      const ContentSizeChanged: Boolean);
    begin
      if CompareValue(NewViewportPosition.Y, GridLayout1.Height - VertScrollBox1.Height) = EqualsValue then
        Memo1.Lines.Add('At bottom, time to grow and load more content to the GridLayout');
    end;
    

    Since the values we compare are floats, use Math.CompareValue() for comparison.

    Alternatively function SameValue(), also in the Math unit