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

            var app = UIApplication.SharedApplication;

            app.InvokeOnMainThread(() =>
            {
                //var snackbar = new TTGSnackbar(cfg.Message)
                var snackbar = new TTGSnackbar
                {
                    Message       = cfg.Message,
                    Duration      = cfg.Duration,
                    AnimationType = TTGSnackbarAnimationType.FadeInFadeOut,
                    ShowOnTop     = cfg.Position == ToastPosition.Top
                };
                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();
                }
                //snackbar.MessageTextColor = cfg.MessageTextColor.Value.ToNative();

                //if (cfg.Position != null)
                //    snackbar.LocationType = cfg.Position == ToastPosition.Top
                //        ? TTGSnackbarLocation.Top
                //        : TTGSnackbarLocation.Bottom;

                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);
        }
Esempio n. 2
0
        public IDisposable Build(UIApplication app, SnackbarConfig config)
        {
            app.SafeInvokeOnMainThread(() =>
            {
                _snackbar?.Dismiss();

                _snackbar               = new TTGSnackbar(config.Message);
                _snackbar.Duration      = config.Duration;
                _snackbar.AnimationType = TTGSnackbarAnimationType.FadeInFadeOut;

                if (config.ActionText != null)
                {
                    _snackbar.ActionText  = config.ActionText;
                    _snackbar.ActionBlock = (_) => config.Action?.Invoke();

                    if (config.ActionTextColor != null)
                    {
                        _snackbar.ActionTextColor = config.ActionTextColor.Value.ToNative();
                    }
                }

                if (config.TextColor != null)
                {
                    _snackbar.MessageTextColor = config.TextColor.Value.ToNative();
                }

                if (config.BackgroundColor != null)
                {
                    _snackbar.BackgroundColor = config.BackgroundColor.Value.ToNative();
                }

                _snackbar.Show();
            });

            return(new DisposableAction(() => app.SafeInvokeOnMainThread(() => _snackbar?.Dismiss())));
        }
        public override IDisposable Toast(ToastConfig cfg)
        {
            this.currentToast?.Dispose();

            var app = UIApplication.SharedApplication;

            app.SafeInvokeOnMainThread(() =>
            {
                //var snackbar = new TTGSnackbar(cfg.Message)
                var snackbar = new TTGSnackbar
                {
                    Message       = cfg.Message,
                    Duration      = cfg.Duration,
                    AnimationType = TTGSnackbarAnimationType.FadeInFadeOut,
                    ShowOnTop     = cfg.Position == ToastPosition.Top || cfg.Position == ToastPosition.UnderTopNavigationBar,
                    CornerRadius  = 0,
                };

                if (cfg.Position == ToastPosition.UnderTopNavigationBar)
                {
                    if (navigationBarHeight == 0)
                    {
                        using (var bar = new UINavigationController())
                            navigationBarHeight = (int)bar.NavigationBar.Frame.Height;
                    }
                    snackbar.TopMargin = navigationBarHeight;
                }

                if (cfg.Icon != null)
                {
                    snackbar.Icon = UIImage.FromBundle(cfg.Icon);
                }

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

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

                //if (cfg.Position != null)
                //    snackbar.LocationType = cfg.Position == ToastPosition.Top
                //        ? TTGSnackbarLocation.Top
                //        : TTGSnackbarLocation.Bottom;

                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.SafeInvokeOnMainThread(() => snackbar.Dismiss())
                    );
            });
            return(this.currentToast);
        }