Exemplo n.º 1
0
        internal async Task DisplayToast(string text, Action <ToastOptions> options, Action <ToastLayout> layout)
        {
            var toastOptions = new ToastOptions();

            options(toastOptions);
            var layoutOptions = new ToastLayout();

            layout(layoutOptions);

            await DisplayToast(text, toastOptions, layoutOptions);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Display a Toast
        /// </summary>
        /// <param name="text">Text to be displayed inside the toast</param>
        /// <param name="options"><see cref="ToastOptions" /> to set for the Toast</param>
        /// <param name="layout"><see cref="ToastLayout" /> to set for the Toast</param>
        /// <returns>A void <c>Task</c></returns>
        public static async Task DisplayToast(string text, ToastOptions options = null, ToastLayout layout = null)
        {
            try
            {
                if (ToastCore == null)
                {
                    Initialize();
                }

                await ToastCore?.DisplayToast(text, options, layout) !;
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }
        }
Exemplo n.º 3
0
        private static ToastView GetToast(string text, ToastOptions options, ToastLayout layout)
        {
            var toast = new ToastView
            {
                Text         = text,
                ToastOptions = options,
                ToastLayout  = layout,
                Margin       = new Thickness(layout.HorizontalMargin, layout.PositionY, layout.HorizontalMargin, 0)
            };

            if (toast.ToastOptions.ToastAction != null)
            {
                toast.GestureRecognizers.Add(new TapGestureRecognizer()
                {
                    Command = new Command((toast.ToastOptions.ToastAction))
                });
            }

            return(toast);
        }
Exemplo n.º 4
0
        internal async Task DisplayToast(string text, ToastOptions options, ToastLayout layout)
        {
            // get toast container
            var toastContainer = GetToastContainer();

            // toast view
            var toastView = GetToast(text, options, layout);

            toastContainer.Children.Add(toastView);

            // animate toast
            if (toastView.ToastOptions.OnBeforeDisplayingToast != null)
            {
                await toastView.ToastOptions.OnBeforeDisplayingToast(toastView);
            }

            // hide toast
            if (toastView.ToastOptions.Duration >= 0)
            {
                await HideToastIn(toastView.ToastOptions.Duration);
            }
        }