Exemplo n.º 1
0
        public override IDisposable Toast(ToastConfig cfg)
        {
            this.currentToast?.Dispose();

            var app = UIApplication.SharedApplication;

            app.InvokeOnMainThread(() =>
            {
                var snackbar = new TTG.TTGSnackbar
                {
                    Message       = cfg.Message,
                    Duration      = cfg.Duration,
                    AnimationType = TTG.TTGSnackbarAnimationType.FadeInFadeOut
                };
                if (cfg.Icon != null)
                {
                    snackbar.Icon = cfg.Icon.ToNative();
                }

                if (cfg.BackgroundColor != null)
                {
                    snackbar.BackgroundColor = cfg.BackgroundColor.Value.ToNative();
                }

                if (cfg.MessageTextColor != null)
                {
                    snackbar.MessageLabel.TextColor = cfg.MessageTextColor.Value.ToNative();
                }

                if (cfg.Action != null)
                {
                    var color = cfg.Action.TextColor ?? ToastConfig.DefaultActionTextColor;
                    if (color != null)
                    {
                        snackbar.ActionButton.SetTitleColor(color.Value.ToNative(), UIControlState.Normal);
                    }

                    snackbar.ActionText  = cfg.Action.Text;
                    snackbar.ActionBlock = x =>
                    {
                        snackbar.Dismiss();
                        cfg.Action.Action?.Invoke();
                    };
                }
                snackbar.Show();

                this.currentToast = new DisposableAction(
                    () => app.InvokeOnMainThread(() => snackbar.Dismiss())
                    );
            });
            return(this.currentToast);
        }
Exemplo n.º 2
0
        public override IDisposable Toast(ToastConfig cfg)
        {
            this.currentToast?.Dispose();

            var app = UIApplication.SharedApplication;
            app.InvokeOnMainThread(() =>
            {
                var snackbar = new TTG.TTGSnackbar
                {
                    Message = cfg.Message,
                    Duration = cfg.Duration,
                    AnimationType = TTG.TTGSnackbarAnimationType.FadeInFadeOut
                };
                if (cfg.BackgroundColor != null)
                    snackbar.BackgroundColor = cfg.BackgroundColor.Value.ToNative();

                if (cfg.MessageTextColor != null)
                    snackbar.MessageLabel.TextColor = cfg.MessageTextColor.Value.ToNative();

                if (cfg.Action != null)
                {
                    var color = cfg.Action.TextColor ?? ToastConfig.DefaultActionTextColor;
                    if (color != null)
                        snackbar.ActionButton.SetTitleColor(color.Value.ToNative(), UIControlState.Normal);

                    snackbar.ActionText = cfg.Action.Text;
                    snackbar.ActionBlock = x =>
                    {
                        snackbar.Dismiss();
                        cfg.Action.Action?.Invoke();
                    };
                }
                snackbar.Show();

                this.currentToast = new DisposableAction(
                    () => app.InvokeOnMainThread(() => snackbar.Dismiss())
                );
            });
            return this.currentToast;
        }