コード例 #1
0
ファイル: ToastManager.cs プロジェクト: akobr/strong-beaver
        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);
        }
コード例 #2
0
ファイル: ToastManager.cs プロジェクト: akobr/strong-beaver
        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;
                }
            });
        }
コード例 #3
0
ファイル: ToastManager.cs プロジェクト: akobr/strong-beaver
        private void MessageTapped(UIGestureRecognizer recognizer)
        {
            ToastView view = recognizer.View as ToastView;

            if (view != null)
            {
                DismissMessage(view, true);
            }
        }
コード例 #4
0
        public override bool Equals(object obj)
        {
            if (!(obj is ToastView))
            {
                return(false);
            }

            ToastView messageView = (ToastView)obj;

            return(Message == messageView.Description);
        }
コード例 #5
0
ファイル: ToastManager.cs プロジェクト: akobr/strong-beaver
 private static void InvokeDismissEvent(ToastView messageView, bool dismissedByTap)
 {
     if (!dismissedByTap)
     {
         messageView.OnDismiss?.Invoke();
     }
     else
     {
         messageView.OnTapped?.Invoke();
     }
 }
コード例 #6
0
ファイル: ToastManager.cs プロジェクト: akobr/strong-beaver
        private void DismissMessage(object messageView)
        {
            ToastView view = messageView as ToastView;

            if (view == null)
            {
                return;
            }

            InvokeOnMainThread(() => DismissMessage(view, false));
        }
コード例 #7
0
ファイル: ToastManager.cs プロジェクト: akobr/strong-beaver
        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);
        }
コード例 #8
0
ファイル: ToastManager.cs プロジェクト: akobr/strong-beaver
        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));
            }
        }
コード例 #9
0
ファイル: ToastManager.cs プロジェクト: akobr/strong-beaver
        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();
            }
        }
コード例 #10
0
ファイル: ToastManager.cs プロジェクト: akobr/strong-beaver
 private bool IsEqualLastMessage(ToastView message)
 {
     return(message.Equals(lastMessage));
 }