Ejemplo n.º 1
0
 public void Show(Page page, SnackbarArguments arguments)
 {
     if (System.Windows.Application.Current.MainWindow is MyFormsWindow window)
     {
         snackbarTimer = new Timer {
             Interval = arguments.Duration
         };
         snackbarTimer.Tick += delegate
         {
             window.HideSnackBar();
             snackbarTimer.Stop();
             arguments.SetResult(false);
         };
         window.OnSnackbarActionExecuted += delegate
         {
             window.HideSnackBar();
             snackbarTimer.Stop();
             arguments.SetResult(true);
         };
         snackbarTimer.Start();
         window.ShowSnackBar(arguments.Message, arguments.ActionButtonText, arguments.Action);
     }
     else
     {
         arguments.SetResult(false);
     }
 }
Ejemplo n.º 2
0
        public void Show(Page sender, SnackbarArguments arguments)
        {
#if __IOS__
            var snackbar = IOSSnackBar.MakeSnackbar(arguments.Message)
#elif __MACOS__
            var snackbar = MacOSSnackBar.MakeSnackbar(arguments.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

            if (!string.IsNullOrEmpty(arguments.ActionButtonText) && arguments.Action != null)
            {
                snackbar.SetActionButtonText(arguments.ActionButtonText);
                snackbar.SetAction(async() =>
                {
                    snackbar.Dismiss();
                    await arguments.Action();
                    arguments.SetResult(true);
                });
            }

            snackbar.Show();
        }
        static HBox GetSnackbarLayout(Widget platformRender, SnackbarArguments arguments)
        {
            var snackbarLayout = new HBox();
            var message        = new Gtk.Label(arguments.Message);

            snackbarLayout.Add(message);
            var isActionDialog = !string.IsNullOrEmpty(arguments.ActionButtonText) && arguments.Action != null;

            if (isActionDialog)
            {
                var button = new Gtk.Button();
                button.Label    = arguments.ActionButtonText;
                button.Clicked += async delegate
                {
                    snackbarTimer.Stop();
                    await arguments.Action();

                    arguments.SetResult(true);
                    (GetTopWindowContainer(platformRender) as VBox).Remove(snackbarLayout);
                    isSnackBarActive = false;
                };
                snackbarLayout.Add(button);
            }

            return(snackbarLayout);
        }
Ejemplo n.º 4
0
        public void Show(Forms.Page sender, SnackbarArguments arguments)
        {
            var snackbarDialog =
                Forms.Platform.Tizen.Native.Dialog.CreateDialog(Forms.Forms.NativeParent,
                                                                (arguments.ActionButtonText != null));

            snackbarDialog.Timeout = TimeSpan.FromMilliseconds(arguments.Duration).TotalSeconds;

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

            snackbarDialog.Message = message;

            if (!string.IsNullOrEmpty(arguments.ActionButtonText) && arguments.Action != null)
            {
                var ok = new EButton(snackbarDialog)
                {
                    Text = arguments.ActionButtonText
                };
                snackbarDialog.NeutralButton = ok;
                ok.Clicked += async(s, evt) =>
                {
                    snackbarDialog.Dismiss();
                    await arguments.Action();

                    arguments.SetResult(true);
                };
            }

            snackbarDialog.TimedOut += (s, evt) => { DismissSnackbar(); };

            snackbarDialog.BackButtonPressed += (s, evt) => { DismissSnackbar(); };

            snackbarDialog.Show();

            void DismissSnackbar()
            {
                snackbarDialog.Dismiss();
                arguments.SetResult(false);
            }
        }
        public void Show(Forms.Page page, SnackbarArguments arguments)
        {
            var pageControl = Platform.GetRenderer(page).ContainerElement.Parent as PageControl;
            var sender      = new ExtendedPageControl(pageControl);

            snackbarTimer = new DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(arguments.Duration)
            };
            snackbarTimer.Tick += delegate
            {
                sender.HideSnackBar();
                snackbarTimer.Stop();
                arguments.SetResult(false);
            };
            sender.OnSnackbarActionExecuted += delegate
            {
                sender.HideSnackBar();
                snackbarTimer.Stop();
                arguments.SetResult(true);
            };
            snackbarTimer.Start();
            sender.ShowSnackBar(arguments.Message, arguments.ActionButtonText, arguments.Action);
        }
        public void Show(Page sender, SnackbarArguments arguments)
        {
            if (isSnackBarActive)
            {
                return;
            }

            isSnackBarActive = true;
            var platformRender = Platform.GetRenderer(sender) as Widget;
            var snackBar       = GetSnackbarLayout(platformRender, arguments);

            AddPageContainer(platformRender);
            ((platformRender.Toplevel as Window).Child as VBox).Add(snackBar);
            (platformRender.Toplevel as Window).Child.ShowAll();
            snackbarTimer          = new Timer(arguments.Duration);
            snackbarTimer.Elapsed += delegate
            {
                ((platformRender.Toplevel as Window).Child as VBox).Remove(snackBar);
                snackbarTimer.Stop();
                arguments.SetResult(false);
                isSnackBarActive = false;
            };
            snackbarTimer.Start();
        }