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();
        }
        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)
        {
            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();
        }
Beispiel #4
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);
            }
        }