Ejemplo n.º 1
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);
        }
        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);
        }
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);
        }
        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);
        }
        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> DisplaySnackbar(this Page page, string message, int duration = 3000, string actionButtonText = null, Func <Task> action = null)
        {
            var args     = new SnackbarArguments(message, duration, actionButtonText, action);
            var snackBar = new SnackBar();

            snackBar.Show(page, args);
            return(args.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);
        }
            public void OnClick(View v)
            {
                SnackBar snack = new SnackBar(activity, "Do you want change color of this button to red?", "yes", delegate
                {
                    ButtonFlat btn = (ButtonFlat)activity.FindViewById(Resource.Id.buttonSnackBar);
                    btn.SetTextColor(Color.Red);
                });

                snack.Show();
            }
Ejemplo n.º 10
0
        /// <summary>
        /// Display snackbar with custom configuration
        /// </summary>
        /// <param name="visualElement">Snackbar anchor</param>
        /// <param name="snackBarOptions">Snackbar options</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, SnackBarOptions snackBarOptions)
        {
            _ = visualElement ?? throw new ArgumentNullException(nameof(visualElement));

            var snackBar = new SnackBar();
            await snackBar.Show(visualElement, snackBarOptions);

            var result = await snackBarOptions.Result.Task;

            return(result);
        }
Ejemplo n.º 11
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.º 12
0
 public void ShowToast(string message) =>
 Device.InvokeOnMainThreadAsync(() =>
 {
     var snackbar = new SnackBar
     {
         Message         = message,
         LeftMargin      = 25f,
         RightMargin     = 25f,
         BottomMargin    = 25f,
         BackgroundColor = Color.Gray.ToUIColor(),
         Duration        = TimeSpan.FromSeconds(3),
         AnimationType   = SnackbarAnimationType.FadeInFadeOut
     };
     snackbar.Show();
 });
        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);
        }
 private void ShowSnackMethod(object obj)
 {
     SnackBar.Show(new Snack()
     {
         Duration        = 10000,
         Background      = Color.FromHex("#DF8049"),
         TextColor       = Color.White,
         ActionTextColor = Color.White,
         Text            = "Excellent Work!!",
         ActionText      = "Ok",
         Action          = (aobj) =>
         {
             SnackBar.Close();
         }
     });
 }
Ejemplo n.º 15
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;
        }
Ejemplo n.º 16
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.º 17
0
        private void toggleUndoDeletion(bool show)
        {
            if (snackBar != null)
            {
                snackBar.Hide();
                snackBar = null;
            }

            if (!show)
            {
                return;
            }

            snackBar = SnackBar.Factory.CreateUndoSnackBar(
                onUndo: () => ViewModel.TimeEntriesViewModel.CancelDeleteTimeEntry.Execute(Unit.Default));

            snackBar.SnackBottomAnchor = StartTimeEntryButton.TopAnchor;
            snackBar.Show(superView: View);
        }
        public static Task DisplayToastAsync(this Page page, string message, int durationMilliseconds = 3000)
        {
            var messageOptions = new MessageOptions {
                Message = message
            };
            var args = new SnackBarOptions
            {
                MessageOptions = messageOptions,
                Duration       = TimeSpan.FromMilliseconds(durationMilliseconds),
#if NETSTANDARD1_0
                IsRtl = false,
#else
                IsRtl = CultureInfo.CurrentCulture.TextInfo.IsRightToLeft,
#endif
            };
            var snackBar = new SnackBar();

            snackBar.Show(page, args);
            return(args.Result.Task);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Display toast with the default visual configuration
        /// </summary>
        /// <param name="visualElement">Toast anchor</param>
        /// <param name="message">Toast text</param>
        /// <param name="durationMilliseconds">Toast duration (milliseconds)</param>
        /// <returns>Task</returns>
        public static async Task DisplayToastAsync(this VisualElement visualElement, string message, int durationMilliseconds = 3000)
        {
            _ = visualElement ?? throw new ArgumentNullException(nameof(visualElement));

            var messageOptions = new MessageOptions {
                Message = message
            };
            var args = new SnackBarOptions
            {
                MessageOptions = messageOptions,
                Duration       = TimeSpan.FromMilliseconds(durationMilliseconds),
#if NETSTANDARD1_0
                IsRtl = false,
#else
                IsRtl = CultureInfo.CurrentCulture.TextInfo.IsRightToLeft,
#endif
            };
            var snackBar = new SnackBar();
            await snackBar.Show(visualElement, args);

            await args.Result.Task;
        }
Ejemplo n.º 20
0
        private void toggleUndoDeletion(int?numberOfTimeEntriesPendingDeletion)
        {
            if (snackBar != null)
            {
                snackBar.Hide();
                snackBar = null;
            }

            if (!numberOfTimeEntriesPendingDeletion.HasValue)
            {
                return;
            }

            var undoText = numberOfTimeEntriesPendingDeletion > 1
                ? String.Format(Resources.MultipleEntriesDeleted, numberOfTimeEntriesPendingDeletion)
                : Resources.EntryDeleted;

            snackBar = SnackBar.Factory.CreateUndoSnackBar(
                onUndo: () => ViewModel.TimeEntriesViewModel.CancelDeleteTimeEntry.Execute(Unit.Default),
                text: undoText);

            snackBar.SnackBottomAnchor = StartTimeEntryButton.TopAnchor;
            snackBar.Show(superView: View);
        }