internal void Show(Forms.Page page, SnackBarOptions arguments)
        {
            var snackBarLayout = new SnackBarLayout(arguments);
            var pageControl    = Platform.GetRenderer(page).ContainerElement.Parent;
            var grid           = FindVisualChildByName <Border>(pageControl, "BottomCommandBarArea").Parent as Grid;
            var snackBarRow    = new RowDefinition()
            {
                Height = GridLength.Auto
            };

            snackBarTimer = new DispatcherTimer {
                Interval = arguments.Duration
            };
            snackBarTimer.Tick += (sender, e) =>
            {
                grid.Children.Remove(snackBarLayout);
                grid.RowDefinitions.Remove(snackBarRow);
                snackBarTimer.Stop();
                arguments.SetResult(false);
            };
            snackBarLayout.OnSnackBarActionExecuted += () =>
            {
                grid.Children.Remove(snackBarLayout);
                grid.RowDefinitions.Remove(snackBarRow);
                snackBarTimer.Stop();
                arguments.SetResult(true);
            };
            snackBarTimer.Start();
            grid.RowDefinitions.Add(snackBarRow);
            grid.Children.Add(snackBarLayout);
            Grid.SetRow(snackBarLayout, grid.RowDefinitions.Count - 1);
        }
Ejemplo n.º 2
0
        internal void Show(Page sender, SnackBarOptions arguments)
        {
            var view         = Platform.GetRenderer(sender).View;
            var snackBar     = AndroidSnackBar.Make(view, arguments.MessageOptions.Message, (int)arguments.Duration.TotalMilliseconds);
            var snackBarView = snackBar.View;

            snackBarView.SetBackgroundColor(arguments.BackgroundColor.ToAndroid());

            var snackTextView = snackBarView.FindViewById <TextView>(Resource.Id.snackbar_text);

            snackTextView.SetMaxLines(10);
            snackTextView.SetBackgroundColor(arguments.MessageOptions.Foreground.ToAndroid());
            snackTextView.SetTextSize(ComplexUnitType.Pt, (float)arguments.MessageOptions.FontSize);
            snackTextView.LayoutDirection = arguments.IsRtl
                                ? global::Android.Views.LayoutDirection.Rtl
                                : global::Android.Views.LayoutDirection.Inherit;

            foreach (var action in arguments.Actions)
            {
                snackBar.SetAction(action.Text, async v => await action.Action());
                snackBar.SetActionTextColor(action.ForegroundColor.ToAndroid());
            }

            snackBar.AddCallback(new SnackBarCallback(arguments));
            snackBar.Show();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Display snackbar with the default visual configuration
        /// </summary>
        /// <param name="visualElement">Anchor element</param>
        /// <param name="message">Text of the snackbar</param>
        /// <param name="actionButtonText">Text of the snackbar button</param>
        /// <param name="action">Action of the snackbar button</param>
        /// <param name="duration">Snackbar duration</param>
        /// <returns>True if snackbar action is executed. False if snackbar is closed by timeout</returns>
        public static async Task <bool> DisplaySnackBarAsync(this VisualElement visualElement, string message, string actionButtonText, Func <Task> action, TimeSpan?duration = null)
        {
            _ = visualElement ?? throw new ArgumentNullException(nameof(visualElement));

            var messageOptions = new MessageOptions {
                Message = message
            };
            var actionOptions = new List <SnackBarActionOptions>
            {
                new ()
                {
                    Text = actionButtonText, Action = action
                }
            };
            var options = new SnackBarOptions
            {
                MessageOptions = messageOptions,
                Duration       = duration ?? TimeSpan.FromSeconds(3),
                Actions        = actionOptions,
#if NETSTANDARD1_0
                IsRtl = false,
#else
                IsRtl = CultureInfo.CurrentCulture.TextInfo.IsRightToLeft,
#endif
            };
            var snackBar = new SnackBar();
            await snackBar.Show(visualElement, options);

            var result = await options.Result.Task;

            return(result);
        }
Ejemplo n.º 4
0
        internal void Show(Page sender, SnackBarOptions arguments)
        {
#if __IOS__
            var snackBar = IOSSnackBar.MakeSnackBar(arguments.MessageOptions.Message)
#elif __MACOS__
            var snackBar = MacOSSnackBar.MakeSnackBar(arguments.MessageOptions.Message)
#endif
                           .SetDuration(arguments.Duration)
                           .SetTimeoutAction(() =>
            {
                arguments.SetResult(false);
                return(Task.CompletedTask);
            });

#if __IOS__
            if (!UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
                var renderer = Platform.GetRenderer(sender);
                snackBar.SetParentController(renderer.ViewController);
            }
#endif

            foreach (var action in arguments.Actions)
            {
                snackBar.SetActionButtonText(action.Text);
                snackBar.SetAction(async() =>
                {
                    snackBar.Dismiss();
                    await action.Action();
                    arguments.SetResult(true);
                });
            }

            snackBar.Show();
        }
Ejemplo n.º 5
0
        public static async Task <bool> DisplaySnackBarAsync(this Page page, string message, string actionButtonText, Func <Task> action, int durationMilliseconds = 3000)
        {
            _ = page ?? throw new ArgumentNullException(nameof(page));

            var messageOptions = new MessageOptions {
                Message = message
            };
            var actionOptions = new List <SnackBarActionOptions>
            {
                new SnackBarActionOptions
                {
                    Text = actionButtonText, Action = action
                }
            };
            var options = new SnackBarOptions
            {
                MessageOptions = messageOptions,
                Duration       = TimeSpan.FromMilliseconds(durationMilliseconds),
                Actions        = actionOptions,
#if NETSTANDARD1_0
                IsRtl = false,
#else
                IsRtl = CultureInfo.CurrentCulture.TextInfo.IsRightToLeft,
#endif
            };
            var snackBar = new SnackBar();
            await snackBar.Show(page, options);

            var isButtonClicked = await options.Result.Task;

            return(isButtonClicked);
        }
Ejemplo n.º 6
0
        internal partial ValueTask Show(Forms.VisualElement visualElement, SnackBarOptions arguments)
        {
            var formsAppBar    = System.Windows.Application.Current.MainWindow.FindChild <FormsAppBar>("PART_BottomAppBar");
            var currentContent = formsAppBar.Content;
            var snackBar       = new SnackBarLayout(arguments);

            snackBarTimer = new Timer {
                Interval = (int)arguments.Duration.TotalMilliseconds
            };
            snackBarTimer.Tick += (sender, e) =>
            {
                formsAppBar.Content = currentContent;
                snackBarTimer.Stop();
                arguments.SetResult(false);
            };
            snackBar.OnSnackBarActionExecuted += () =>
            {
                formsAppBar.Content = currentContent;
                snackBarTimer.Stop();
            };
            snackBarTimer.Start();
            var border = new Border
            {
                CornerRadius = new CornerRadius(arguments.CornerRadius.Left, arguments.CornerRadius.Top, arguments.CornerRadius.Right, arguments.CornerRadius.Bottom)
            };

            border.Child        = snackBar;
            formsAppBar.Content = border;
            return(default);
        internal partial ValueTask Show(Forms.VisualElement sender, SnackBarOptions arguments)
        {
            var snackBarDialog =
                Forms.Platform.Tizen.Native.Dialog.CreateDialog(Forms.Forms.NativeParent,
                                                                arguments.Actions.Any());

            snackBarDialog.Timeout = arguments.Duration.TotalSeconds;

            var message = arguments.MessageOptions.Message.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;")
                          .Replace(Environment.NewLine, "<br>");

            snackBarDialog.Message = message;

            foreach (var action in arguments.Actions)
            {
                var ok = new EButton(snackBarDialog)
                {
                    Text = action.Text
                };
                snackBarDialog.NeutralButton = ok;
                ok.Clicked += async(_, _) =>
                {
                    snackBarDialog.Dismiss();
                    await OnActionClick(action, arguments).ConfigureAwait(false);
                };
            }

            snackBarDialog.TimedOut          += (_, _) => DismissSnackBar();
            snackBarDialog.BackButtonPressed += (_, _) => DismissSnackBar();
            snackBarDialog.Show();

            return(default);
        public static Task <bool> DisplaySnackBarAsync(this Page page, string message, string actionButtonText, Func <Task> action, int duration = 3000)
        {
            var messageOptions = new MessageOptions {
                Message = message
            };
            var actionOptions = new List <SnackBarActionOptions>
            {
                new SnackBarActionOptions
                {
                    Text = actionButtonText, Action = action
                }
            };
            var args = new SnackBarOptions(messageOptions,
                                           duration,
                                           Color.Default,
#if NETSTANDARD1_0
                                           false,
#else
                                           CultureInfo.CurrentCulture.TextInfo.IsRightToLeft,
#endif
                                           actionOptions);
            var snackBar = new SnackBar();

            snackBar.Show(page, args);
            return(args.Result.Task);
        }
        public static Task <bool> DisplaySnackBarAsync(this Page page, string message, string actionButtonText, Func <Task> action, int durationMilliseconds = 3000)
        {
            var messageOptions = new MessageOptions {
                Message = message
            };
            var actionOptions = new List <SnackBarActionOptions>
            {
                new SnackBarActionOptions
                {
                    Text = actionButtonText, Action = action
                }
            };
            var options = new SnackBarOptions
            {
                MessageOptions = messageOptions,
                Duration       = TimeSpan.FromMilliseconds(durationMilliseconds),
                Actions        = actionOptions,
#if NETSTANDARD1_0
                IsRtl = false,
#else
                IsRtl = CultureInfo.CurrentCulture.TextInfo.IsRightToLeft,
#endif
            };
            var snackBar = new SnackBar();

            snackBar.Show(page, options);
            return(options.Result.Task);
        }
        async void DisplaySnackbarAnchoredClicked(object?sender, EventArgs args)
        {
            var messageOptions = new MessageOptions
            {
                Message    = GenerateLongText(5),
                Foreground = Color.Black
            };

            var options = new SnackBarOptions
            {
                MessageOptions  = messageOptions,
                Duration        = TimeSpan.FromMilliseconds(5000),
                BackgroundColor = Color.LightBlue,
                Actions         = new List <SnackBarActionOptions>
                {
                    new SnackBarActionOptions
                    {
                        ForegroundColor = Color.Red,
                        BackgroundColor = Color.Green,
                        Font            = Font.OfSize("Times New Roman", 15),
                        Padding         = new Thickness(10, 20, 30, 40),
                        Text            = "Action1",
                        Action          = () =>
                        {
                            Debug.WriteLine("1");
                            return(Task.CompletedTask);
                        }
                    }
                }
            };

            var result = await Anchor2.DisplaySnackBarAsync(options);

            StatusText.Text = result ? "SnackBar is closed by user" : "SnackBar is closed by timeout";
        }
        internal ValueTask Show(Forms.VisualElement visualElement, SnackBarOptions arguments)
        {
            var snackBarLayout = new SnackBarLayout(arguments);
            var pageControl    = Platform.GetRenderer(visualElement).ContainerElement.Parent;
            var grid           = (Grid)(FindVisualChildByName <Border>(pageControl, "BottomCommandBarArea")?.Parent ?? throw new NotSupportedException("Anchor Not Supported on UWP"));

            var snackBarRow = new RowDefinition()
            {
                Height = GridLength.Auto
            };

            snackBarTimer = new DispatcherTimer {
                Interval = arguments.Duration
            };
            snackBarTimer.Tick += (sender, e) =>
            {
                grid.Children.Remove(snackBarLayout);
                grid.RowDefinitions.Remove(snackBarRow);
                snackBarTimer.Stop();
                arguments.SetResult(false);
            };
            snackBarLayout.OnSnackBarActionExecuted += () =>
            {
                grid.Children.Remove(snackBarLayout);
                grid.RowDefinitions.Remove(snackBarRow);
                snackBarTimer.Stop();
                arguments.SetResult(true);
            };
            snackBarTimer.Start();
            grid.RowDefinitions.Add(snackBarRow);
            grid.Children.Add(snackBarLayout);
            Grid.SetRow(snackBarLayout, grid.RowDefinitions.Count - 1);
            return(default);
Ejemplo n.º 12
0
        async void AddItem_Clicked(object sender, EventArgs e)
        {
            var messageOptions = new MessageOptions
            {
                Foreground = primary,
                FontSize   = 7,
                Message    = alertMessage
            };

            var actionOptions = new List <SnackBarActionOptions>
            {
                new SnackBarActionOptions
                {
                    ForegroundColor = Color.White,
                    BackgroundColor = primary,
                    FontSize        = 7
                }
            };

            var options = new SnackBarOptions
            {
                MessageOptions  = messageOptions,
                Duration        = TimeSpan.FromMilliseconds(5000),
                BackgroundColor = primary,
                IsRtl           = false,
                Actions         = actionOptions
            };

            await this.DisplaySnackBarAsync(options);
        }
Ejemplo n.º 13
0
        internal void Show(Page sender, SnackBarOptions arguments)
        {
#if __IOS__
            var snackBar = IOSSnackBar.MakeSnackBar(arguments.MessageOptions.Message)
                           .SetAppearance(new SnackBarAppearance
            {
                BackgroundColor      = arguments.BackgroundColor.ToUIColor(),
                TextFontSize         = (nfloat)arguments.MessageOptions.FontSize,
                TextForeground       = arguments.MessageOptions.Foreground.ToUIColor(),
                TextFontName         = arguments.MessageOptions.FontFamily,
                MessageTextAlignment = arguments.IsRtl ? UITextAlignment.Right : UITextAlignment.Left
            })
#elif __MACOS__
            var snackBar = MacOSSnackBar.MakeSnackBar(arguments.MessageOptions.Message)
                           .SetAppearance(new SnackBarAppearance
            {
                BackgroundColor      = arguments.BackgroundColor.ToNSColor(),
                TextFontSize         = (nfloat)arguments.MessageOptions.FontSize,
                TextForeground       = arguments.MessageOptions.Foreground.ToNSColor(),
                TextFontName         = arguments.MessageOptions.FontFamily,
                MessageTextAlignment = arguments.IsRtl ? NSTextAlignment.Right : NSTextAlignment.Left
            })
#endif
                           .SetDuration(arguments.Duration.TotalMilliseconds)
                           .SetTimeoutAction(() =>
            {
                arguments.SetResult(false);
                return(Task.CompletedTask);
            });

#if __IOS__
            if (!UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
                var renderer = Platform.GetRenderer(sender);
                snackBar.SetParentController(renderer.ViewController);
            }
#endif

            foreach (var action in arguments.Actions)
            {
                snackBar.SetActionButtonText(action.Text);
#if __IOS__
                snackBar.Appearance.ButtonBackgroundColor = action.BackgroundColor.ToUIColor();
                snackBar.Appearance.ButtonForegroundColor = action.ForegroundColor.ToUIColor();
#elif __MACOS__
                snackBar.Appearance.ButtonBackgroundColor = action.BackgroundColor.ToNSColor();
                snackBar.Appearance.ButtonForegroundColor = action.ForegroundColor.ToNSColor();
#endif
                snackBar.Appearance.ButtonFontSize = (nfloat)action.FontSize;
                snackBar.Appearance.ButtonFontName = action.FontFamily;
                snackBar.SetAction(async() =>
                {
                    snackBar.Dismiss();
                    await action.Action();
                    arguments.SetResult(true);
                });
            }

            snackBar.Show();
        }
Ejemplo n.º 14
0
        public async void CanExecuteDelete()
        {
            if (SelectedClinic?.ClinicName != null)
            {
                var acceptAction = new SnackBarActionOptions()
                {
                    Action          = () => ExecuteDelete(),
                    ForegroundColor = Color.FromHex("#0990bf"),
                    BackgroundColor = Color.FromHex("#e2e2e2"),
                    Text            = "OK",
                    Padding         = 12
                };

                var options = new SnackBarOptions()
                {
                    MessageOptions = new MessageOptions()
                    {
                        Foreground = Color.FromHex("#505050"),
                        Padding    = 12,
                        Message    = "Do you want to move this to recycle bin?"
                    },

                    BackgroundColor = Color.FromHex("#e2e2e2"),
                    Duration        = TimeSpan.FromSeconds(5),
                    CornerRadius    = 12,
                    Actions         = new[] { acceptAction }
                };
                await App.Current.MainPage.DisplaySnackBarAsync(options);
            }
            else
            {
                StandardMessagesDisplay.NoItemSelectedDisplayMessage();
            }
        }
        public static Task <bool> DisplaySnackBarAsync(this Page page, SnackBarOptions snackBarOptions)
        {
            var snackBar  = new SnackBar();
            var arguments = snackBarOptions ?? new SnackBarOptions();

            snackBar.Show(page, arguments);
            return(arguments.Result.Task);
        }
        public static Task <bool> DisplayToastAsync(this Page page, ActionOptions actionOptions)
        {
            var snackBar  = new SnackBar();
            var arguments = actionOptions ?? new ActionOptions();
            var options   = new SnackBarOptions(arguments.MessageOptions, arguments.Duration, arguments.BackgroundColor, arguments.IsRtl, null);

            snackBar.Show(page, options);
            return(options.Result.Task);
        }
        public static Task <bool> DisplaySnackBarAsync(this Page page, SnackBarOptions snackBarOptions)
        {
            _ = page ?? throw new ArgumentNullException(nameof(page));

            var snackBar  = new SnackBar();
            var arguments = snackBarOptions ?? new SnackBarOptions();

            snackBar.Show(page, arguments);
            return(arguments.Result.Task);
        }
Ejemplo n.º 18
0
        public static async Task <bool> DisplaySnackBarAsync(this Page page, SnackBarOptions snackBarOptions)
        {
            _ = page ?? throw new ArgumentNullException(nameof(page));

            var snackBar = new SnackBar();
            var options  = snackBarOptions ?? new SnackBarOptions();
            await snackBar.Show(page, options);

            var isButtonClicked = await options.Result.Task;

            return(isButtonClicked);
        }
Ejemplo n.º 19
0
        async void DisplaySnackBarAdvancedClicked(object sender, EventArgs args)
        {
            var messageOptions = new MessageOptions
            {
                Foreground = Color.DeepSkyBlue,
                FontSize   = 40,
                FontFamily = "Times New Roman",
                Message    = GenerateLongText(5)
            };

            var actionOptions = new List <SnackBarActionOptions>
            {
                new SnackBarActionOptions
                {
                    ForegroundColor = Color.Red,
                    BackgroundColor = Color.Green,
                    FontSize        = 40,
                    FontFamily      = "Times New Roman",
                    Text            = "Action1",
                    Action          = () =>
                    {
                        Debug.WriteLine("1");
                        return(Task.CompletedTask);
                    }
                },
                new SnackBarActionOptions
                {
                    ForegroundColor = Color.Green,
                    BackgroundColor = Color.Red,
                    FontSize        = 20,
                    FontFamily      = "Times New Roman",
                    Text            = "Action2",
                    Action          = () =>
                    {
                        Debug.WriteLine("2");
                        return(Task.CompletedTask);
                    }
                }
            };
            var options = new SnackBarOptions
            {
                MessageOptions  = messageOptions,
                Duration        = TimeSpan.FromMilliseconds(5000),
                BackgroundColor = Color.Coral,
                IsRtl           = CultureInfo.CurrentCulture.TextInfo.IsRightToLeft,
                Actions         = actionOptions
            };
            var result = await this.DisplaySnackBarAsync(options);

            StatusText.Text = result ? "SnackBar is closed by user" : "SnackBar is closed by timeout";
        }
        public SnackBarLayout(SnackBarOptions options)
        {
            RowDefinitions.Add(new RowDefinition());
            ColumnDefinitions.Add(new ColumnDefinition());
#if UWP
            Background = options.BackgroundColor.ToBrush();
            var messageLabel = new TextBlock
            {
                Text       = options.MessageOptions.Message,
                FontSize   = options.MessageOptions.FontSize,
                FontFamily = new FontFamily(options.MessageOptions.FontFamily),
                Foreground = options.MessageOptions.Foreground.ToBrush()
            };
#else
            Background = options.BackgroundColor.ToBrush();
            var messageLabel = new Label
            {
                Content    = options.MessageOptions.Message,
                FontSize   = options.MessageOptions.FontSize,
                FontFamily = new FontFamily(options.MessageOptions.FontFamily),
                Foreground = options.MessageOptions.Foreground.ToBrush()
            };
#endif
            Children.Add(messageLabel);
            SetRow(messageLabel, 0);
            SetColumn(messageLabel, 0);
            for (var i = 0; i < options.Actions.Count(); i++)
            {
                ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = GridLength.Auto
                });
                var action = options.Actions.ToArray()[i];
                var button = new Button
                {
                    Content    = action.Text,
                    Foreground = action.ForegroundColor.ToBrush(),
                    Background = action.BackgroundColor.ToBrush(),
                    FontSize   = action.FontSize,
                    FontFamily = new FontFamily(action.FontFamily),
                    Command    = new Forms.Command(async() =>
                    {
                        OnSnackBarActionExecuted?.Invoke();
                        await action.Action();
                    })
                };
                Children.Add(button);
                SetRow(button, 0);
                SetColumn(button, i + 1);
            }
        }
        async void DisplaySnackBarAdvancedClicked(object?sender, EventArgs args)
        {
            const string smileIcon = "\uf118";
            var          options   = new SnackBarOptions
            {
                MessageOptions = new MessageOptions
                {
                    Foreground = Color.DeepSkyBlue,
                    Font       = Font.OfSize("FARegular", 40),
                    Padding    = new Thickness(10, 20, 30, 40),
                    Message    = smileIcon
                },
                CornerRadius    = new Thickness(10, 20, 30, 40),
                Duration        = TimeSpan.FromMilliseconds(5000),
                BackgroundColor = Color.Coral,
                IsRtl           = CultureInfo.CurrentCulture.TextInfo.IsRightToLeft,
                Actions         = new List <SnackBarActionOptions>
                {
                    new SnackBarActionOptions
                    {
                        ForegroundColor = Color.Red,
                        BackgroundColor = Color.Green,
                        Font            = Font.OfSize("Times New Roman", 15),
                        Padding         = new Thickness(10, 20, 30, 40),
                        Text            = "Action1",
                        Action          = () =>
                        {
                            Debug.WriteLine("1");
                            return(Task.CompletedTask);
                        }
                    },
                    new SnackBarActionOptions
                    {
                        ForegroundColor = Color.Green,
                        BackgroundColor = Color.Red,
                        Font            = Font.OfSize("Times New Roman", 20),
                        Padding         = new Thickness(40, 30, 20, 10),
                        Text            = "Action2",
                        Action          = () =>
                        {
                            Debug.WriteLine("2");
                            return(Task.CompletedTask);
                        }
                    }
                }
            };
            var result = await this.DisplaySnackBarAsync(options);

            StatusText.Text = result ? "SnackBar is closed by user" : "SnackBar is closed by timeout";
        }
        public static Task DisplayToastAsync(this Page page, ToastOptions toastOptions)
        {
            var snackBar  = new SnackBar();
            var arguments = toastOptions ?? new ToastOptions();
            var options   = new SnackBarOptions
            {
                MessageOptions  = arguments.MessageOptions,
                Duration        = arguments.Duration,
                BackgroundColor = arguments.BackgroundColor,
                IsRtl           = arguments.IsRtl
            };

            snackBar.Show(page, options);
            return(options.Result.Task);
        }
        public void Show(Page page, SnackBarOptions arguments)
        {
            var mainWindow     = (Platform.GetRenderer(page).Container.Child as Forms.Platform.GTK.Controls.Page)?.Children[0] as VBox;
            var snackBarLayout = GetSnackBarLayout(mainWindow, arguments);

            AddSnackBarContainer(mainWindow, snackBarLayout);
            snackBarTimer          = new Timer(arguments.Duration);
            snackBarTimer.Elapsed += (sender, e) =>
            {
                mainWindow.Remove(snackBarLayout);
                snackBarTimer.Stop();
                arguments.SetResult(false);
            };
            snackBarTimer.Start();
        }
        async void DisplaySnackBarWithPadding(object?sender, EventArgs args)
        {
            var options = new SnackBarOptions()
            {
                BackgroundColor = Color.FromHex("#CC0000"),
                MessageOptions  = new MessageOptions
                {
                    Message    = "msg",
                    Foreground = Color.White,
                    Font       = Font.SystemFontOfSize(16),
                    Padding    = new Thickness(10, 20, 30, 40)
                }
            };

            await this.DisplaySnackBarAsync(options);
        }
Ejemplo n.º 25
0
        async Task OnActionClick(SnackBarActionOptions action, SnackBarOptions arguments)
        {
            try
            {
                if (action.Action != null)
                {
                    await action.Action();
                }

                arguments.SetResult(true);
            }
            catch (Exception ex)
            {
                arguments.SetException(ex);
            }
        }
Ejemplo n.º 26
0
        HBox GetSnackBarLayout(Container?container, SnackBarOptions arguments)
        {
            var snackBarLayout = new HBox();

            snackBarLayout.ModifyBg(StateType.Normal, arguments.BackgroundColor.ToGtkColor());

            var message = new Gtk.Label(arguments.MessageOptions.Message);

            message.ModifyFont(new FontDescription {
                AbsoluteSize = arguments.MessageOptions.Font.FontSize, Family = arguments.MessageOptions.Font.FontFamily
            });
            message.ModifyFg(StateType.Normal, arguments.MessageOptions.Foreground.ToGtkColor());
            message.SetPadding((int)arguments.MessageOptions.Padding.Left, (int)arguments.MessageOptions.Padding.Top);
            snackBarLayout.Add(message);
            snackBarLayout.SetChildPacking(message, false, false, 0, PackType.Start);

            foreach (var action in arguments.Actions)
            {
                var button = new Gtk.Button
                {
                    Label = action.Text
                };
                button.ModifyFont(new FontDescription {
                    AbsoluteSize = action.Font.FontSize, Family = action.Font.FontFamily
                });
                button.ModifyBg(StateType.Normal, action.BackgroundColor.ToGtkColor());
                button.ModifyFg(StateType.Normal, action.ForegroundColor.ToGtkColor());

                button.Clicked += async(sender, e) =>
                {
                    snackBarTimer?.Stop();

                    if (action.Action != null)
                    {
                        await action.Action();
                    }

                    arguments.SetResult(true);
                    container?.Remove(snackBarLayout);
                };

                snackBarLayout.Add(button);
                snackBarLayout.SetChildPacking(button, false, false, 0, PackType.End);
            }

            return(snackBarLayout);
        }
Ejemplo n.º 27
0
        public static async Task ShowSuccessSnackBarAsync(this Page page, string message, SnackbarDuration duration = SnackbarDuration.Short)
        {
            var messageOptions = new MessageOptions
            {
                Foreground = Color.White,
                Message    = message
            };

            var options = new SnackBarOptions()
            {
                MessageOptions  = messageOptions,
                Duration        = duration == SnackbarDuration.Long ? TimeSpan.FromMilliseconds(5000) : TimeSpan.FromMilliseconds(2500),
                BackgroundColor = Color.FromHex("20be28"),
                IsRtl           = false,
            };
            await page.DisplaySnackBarAsync(options);
        }
Ejemplo n.º 28
0
        public static async Task DisplayToastAsync(this Page page, ToastOptions toastOptions)
        {
            _ = page ?? throw new ArgumentNullException(nameof(page));

            var snackBar  = new SnackBar();
            var arguments = toastOptions ?? new ToastOptions();
            var options   = new SnackBarOptions
            {
                MessageOptions  = arguments.MessageOptions,
                Duration        = arguments.Duration,
                BackgroundColor = arguments.BackgroundColor,
                IsRtl           = arguments.IsRtl
            };
            await snackBar.Show(page, options);

            await options.Result.Task;
        }
Ejemplo n.º 29
0
        public ValueTask Show(VisualElement visualElement, SnackBarOptions arguments)
        {
            var mainWindow     = (Platform.GetRenderer(visualElement).Container.Child as Forms.Platform.GTK.Controls.Page)?.Children[0] as VBox;
            var snackBarLayout = GetSnackBarLayout(mainWindow, arguments);

            AddSnackBarContainer(mainWindow, snackBarLayout);

            snackBarTimer          = new Timer(arguments.Duration.TotalMilliseconds);
            snackBarTimer.Elapsed += (sender, e) =>
            {
                mainWindow?.Remove(snackBarLayout);
                snackBarTimer.Stop();
                arguments.SetResult(false);
            };

            snackBarTimer.Start();
            return(default);
Ejemplo n.º 30
0
        /// <summary>
        /// Display toast with the custom options
        /// </summary>
        /// <param name="visualElement">Toast anchor</param>
        /// <param name="toastOptions">Toast options</param>
        /// <returns>Task</returns>
        public static async Task DisplayToastAsync(this VisualElement visualElement, ToastOptions toastOptions)
        {
            _ = visualElement ?? throw new ArgumentNullException(nameof(visualElement));

            var snackBar = new SnackBar();
            var options  = new SnackBarOptions
            {
                MessageOptions  = toastOptions.MessageOptions,
                Duration        = toastOptions.Duration,
                BackgroundColor = toastOptions.BackgroundColor,
                IsRtl           = toastOptions.IsRtl
            };

            await snackBar.Show(visualElement, options);

            await options.Result.Task;
        }