private ToastView GetNextMessage() { ToastView message = null; if (!DiscardRepeated) { return(messageBarQueue.Dequeue()); } // Removes all except the last message. while (messageBarQueue.Count > 0) { message = messageBarQueue.Dequeue(); if (!IsEqualLastMessage(message)) { break; } message = null; } lastMessage = message; return(message); }
private void DismissMessage(ToastView messageView, bool dismissedByTap) { if (messageView == null || messageView.Hit) { return; } messageView.Hit = true; UIView.Animate( DismissAnimationDuration, () => { messageView.Frame = new CGRect( messageView.Frame.X, initialPosition, messageView.Frame.Width, messageView.Frame.Height); }, () => { MessageVisible = false; messageView.RemoveFromSuperview(); InvokeDismissEvent(messageView, dismissedByTap); if (messageBarQueue.Count > 0) { ShowNextMessage(); } else { lastMessage = null; } }); }
private void MessageTapped(UIGestureRecognizer recognizer) { ToastView view = recognizer.View as ToastView; if (view != null) { DismissMessage(view, true); } }
public override bool Equals(object obj) { if (!(obj is ToastView)) { return(false); } ToastView messageView = (ToastView)obj; return(Message == messageView.Description); }
private static void InvokeDismissEvent(ToastView messageView, bool dismissedByTap) { if (!dismissedByTap) { messageView.OnDismiss?.Invoke(); } else { messageView.OnTapped?.Invoke(); } }
private void DismissMessage(object messageView) { ToastView view = messageView as ToastView; if (view == null) { return; } InvokeOnMainThread(() => DismissMessage(view, false)); }
public void HideAll() { var subviews = MessageWindowView.Subviews; foreach (UIView subview in subviews) { ToastView view = subview as ToastView; view?.RemoveFromSuperview(); } MessageVisible = false; messageBarQueue.Clear(); CancelPreviousPerformRequest(this); }
private void ShowNextMessage() { ToastView messageView = GetNextMessage(); if (messageView != null) { MessageVisible = true; if (ShowAtTheBottom) { initialPosition = MessageWindowView.Bounds.Height + messageView.Height; showPosition = MessageWindowView.Bounds.Height - messageView.Height; } else { initialPosition = MessageWindowView.Bounds.Y - messageView.Height; showPosition = MessageWindowView.Bounds.Y + MessageBarOffset; } messageView.Frame = new CGRect(0, initialPosition, messageView.Width, messageView.Height); messageView.Hidden = false; messageView.SetNeedsDisplay(); var gest = new UITapGestureRecognizer(MessageTapped); messageView.AddGestureRecognizer(gest); UIView.Animate( DismissAnimationDuration, () => messageView.Frame = new CGRect( messageView.Frame.X, showPosition, messageView.Width, messageView.Height)); // Need a better way of dissmissing the method var dismiss = new Timer( DismissMessage, messageView, messageView.Duration, TimeSpan.FromMilliseconds(-1)); } }
public void ShowMessage( string message, TimeSpan?duration = null, Action onTapped = null, Action onDismiss = null) { var messageView = new ToastView(message) { OnTapped = onTapped, OnDismiss = onDismiss, Hidden = true, Duration = duration ?? TimeSpan.FromSeconds(2.5) }; MessageWindowView.AddSubview(messageView); MessageWindowView.BringSubviewToFront(messageView); messageBarQueue.Enqueue(messageView); if (!MessageVisible) { ShowNextMessage(); } }
private bool IsEqualLastMessage(ToastView message) { return(message.Equals(lastMessage)); }