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
                {
                    Label = arguments.ActionButtonText
                };
                button.Clicked += async(sender, e) =>
                {
                    snackbarTimer.Stop();
                    await arguments.Action();

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

            return(snackbarLayout);
        }
        internal 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();
        }
Example #3
0
 internal 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);
     }
 }
		internal void Show(Forms.Page page, SnackbarArguments arguments)
		{

			var snackBarLayout = new SnackbarLayout(arguments.Message, arguments.ActionButtonText, arguments.Action);
			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 = TimeSpan.FromMilliseconds(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 void Show(Page sender, SnackbarArguments arguments)
        {
            var view          = Platform.GetRenderer(sender).View;
            var snackbar      = AndroidSnackbar.Make(view, arguments.Message, arguments.Duration);
            var snackbarView  = snackbar.View;
            var snackTextView = snackbarView.FindViewById <TextView>(Resource.Id.snackbar_text);

            snackTextView.SetMaxLines(10);

            if (!string.IsNullOrEmpty(arguments.ActionButtonText) && arguments.Action != null)
            {
                snackbar.SetAction(arguments.ActionButtonText, async(v) => await arguments.Action());
            }

            snackbar.AddCallback(new SnackbarCallback(arguments));
            snackbar.Show();
        }
Example #6
0
        internal 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);
            }
        }
Example #7
0
        internal 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);
        }
Example #8
0
        internal void Show(Page page, SnackbarArguments arguments)
        {
            var formsAppBar    = System.Windows.Application.Current.MainWindow.FindChild <FormsAppBar>("PART_BottomAppBar");
            var currentContent = formsAppBar.Content;
            var snackBar       = new SnackbarLayout(arguments.Message, arguments.ActionButtonText, arguments.Action);

            snackbarTimer = new Timer {
                Interval = arguments.Duration
            };
            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, SnackbarArguments arguments)
        {
            if (isSnackBarActive)
            {
                return;
            }

            isSnackBarActive = true;
            var platformRender = Platform.GetRenderer(page) 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 += (sender, e) =>
            {
                ((platformRender.Toplevel as Window).Child as VBox).Remove(snackBar);
                snackbarTimer.Stop();
                arguments.SetResult(false);
                isSnackBarActive = false;
            };
            snackbarTimer.Start();
        }
Example #10
0
 internal void Show(Page sender, SnackbarArguments arguments) => throw new PlatformNotSupportedException();
 public SnackbarCallback(SnackbarArguments arguments) => this.arguments = arguments;