示例#1
0
        void ShowNextMessage()
        {
            if (MessageBarQueue.Count > 0)
            {
                MessageVisible = true;
                MessageView messageView = MessageBarQueue.Dequeue();
                messageView.Frame  = new RectangleF(0, -messageView.Height, messageView.Width, messageView.Height);
                messageView.Hidden = false;
                messageView.SetNeedsDisplay();

                var gest = new UITapGestureRecognizer(MessageTapped);
                messageView.AddGestureRecognizer(gest);
                if (messageView == null)
                {
                    return;
                }

                UIView.Animate(DismissAnimationDuration,
                               () =>
                               messageView.Frame = new RectangleF(messageView.Frame.X,
                                                                  MessageBarOffset + messageView.Frame.Y + messageView.Height,
                                                                  messageView.Width, messageView.Height)
                               );

                //Need a better way of dissmissing the method
                var dismiss = new Timer(DismissMessage, messageView, TimeSpan.FromSeconds(DisplayDelay),
                                        TimeSpan.FromMilliseconds(-1));
            }
        }
        async void DismissMessage(MessageView messageView, bool clicked)
        {
            if (messageView != null && !messageView.Hit)
            {
                messageView.Hit = true;
                UIView.Animate(AnimationDuration + .1, 0, UIViewAnimationOptions.CurveEaseOut, () =>
                {
                    //messageView.Alpha = 0f;
                    messageView.Frame = new CGRect(messageView.Frame.X, initialPosition, messageView.Frame.Width, messageView.Frame.Height);
                }, () =>
                {
                    MessageVisible = false;
                    messageView.RemoveFromSuperview();

                    var action = messageView.OnDismiss;
                    if (action != null)
                    {
                        action(clicked);
                    }

                    if (MessageBarQueue.Count > 0)
                    {
                        ShowNextMessage();
                    }
                    else
                    {
                        lastMessage = null;
                    }
                });
            }
        }
