Skip to content

Delphi/FMX component for displaying customizable toast notifications, handles display over native controls.

License

Notifications You must be signed in to change notification settings

MEStackCodes/Delphi.FMX.UIToast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FMX.UIToast

Delphi/FMX component for displaying customizable, non-intrusive alert notifications. It's ideal for providing feedback to users, such as confirming an action (e.g., "Message sent"), displaying alerts (e.g., "Network error"), or displaying other brief messages without interrupting the user's workflow.

✨ Features

  • Pure FMX Code, all FireMonkey-compatible platforms.
  • Highly Customizable: Easily modify text, colors, fonts, borders, corner radius, opacity, and more.
  • Predefined Styles: Use built-in styles for common notification types like Success, Warning, and Danger.
  • Flexible Positioning: Display toasts at the top, bottom, or center of any parent control.
  • Animation Control: Choose between fade, slide, or no animation, with customizable transition speeds.
  • Z-Order Support: Properly handles display over native controls using the ControlType property.
  • Responsive Sizing: Automatically adjusts its width based on the parent control's orientation (landscape/portrait).

🚀 Getting Started

Installation

  1. Add the FMX.UIToast.pas unit to your project's search path.
  2. Include the unit in the uses clause of the form or frame where you want to display the toast.
  3. Set a var & create an instance of TUIToast on FormCreate Event;
uses
  ..., FMX.UIToast;

var
MyToast: TUIToast;

procedure TMyForm.Create(Sender: TObject);
begin
 MyToast:= TUIToast.Create(Self);
end;

Basic Usage

To show a toast, set its properties, and call the Show method. The Show method requires a parent TFMXObject (like a TForm or a TLayout) where the toast will be rendered.

procedure TMyForm.ShowSimpleToastClick(Sender: TObject);
begin  
    MyToast.Text := 'This is a simple toast message!';
    MyToast.Show(Self); // 'Self' is the TForm  
end;

🎨 Customization & Examples

FMX.UIToast offers a wide range of properties to tailor the appearance and behavior of your notifications.

Using Predefined Color Styles

You can quickly apply a style using the ToastColorType property. This automatically sets the background and font colors.

procedure TMyForm.ShowSuccessToastClick(Sender: TObject);
begin
    // Use a predefined style
    MyToast.ToastColorType := TToastType.Success;
    MyToast.Text := 'Operation completed successfully!';
    MyToast.Show(Self);
end;

Advanced Customization

Here is an example demonstrating various properties to create a fully custom toast notification.

procedure TMyForm.ShowCustomToastClick(Sender: TObject);
begin
    MyToast.Text := 'This is a custom toast.';
    MyToast.BackColor := TAlphaColors.Blue;
    MyToast.FontColor := TAlphaColors.White;
    MyToast.FontSize := 18;
    MyToast.CornerRadius := 24;
    MyToast.BorderColor := TAlphaColors.Lightblue;
    MyToast.BorderWidth := 2;
    MyToast.Position := TToastPosition.tpTop; // Display at the top
    MyToast.Animation := TToastAnimation.taSlide; // Slide-in animation
    MyToast.Duration := 3.5; // Stays visible for 3.5 seconds
    MyToast.Transition := 0.5; // Animation takes 0.5 seconds
    MyToast.Margin.Top := 50; // Extra margin from the top
    MyToast.Show(Self);
end;

📚 API Reference

The main class is TUIToast, which contains all the necessary properties and methods to configure and display notifications.

Properties

Property Type Description
Text string The message content to be displayed inside the toast.
BackColor TAlphaColor The background color of the toast.
FontColor TAlphaColor The text color.
FontSize Single The font size of the text.
ToastColorType TToastColorRec A predefined style record (Success, Warning, Danger, Dark, Light) that sets BackColor and FontColor together.
Duration Single The time in seconds that the toast remains visible on screen after its entrance animation is complete.
Transition Single The time in seconds for the entrance and exit animations (fade or slide) to complete.
Animation TToastAnimation The animation type: taFade (default), taSlide, or taNone.
Position TToastPosition The vertical position on the parent control: tpTop, tpBottom (default), or tpCenter.
CornerRadius Single The radius for the rounded corners of the toast background.
BorderColor TAlphaColor The color of the border around the toast.
BorderWidth Single The thickness of the border.
Opacity Single The overall opacity of the toast (from 0.0 to 1.0).
Margin TBounds The outer margins to position the toast relative to the parent control's edges.
ToastHeight Single The fixed height of the toast control.
TextAlign TTextAlign The horizontal alignment of the text: Center (default), Leading, or Trailing.
ControlType TControlType Determines rendering mode. Use Platform to ensure the toast is correctly displayed on top of native controls, resolving Z-order issues. Use Styled for standard FMX controls.

Methods

Method Description
Show(AParent: TFMXObject) Renders and displays the toast on the specified parent component (TForm, TLayout, TPanel, etc.).

About

Delphi/FMX component for displaying customizable toast notifications, handles display over native controls.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages