Get access to over 100 FireMonkey cross platform samples for Android, IOS, OSX, Windows, and Linux!

AndroidAppmethodCode SnippetComponentDelphiDemoFiremonkeyIOS

Keep Controls Visible When Virtual Keyboard Pops Up In Firemonkey On Android And IOS

| Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOS

Virtual Keyboard Control Focus Delphi XE5 Firemonkey | Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOS

If you’re building any kind of Delphi XE5 Firemonkey mobile app that has input controls you have probably run into the problem of the virtual keyboard hiding the edit controls underneath itself. There are a few different solutions to this problem but some of the best ones support the multiline TMemo as well. I believe all of the solutions work cross platform in Delphi XE5 Firemonkey for Android and IOS. You can find two solutions from David Nottage and Mike Sutton in this Embarcadero forum post from September 2013. David Nottage also wrote a blog post about his solution which comes with demo source code. David’s solution has been put into a component called TControlMover you can easily add to any of your projects. Here is a sample from his component:
procedure TControlMover.FormVirtualKeyboardHidden(Sender: TObject; KeyboardVisible: Boolean; const Bounds: TRect);
begin
FVKVisible := False;
if Assigned(FSaveProps.Control) then
begin
FSaveProps.Control.AnimateFloat('Position.Y', FSaveProps.Position.Y, 0.1);
FSaveProps.Control.Align := FSaveProps.Align;
end;
end;

procedure TControlMover.FormVirtualKeyboardShown(Sender: TObject; KeyboardVisible: Boolean; const Bounds: TRect);
begin
FVKVisible := True;
FVKBounds := Bounds;
if FocusedControl = nil then
Exit;
DoGetMoveControl;
if Assigned(FSaveProps.Control) then
begin
FSaveProps.Control.Align := TAlignLayout.alNone;
FSaveProps.Position.Y := FSaveProps.Control.Position.Y;
SlideControl;
end;
end;

There is a problem on IOS where the Bounds rectangle is reported incorrectly when in landscape mode. You can get the correct bounds rectangle using code found on this QC entry. Lastly, there is a ScrollableForm demo available from Embarcadero. Here is a sample of the source from the ScrollableForm demo:
procedure TFormMain.FormVirtualKeyboardHidden(Sender: TObject;
KeyboardVisible: Boolean;
const Bounds: TRect);
begin
FKBBounds.Create(0, 0, 0, 0);
FNeedOffset := False;
RestorePosition;
end;

procedure TFormMain.FormVirtualKeyboardShown(Sender: TObject;
KeyboardVisible: Boolean;
const Bounds: TRect);
begin
FKBBounds := TRectF.Create(Bounds);
FKBBounds.TopLeft := ScreenToClient(FKBBounds.TopLeft);
FKBBounds.BottomRight := ScreenToClient(FKBBounds.BottomRight);
UpdateKBBounds;
end;

Head over and get the full source to the TControlMover component and demo.

close

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Related posts
DelphiFiremonkeyShowcaseWindows

How To Build Stable Diffusion Text To Image Prompts

AndroidC++BuilderDelphiFiremonkeyIOSOSXWindows

FireMonkey 10.4.2 Features Updated iOS 14, Android 11, And macOS 11 Support Plus Hundreds Of Fixes

DelphiIDEShowcaseWindows

Ryzen 9 5950x: One Billion Lines Of Delphi Code Compiled In ~5 Minutes On 16 Cores

DelphiFiremonkeyIDEIOSOSXWindows

DelphiCon 2020 FireMonkey Sessions Available Starting November 19

Sign up for our Newsletter and
stay informed

8 Comments

Leave a Reply to Harald Cancel reply