示例#3
0
        void DismissMessage(MessageView messageView)
        {
            if (messageView != null && !messageView.Hit)
            {
                messageView.Hit = true;
                UIView.Animate(DismissAnimationDuration,
                               delegate {
                    messageView.Frame = new RectangleF(
                        messageView.Frame.X,
                        -(messageView.Frame.Height - MessageBarOffset),
                        messageView.Frame.Width, messageView.Frame.Height);
                },
                               delegate {
                    MessageVisible = false;
                    messageView.RemoveFromSuperview();

                    var action = messageView.OnDismiss;
                    if (action != null)
                    {
                        action();
                    }

                    if (MessageBarQueue.Count > 0)
                    {
                        ShowNextMessage();
                    }
                }
                               );
            }
        }
        MessageView GetNextMessage()
        {
            MessageView message = null;

            if (!DiscardRepeated)
            {
                return(MessageBarQueue.Dequeue());
            }

            while (MessageBarQueue.Count > 0)
            {
                message = MessageBarQueue.Dequeue();

                if (IsEqualLastMessage(message))
                {
                    message = null;
                }
                else
                {
                    break;
                }
            }

            lastMessage = message;

            return(message);
        }
        /// <summary>
        /// Dismisses the message.
        /// </summary>
        /// <param name="messageView">
        /// The message view.
        /// </param>
        /// <param name="dismissedByTap">
        /// if set to <c>true</c> [dismissed by tap].
        /// </param>
        private void DismissMessage(MessageView messageView, bool dismissedByTap)
        {
            if (messageView != null && !messageView.Hit)
            {
                messageView.Hit = true;
                UIView.Animate(
                    DismissAnimationDuration,
                    () => {
                    messageView.Frame = new CGRect(
                        messageView.Frame.X,
                        this.initialPosition,
                        messageView.Frame.Width,
                        messageView.Frame.Height);
                },
                    () => {
                    this.MessageVisible = false;
                    messageView.RemoveFromSuperview();

                    InvokeDismissEvent(messageView, dismissedByTap);

                    if (this.MessageBarQueue.Count > 0)
                    {
                        this.ShowNextMessage();
                    }
                    else
                    {
                        this.lastMessage = null;
                    }
                });
            }
        }
        /// <summary>
        /// Gets the next message.
        /// </summary>
        /// <returns>
        /// The <see cref="MessageView"/>.
        /// </returns>
        private MessageView GetNextMessage()
        {
            MessageView message = null;

            if (!this.DiscardRepeated)
            {
                return(this.MessageBarQueue.Dequeue());
            }

            // Removes all except the last message.
            while (this.MessageBarQueue.Count > 0)
            {
                message = this.MessageBarQueue.Dequeue();

                if (!this.IsEqualLastMessage(message))
                {
                    break;
                }

                message = null;
            }

            this.lastMessage = message;

            return(message);
        }
        /// <summary>
        /// Shows the message.
        ///     <para>
        /// Adds a new message to the queue, and shows it when all previous messages has finished showing.
        ///         If no messages exists in the queue, will (obviously) be displayed instantly.
        ///     </para>
        /// </summary>
        /// <param name="title">
        /// Message Bar title
        /// </param>
        /// <param name="description">
        /// Message Bar description
        /// </param>
        /// <param name="type">
        /// Message type
        /// </param>
        /// <param name="duration">
        /// The duration. Default (null) is 3 Seconds.
        /// </param>
        /// <param name="onTapped">
        /// OnTapped callback.
        /// </param>
        /// <param name="onDismiss">
        /// OnDismiss callback
        /// </param>
        public void ShowMessage(
            string title,
            string description,
            MessageType type,
            TimeSpan?duration = null,
            Action onTapped   = null,
            Action onDismiss  = null)
        {
            var messageView = new MessageView(title, description, type)
            {
                StylesheetProvider = this,
                OnTapped           = onTapped,
                OnDismiss          = onDismiss,
                Hidden             = true,
                Duration           = duration ?? TimeSpan.FromSeconds(3)
            };

            this.MessageWindowView.AddSubview(messageView);
            this.MessageWindowView.BringSubviewToFront(messageView);

            this.MessageBarQueue.Enqueue(messageView);

            if (!this.MessageVisible)
            {
                this.ShowNextMessage();
            }
        }
        void DismissMessage(MessageView messageView)
        {
            if (messageView != null && !messageView.Hit)
            {
                messageView.Hit = true;
                UIView.Animate(DismissAnimationDuration,
                               delegate {
                    messageView.Frame = new CGRect(
                        messageView.Frame.X,
                        initialPosition,
                        messageView.Frame.Width, messageView.Frame.Height);
                },
                               delegate {
                    MessageVisible = false;
                    messageView.RemoveFromSuperview();

                    messageView.OnDismiss?.Invoke();

                    if (MessageBarQueue.Count > 0)
                    {
                        ShowNextMessage();
                    }
                    else
                    {
                        lastMessage = null;
                    }
                }
                               );
            }
        }
        /// <summary>
        /// Shows the message
        /// </summary>
        /// <param name="title">Messagebar title</param>
        /// <param name="description">Messagebar description</param>
        /// <param name="type">Message type</param>
        /// <param name = "onDismiss">OnDismiss callback</param>
        public void ShowMessage(string title, string description, MessageType type, Action onDismiss)
        {
            var messageView = new MessageView(title, description, type);

            messageView.StylesheetProvider = this;
            messageView.OnDismiss          = onDismiss;
            messageView.Hidden             = true;
            UIApplication.SharedApplication.KeyWindow.InsertSubview(messageView, 1);
            MessageBarQueue.Enqueue(messageView);

            if (!MessageVisible)
            {
                ShowNextMessage();
            }
        }
        /// <summary>
        ///     Hides all currently-displayed messages, and discards the Message queue.
        /// </summary>
        public void HideAll()
        {
            var subviews = this.MessageWindowView.Subviews;

            foreach (UIView subview in subviews)
            {
                var view = subview as MessageView;
                if (view != null)
                {
                    MessageView currentMessageView = view;
                    currentMessageView.RemoveFromSuperview();
                }
            }

            this.MessageVisible = false;
            this.MessageBarQueue.Clear();
            CancelPreviousPerformRequest(this);
        }
        /// <summary>
        /// Hides all messages
        /// </summary>
        public void HideAll()
        {
            MessageView currentMessageView = null;
            var         subviews           = UIApplication.SharedApplication.KeyWindow.Subviews;

            foreach (UIView subview in subviews)
            {
                var view = subview as MessageView;
                if (view != null)
                {
                    currentMessageView = view;
                    currentMessageView.RemoveFromSuperview();
                }
            }

            MessageVisible = false;
            MessageBarQueue.Clear();
            CancelPreviousPerformRequest(this);
        }
 /// <summary>
 /// Invokes the correct dismiss event, depending on the <see cref="dismissedByTap"/> value.
 /// </summary>
 /// <param name="messageView">
 /// The message view.
 /// </param>
 /// <param name="dismissedByTap">
 /// if set to <c>true</c> [dismissed by tap].
 /// </param>
 private static void InvokeDismissEvent(MessageView messageView, bool dismissedByTap)
 {
     if (!dismissedByTap)
     {
         var onDismiss = messageView.OnDismiss;
         if (onDismiss != null)
         {
             onDismiss();
         }
     }
     else
     {
         var onTapped = messageView.OnTapped;
         if (onTapped != null)
         {
             onTapped();
         }
     }
 }
        void ShowNextMessage()
        {
            MessageView 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);
                if (messageView == null)
                {
                    return;
                }

                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, TimeSpan.FromSeconds(DisplayDelay),
                                        TimeSpan.FromMilliseconds(-1));
            }
        }
        void ShowNextMessage(double duration = DisplayDelay)
        {
            MessageView messageView = GetNextMessage();

            if (messageView != null)
            {
                MessageVisible = true;

                if (ShowAtTheBottom)
                {
                    initialPosition = MessageWindowView.Bounds.Height + messageView.Height;
                    showPosition    = MessageWindowView.Bounds.Height - messageView.Height - messageView.Margin;
                }
                else
                {
                    initialPosition = MessageWindowView.Bounds.Y - messageView.Height;
                    showPosition    = MessageWindowView.Bounds.Y;
                }

                messageView.Frame  = new CGRect(messageView.Margin, initialPosition, messageView.Width, messageView.Height);
                messageView.Hidden = false;
                messageView.SetNeedsDisplay();

                var gest = new UITapGestureRecognizer(MessageTapped);
                messageView.AddGestureRecognizer(gest);
                if (messageView == null)
                {
                    return;
                }

                //messageView.Alpha = 0f;
                UIView.Animate(AnimationDuration, 0, UIViewAnimationOptions.CurveEaseIn, () =>
                {
                    //messageView.Alpha = 1f;
                    messageView.Frame = new CGRect(messageView.Frame.X, showPosition, messageView.Width, messageView.Height);
                }, null);

                //Need a better way of dissmissing the method
                new Timer(DismissMessage, messageView, TimeSpan.FromSeconds(duration), TimeSpan.FromMilliseconds(-1));
            }
        }
		public MessageBarStyleSheet StyleSheetForMessageView (MessageView messageView)
		{
			return StyleSheet;
		}
 bool IsEqualLastMessage(MessageView message)
 {
     return(message.Equals(lastMessage));
 }
		bool IsEqualLastMessage(MessageView message){
			return message.Equals(lastMessage);
		}
		void DismissMessage (MessageView messageView)
		{
			if (messageView != null && !messageView.Hit) {

				messageView.Hit = true;
				UIView.Animate (DismissAnimationDuration,
					delegate {
						messageView.Frame = new CGRect (
							messageView.Frame.X,
							initialPosition,
							messageView.Frame.Width, messageView.Frame.Height);
					},
					delegate {
						MessageVisible = false;
						messageView.RemoveFromSuperview ();

						messageView.OnDismiss?.Invoke();

						if (MessageBarQueue.Count > 0) {
							ShowNextMessage ();
						}
                        else {
							lastMessage = null;
						}
					}
				);
			}
		}
		MessageView GetNextMessage ()
		{
			MessageView message = null;

			if (!DiscardRepeated)
				return MessageBarQueue.Dequeue ();

			while (MessageBarQueue.Count > 0) {
				message = MessageBarQueue.Dequeue ();

				if (IsEqualLastMessage (message))
					message = null;
				else
					break;
			}

			lastMessage = message;

			return message;
		}
		/// <summary>
		/// Shows the message
		/// </summary>
		/// <param name="title">Messagebar title</param>
		/// <param name="description">Messagebar description</param>
		/// <param name="type">Message type</param>
		/// <param name = "onDismiss">OnDismiss callback</param>
		public void ShowMessage (string title, string description, MessageType type, Action onDismiss, Action onTap)
		{
			var messageView = new MessageView (title, description, type);
			messageView.StylesheetProvider = this;
			messageView.OnDismiss = onDismiss;
			messageView.Hidden = true;
            messageView.OnTap = onTap;

			//UIApplication.SharedApplication.KeyWindow.InsertSubview (messageView, 1);

			MessageWindowView.AddSubview (messageView);
			MessageWindowView.BringSubviewToFront (messageView);

			MessageBarQueue.Enqueue (messageView);

			if (!MessageVisible)
				ShowNextMessage ();
		}
 /// <summary>
 /// Determines whether the specified message is equal to the last message handled.
 /// </summary>
 /// <param name="message">
 /// The message.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 private bool IsEqualLastMessage(MessageView message)
 {
     return(message.Equals(this.lastMessage));
 }
		void DismissMessage (MessageView messageView)
		{
			if (messageView != null && !messageView.Hit) {

				messageView.Hit = true;
				UIView.Animate (DismissAnimationDuration, 
					delegate {
						messageView.Frame = new RectangleF (
							messageView.Frame.X, 
							- (messageView.Frame.Height - MessageBarOffset), 
							messageView.Frame.Width, messageView.Frame.Height);
					}, 
					delegate {
						MessageVisible = false;
						messageView.RemoveFromSuperview ();

						var action = messageView.OnDismiss;
						if (action != null) {
							action ();
						}

						if (MessageBarQueue.Count > 0) {
							ShowNextMessage ();
						}
					}
				);
			}
		}
