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);
예제 #2
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();
        }
예제 #3
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();
        }
        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);
        }
        internal 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();
                arguments.SetResult(true);
            };
            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);
예제 #6
0
        internal void Show(Forms.Page 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(s, evt) =>
                {
                    snackBarDialog.Dismiss();

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

                    arguments.SetResult(true);
                };
            }

            snackBarDialog.TimedOut += (s, evt) => DismissSnackBar();

            snackBarDialog.BackButtonPressed += (s, evt) => DismissSnackBar();

            snackBarDialog.Show();

            void DismissSnackBar()
            {
                snackBarDialog.Dismiss();
                arguments.SetResult(false);
            }
        }
        internal void Show(Page page, 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();
                arguments.SetResult(true);
            };
            snackBarTimer.Start();
            formsAppBar.Content = snackBar;
        }
        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();
        }
예제 #9
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);
            }
        }
예제 #10
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);
        }
예제 #11
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);
        internal ValueTask Show(VisualElement sender, SnackBarOptions arguments)
        {
            var snackBar = NativeSnackBar.MakeSnackBar(arguments.MessageOptions.Message)
                           .SetDuration(arguments.Duration)
                           .SetCornerRadius(arguments.CornerRadius)
                           .SetTimeoutAction(() =>
            {
                arguments.SetResult(false);
                return(Task.CompletedTask);
            });

#if __IOS__
            if (arguments.BackgroundColor != Color.Default)
            {
                snackBar.Appearance.Background = arguments.BackgroundColor.ToUIColor();
            }

            if (arguments.MessageOptions.Font != Font.Default)
            {
                snackBar.Appearance.Font = arguments.MessageOptions.Font.ToUIFont();
            }

            if (arguments.MessageOptions.Foreground != Color.Default)
            {
                snackBar.Appearance.Foreground = arguments.MessageOptions.Foreground.ToUIColor();
            }

            if (arguments.MessageOptions.Padding != MessageOptions.DefaultPadding)
            {
                snackBar.Layout.PaddingTop    = (nfloat)arguments.MessageOptions.Padding.Top;
                snackBar.Layout.PaddingLeft   = (nfloat)arguments.MessageOptions.Padding.Left;
                snackBar.Layout.PaddingBottom = (nfloat)arguments.MessageOptions.Padding.Bottom;
                snackBar.Layout.PaddingRight  = (nfloat)arguments.MessageOptions.Padding.Right;
            }

            snackBar.Appearance.TextAlignment = arguments.IsRtl ? UITextAlignment.Right : UITextAlignment.Left;

            if (!UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
                snackBar.Layout.PaddingTop    = (nfloat)arguments.MessageOptions.Padding.Top;
                snackBar.Layout.PaddingLeft   = (nfloat)arguments.MessageOptions.Padding.Left;
                snackBar.Layout.PaddingBottom = (nfloat)arguments.MessageOptions.Padding.Bottom;
                snackBar.Layout.PaddingRight  = (nfloat)arguments.MessageOptions.Padding.Right;
            }

            snackBar.Appearance.TextAlignment = arguments.IsRtl ? UITextAlignment.Right : UITextAlignment.Left;
#elif __MACOS__
            if (arguments.BackgroundColor != Color.Default)
            {
                snackBar.Appearance.Background = arguments.BackgroundColor.ToNSColor();
            }

            if (arguments.MessageOptions.Font != Font.Default)
            {
                snackBar.Appearance.Font = arguments.MessageOptions.Font.ToNSFont();
            }

            if (arguments.MessageOptions.Foreground != Color.Default)
            {
                snackBar.Appearance.Foreground = arguments.MessageOptions.Foreground.ToNSColor();
            }

            snackBar.Appearance.TextAlignment = arguments.IsRtl ? NSTextAlignment.Right : NSTextAlignment.Left;
#endif
            if (sender is not Page)
            {
                var renderer = Platform.GetRenderer(sender);
                snackBar.SetAnchor(renderer.NativeView);
            }

            foreach (var action in arguments.Actions)
            {
                var actionButton = new NativeSnackButton(action.Padding.Left,
                                                         action.Padding.Top,
                                                         action.Padding.Right,
                                                         action.Padding.Bottom);
                actionButton.SetActionButtonText(action.Text);
#if __IOS__
                if (action.BackgroundColor != Color.Default)
                {
                    actionButton.BackgroundColor = action.BackgroundColor.ToUIColor();
                }

                if (action.Font != Font.Default)
                {
                    actionButton.Font = action.Font.ToUIFont();
                }

                if (action.ForegroundColor != Color.Default)
                {
                    actionButton.SetTitleColor(action.ForegroundColor.ToUIColor(), UIControlState.Normal);
                }
#elif __MACOS__
                if (action.BackgroundColor != Color.Default && actionButton.Layer != null)
                {
                    actionButton.Layer.BackgroundColor = action.BackgroundColor.ToCGColor();
                }

                if (action.Font != Font.Default)
                {
                    actionButton.Font = action.Font.ToNSFont();
                }
#endif
                actionButton.SetAction(async() =>
                {
                    snackBar.Dismiss();

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

                    arguments.SetResult(true);
                });

                snackBar.Actions.Add(actionButton);
            }

            snackBar.Show();

            return(default);
        internal void Show(Page sender, SnackBarOptions arguments)
        {
            var snackBar = NativeSnackBar.MakeSnackBar(arguments.MessageOptions.Message)
                           .SetDuration(arguments.Duration.TotalMilliseconds)
                           .SetTimeoutAction(() =>
            {
                arguments.SetResult(false);
                return(Task.CompletedTask);
            });

#if __IOS__
            if (arguments.BackgroundColor != Color.Default)
            {
                snackBar.Appearance.Background = arguments.BackgroundColor.ToUIColor();
            }

            if (arguments.MessageOptions.Font != Font.Default)
            {
                snackBar.Appearance.Font = arguments.MessageOptions.Font.ToUIFont();
            }

            if (arguments.MessageOptions.Foreground != Color.Default)
            {
                snackBar.Appearance.Foreground = arguments.MessageOptions.Foreground.ToUIColor();
            }

            snackBar.Appearance.TextAlignment = arguments.IsRtl ? UITextAlignment.Right : UITextAlignment.Left;

            if (!UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
            {
                var renderer = Platform.GetRenderer(sender);
                snackBar.SetParentController(renderer.ViewController);
            }
#elif __MACOS__
            if (arguments.BackgroundColor != Color.Default)
            {
                snackBar.Appearance.Background = arguments.BackgroundColor.ToNSColor();
            }

            if (arguments.MessageOptions.Font != Font.Default)
            {
                snackBar.Appearance.Font = arguments.MessageOptions.Font.ToNSFont();
            }

            if (arguments.MessageOptions.Foreground != Color.Default)
            {
                snackBar.Appearance.Foreground = arguments.MessageOptions.Foreground.ToNSColor();
            }

            snackBar.Appearance.TextAlignment = arguments.IsRtl ? NSTextAlignment.Right : NSTextAlignment.Left;
#endif

            foreach (var action in arguments.Actions)
            {
                var actionButton = new NativeActionButton();
                actionButton.SetActionButtonText(action.Text);
#if __IOS__
                if (action.BackgroundColor != Color.Default)
                {
                    actionButton.Appearance.Background = action.BackgroundColor.ToUIColor();
                }

                if (action.Font != Font.Default)
                {
                    actionButton.Appearance.Font = action.Font.ToUIFont();
                }

                if (action.ForegroundColor != Color.Default)
                {
                    actionButton.Appearance.Foreground = action.ForegroundColor.ToUIColor();
                }
#elif __MACOS__
                if (action.BackgroundColor != Color.Default)
                {
                    actionButton.Appearance.Background = action.BackgroundColor.ToNSColor();
                }

                if (action.Font != Font.Default)
                {
                    actionButton.Appearance.Font = action.Font.ToNSFont();
                }

                if (action.ForegroundColor != Color.Default)
                {
                    actionButton.Appearance.Foreground = action.ForegroundColor.ToNSColor();
                }
#endif
                actionButton.SetAction(async() =>
                {
                    snackBar.Dismiss();
                    await action.Action();
                    arguments.SetResult(true);
                });

                snackBar.Actions.Add(actionButton);
            }

            snackBar.Show();
        }
        public SnackBarLayout(SnackBarOptions options)
        {
            RowDefinitions.Add(new RowDefinition());
            ColumnDefinitions.Add(new ColumnDefinition());
            if (options.BackgroundColor != Forms.Color.Default)
            {
                Background = options.BackgroundColor.ToBrush();
            }
#if UAP10_0
            CornerRadius = new CornerRadius(options.CornerRadius.Left, options.CornerRadius.Top, options.CornerRadius.Right, options.CornerRadius.Bottom);
            var messageLabel = new TextBlock
            {
                Text = options.MessageOptions.Message
            };
#else
            var messageLabel = new Label
            {
                Content = options.MessageOptions.Message
            };
#endif
            messageLabel.Padding = new Thickness(options.MessageOptions.Padding.Left,
                                                 options.MessageOptions.Padding.Top,
                                                 options.MessageOptions.Padding.Right,
                                                 options.MessageOptions.Padding.Bottom);

            if (options.MessageOptions.Font != Forms.Font.Default)
            {
                if (options.MessageOptions.Font.FontSize > 0)
                {
                    messageLabel.FontSize = options.MessageOptions.Font.FontSize;
                }

                if (options.MessageOptions.Font.FontFamily != null)
                {
                    messageLabel.FontFamily = new FontFamily(options.MessageOptions.Font.FontFamily);
                }
            }

            if (options.MessageOptions.Foreground != Forms.Color.Default)
            {
                messageLabel.Foreground = options.MessageOptions.Foreground.ToBrush();
            }

            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,
                    Command = new Forms.Command(async() =>
                    {
                        OnSnackBarActionExecuted?.Invoke();
                        try
                        {
                            if (action.Action != null)
                            {
                                await action.Action();
                            }

                            options.SetResult(true);
                        }
                        catch (Exception ex)
                        {
                            options.SetException(ex);
                        }
                    }),
                    Padding = new Thickness(action.Padding.Left,
                                            action.Padding.Top,
                                            action.Padding.Right,
                                            action.Padding.Bottom)
                };
                if (action.Font != Forms.Font.Default)
                {
                    button.FontSize   = action.Font.FontSize;
                    button.FontFamily = new FontFamily(action.Font.FontFamily);
                }

                if (action.BackgroundColor != Forms.Color.Default)
                {
                    button.Background = action.BackgroundColor.ToBrush();
                }

                if (action.ForegroundColor != Forms.Color.Default)
                {
                    button.Foreground = action.ForegroundColor.ToBrush();
                }

                Children.Add(button);
                SetRow(button, 0);
                SetColumn(button, i + 1);
            }
        }