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); }
public void ShowSnackBar(string Message) { var snackbar = new TTGSnackbar(Message); snackbar.Duration = TimeSpan.FromSeconds(2); snackbar.Show(); }
partial void buttonClicked(UIButton sender) { var snackbar = new TTGSnackbar("Hello Xamarin snackbar"); snackbar.Duration = TimeSpan.FromSeconds(3); snackbar.AnimationType = TTGSnackbarAnimationType.FadeInFadeOut; snackbar.SeperateView.Alpha = 0; // Action 1 snackbar.ActionText = "Yes"; snackbar.ActionTextColor = UIColor.Green; snackbar.ActionBlock = (t) => { Console.WriteLine("clicked yes"); }; // Action 2 snackbar.SecondActionText = "No"; snackbar.SecondActionTextColor = UIColor.Magenta; snackbar.SecondActionBlock = (t) => { Console.WriteLine("clicked no"); }; // Dismiss Callback snackbar.DismissBlock = (t) => { Console.WriteLine("dismissed snackbar"); }; snackbar.Icon = UIImage.FromBundle("EmojiCool"); snackbar.LocationType = TTGSnackbarLocation.Top; snackbar.Show(); }
public async Task SnackSuccess(string message) { var snackbar = new TTGSnackbar(message); snackbar.BackgroundColor = UIKit.UIColor.Red; snackbar.MessageTextColor = UIColor.White; snackbar.Duration = TimeSpan.FromSeconds(3); snackbar.Show(); }
protected override Task ProtectedFlashNotificationAsync(string message) { SensusContext.Current.MainThreadSynchronizer.ExecuteThreadSafe(() => { TTGSnackbar snackbar = new TTGSnackbar(message); snackbar.Duration = TimeSpan.FromSeconds(5); snackbar.Show(); }); return(Task.CompletedTask); }
public async Task SnackBar(string message, TypeSnack typesnack) { var snackbar = new TTGSnackbar(message); snackbar.CornerRadius = 8; snackbar.BottomMargin = 10; snackbar.TopMargin = 10; snackbar.LeftMargin = 10; snackbar.RightMargin = 10; snackbar.MessageTextColor = UIColor.White; snackbar.Message = message; if (typesnack == TypeSnack.Error) { snackbar.BackgroundColor = UIColor.FromRGB(244, 67, 54); snackbar.Show(); } else { snackbar.BackgroundColor = UIColor.FromRGB(30, 150, 144); snackbar.Show(); } }
protected override Task ProtectedFlashNotificationAsync(string message, Action callback) { return Task.Run(() => { SensusContext.Current.MainThreadSynchronizer.ExecuteThreadSafe(() => { TTGSnackbar snackbar = new TTGSnackbar(message); snackbar.Duration = TimeSpan.FromSeconds(5); snackbar.Show(); callback?.Invoke(); }); }); }
public async Task Snackbar(string message, string title, TypeSnackbar typeSnackbar) { var snackbar = new TTGSnackbar(message); if (typeSnackbar == TypeSnackbar.Success) { snackbar.MessageTextColor = UIKit.UIColor.White; snackbar.AnimationType = TTGSnackbarAnimationType.SlideFromBottomBackToBottom; snackbar.BackgroundColor = ColorHelper.FromHex("#1E9690"); snackbar.BottomMargin = 0; snackbar.TopMargin = 0; snackbar.LeftMargin = 0; snackbar.RightMargin = 0; snackbar.MessageTextAlign = UITextAlignment.Center; snackbar.MessageMarginLeft = 20; snackbar.MessageMarginRight = 20; snackbar.Height = 150; snackbar.LocationType = TTGSnackbarLocation.Top; snackbar.CornerRadius = 0; snackbar.Show(); } else { snackbar.MessageTextColor = UIKit.UIColor.White; snackbar.AnimationType = TTGSnackbarAnimationType.SlideFromBottomBackToBottom; snackbar.BackgroundColor = ColorHelper.FromHex("#F44336"); snackbar.BottomMargin = 0; snackbar.TopMargin = 0; snackbar.LeftMargin = 0; snackbar.RightMargin = 0; snackbar.MessageMarginLeft = 20; snackbar.MessageMarginRight = 20; snackbar.Height = 100; snackbar.MessageTextAlign = UITextAlignment.Center; snackbar.LocationType = TTGSnackbarLocation.Top; snackbar.CornerRadius = 0; snackbar.Show(); } }
public void Notify(string message) { Helper.RunOnMainThreadIfRequired(() => { TTGSnackbar snackbar = new TTGSnackbar(message) { // Note: This is the only working animation type in XF AnimationType = TTGSnackbarAnimationType.FadeInFadeOut, }; snackbar.Show(); }); }
public static void InvokeSnackBar(string message) { var snackbar = new TTGSnackbar(message); snackbar.Duration = TimeSpan.FromSeconds(3); snackbar.MessageTextColor = UIColor.White; UIColor oragecolor = new UIColor(new nfloat(255 / 255f), new nfloat(140 / 255f), new nfloat(0), 1); snackbar.BackgroundColor = oragecolor; snackbar.MessageTextAlign = UITextAlignment.Center; UIFont font = UIFont.FromName("Menlo", 16); snackbar.Show(); }
protected override Task <int> ShowAsSnackbarImplAsync(UserInfo userInfo) { var tcs = new TaskCompletionSource <int>(); var snackbar = new TTGSnackbar(userInfo.Message); snackbar.Duration = userInfo.SnackbarDuration; snackbar.AnimationType = TTGSnackbarAnimationType.SlideFromBottomBackToBottom; snackbar.CornerRadius = 0f; snackbar.LeftMargin = 0f; snackbar.RightMargin = 0f; snackbar.BottomMargin = 0f; AddDefaultButtonsToSnackbar(tcs, snackbar, userInfo.DefaultButtonTexts); SetResultToCancelledAfterDurationAsync(tcs, userInfo.SnackbarDuration).Ignore(); snackbar.Show(); return(tcs.Task); }
public void Notify(string message) { var snackbar = new TTGSnackbar(message); snackbar.ActionText = "OK"; snackbar.ActionBlock = (o) => { }; snackbar.ActionTextColor = UIColor.FromRGB(29, 145, 255); snackbar.Duration = TimeSpan.FromSeconds(3); snackbar.AnimationType = TTGSnackbarAnimationType.SlideFromBottomBackToBottom; snackbar.SeperateView.Alpha = 0; snackbar.LeftMargin = 0; snackbar.RightMargin = 0; snackbar.BottomMargin = 0; snackbar.CornerRadius = 0; snackbar.Show(); }
void DisplayMessage(string message, int duration, string actionText, ICommand actionCommand) { var snack = new TTGSnackbar(message); snack.Duration = TimeSpan.FromSeconds(duration); if (actionCommand != null) { snack.ActionText = actionText; snack.ActionBlock = (snackbar) => { if (actionCommand?.CanExecute(null) == true) { actionCommand?.Execute(null); } }; } snack.Show(); }
partial void buttonClicked(UIButton sender) { var snackbar = new TTGSnackbar("Hello Xamarin snackbar", TTGSnackbarDuration.Long); snackbar.AnimationType = TTGSnackbarAnimationType.FadeInFadeOut; // Action 1 snackbar.ActionText = "Yes"; snackbar.ActionTextColor = UIColor.Green; snackbar.ActionBlock = (t) => { Console.WriteLine("clicked yes"); }; // Action 2 snackbar.SecondActionText = "No"; snackbar.SecondActionTextColor = UIColor.Magenta; snackbar.SecondActionBlock = (t) => { Console.WriteLine("clicked no"); }; // Dissmiss Callback snackbar.DismissBlock = (t) => { Console.WriteLine("dismissed snackbar"); }; snackbar.Show(); }
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); }