示例#23
0
		async void DismissMessage(MessageView messageView, bool clicked)
		{
			if(messageView != null && !messageView.Hit)
			{
				messageView.Hit = true;
				UIView.Animate(AnimationDuration + .1, 0, UIViewAnimationOptions.CurveEaseOut, () =>
				{
					//messageView.Alpha = 0f;
					messageView.Frame = new CGRect(messageView.Frame.X, initialPosition, messageView.Frame.Width, messageView.Frame.Height);
				}, () =>
				{
					MessageVisible = false;
					messageView.RemoveFromSuperview();

					var action = messageView.OnDismiss;
					if(action != null)
					{
						action(clicked);
					}

					if(MessageBarQueue.Count > 0)
					{
						ShowNextMessage();
					}
					else
					{
						lastMessage = null;
					}
				});
			}
		}
        /// <summary>
        /// Gets the next message.
        /// </summary>
        /// <returns>
        /// The <see cref="MessageView"/>.
        /// </returns>
        private MessageView GetNextMessage()
        {
            MessageView message = null;

            if (!this.DiscardRepeated)
            {
                return this.MessageBarQueue.Dequeue();
            }

            // Removes all except the last message.
            while (this.MessageBarQueue.Count > 0)
            {
                message = this.MessageBarQueue.Dequeue();

                if (!this.IsEqualLastMessage(message))
                {
                    break;
                }

                message = null;
            }

            this.lastMessage = message;

            return message;
        }
 /// <summary>
 /// Determines whether the specified message is equal to the last message handled.
 /// </summary>
 /// <param name="message">
 /// The message.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 private bool IsEqualLastMessage(MessageView message)
 {
     return message.Equals(this.lastMessage);
 }
 /// <summary>
 /// Invokes the correct dismiss event, depending on the <see cref="dismissedByTap"/> value.
 /// </summary>
 /// <param name="messageView">
 /// The message view.
 /// </param>
 /// <param name="dismissedByTap">
 /// if set to <c>true</c> [dismissed by tap].
 /// </param>
 private static void InvokeDismissEvent(MessageView messageView, bool dismissedByTap)
 {
     if (!dismissedByTap)
     {
         var onDismiss = messageView.OnDismiss;
         if (onDismiss != null)
         {
             onDismiss();
         }
     }
     else
     {
         var onTapped = messageView.OnTapped;
         if (onTapped != null)
         {
             onTapped();
         }
     }
 }
        /// <summary>
        /// Dismisses the message.
        /// </summary>
        /// <param name="messageView">
        /// The message view.
        /// </param>
        /// <param name="dismissedByTap">
        /// if set to <c>true</c> [dismissed by tap].
        /// </param>
        private void DismissMessage(MessageView messageView, bool dismissedByTap)
        {
            if (messageView != null && !messageView.Hit)
            {
                messageView.Hit = true;
                UIView.Animate(
                    DismissAnimationDuration, 
                    () => {
                        messageView.Frame = new CGRect(
                            messageView.Frame.X, 
                            this.initialPosition, 
                            messageView.Frame.Width, 
                            messageView.Frame.Height);
                    }, 
                    () => {
                        this.MessageVisible = false;
                        messageView.RemoveFromSuperview();

                        InvokeDismissEvent(messageView, dismissedByTap);

                        if (this.MessageBarQueue.Count > 0)
                        {
                            this.ShowNextMessage();
                        }
                        else
                        {
                            this.lastMessage = null;
                        }
                    });
            }
        }
示例#28
0
 public MessageBarStyleSheet StyleSheetForMessageView(MessageView messageView)
 {
     return(StyleSheet);
 }
        /// <summary>
        /// Shows the message.
        ///     <para>
        /// Adds a new message to the queue, and shows it when all previous messages has finished showing.
        ///         If no messages exists in the queue, will (obviously) be displayed instantly.
        ///     </para>
        /// </summary>
        /// <param name="title">
        /// Message Bar title
        /// </param>
        /// <param name="description">
        /// Message Bar description
        /// </param>
        /// <param name="type">
        /// Message type
        /// </param>
        /// <param name="duration">
        /// The duration. Default (null) is 3 Seconds.
        /// </param>
        /// <param name="onTapped">
        /// OnTapped callback.
        /// </param>
        /// <param name="onDismiss">
        /// OnDismiss callback
        /// </param>
        public void ShowMessage(
            string title, 
            string description, 
            MessageType type, 
            TimeSpan? duration = null, 
            Action onTapped = null, 
            Action onDismiss = null)
        {
            var messageView = new MessageView(title, description, type)
            {
                StylesheetProvider = this, 
                OnTapped = onTapped, 
                OnDismiss = onDismiss, 
                Hidden = true, 
                Duration = duration ?? TimeSpan.FromSeconds(3)
            };

            this.MessageWindowView.AddSubview(messageView);
            this.MessageWindowView.BringSubviewToFront(messageView);

            this.MessageBarQueue.Enqueue(messageView);

            if (!this.MessageVisible)
            {
                this.ShowNextMessage();
            }
        }