Exemple #1
0
        private void SetupNotificationView()
        {
            // Setup subviews
            _notificationViewContainer = new UIView
            {
                BackgroundColor = Appearance.Colors.NatificationPanel,
                Frame           = new CGRect(0, -64, View.Frame.Width, 64)
            };

            _avatar      = new AvatarImageView();
            _displayName = new UILabel {
                TextColor = iOS.Appearance.Colors.White, Font = Appearance.Fonts.LatoBoldWithSize(14), Lines = 1
            };
            _text = new UILabel {
                TextColor = iOS.Appearance.Colors.White, Font = Appearance.Fonts.LatoWithSize(11.86f), Lines = 1, LineBreakMode = UILineBreakMode.TailTruncation
            };
            _bottomSwipHandle = new UIView {
                BackgroundColor = Appearance.Colors.White
            };
            _bottomSwipHandle.Layer.CornerRadius = 2.0f;

            // Gesture recognizers
            _tap = new UITapGestureRecognizer(gesture =>
            {
                if (AppDelegate.MainWindow.RootViewController.VisibleViewController().IsChatConversation())
                {
                    var chatConversation = (ChatConversationView)AppDelegate.MainWindow.RootViewController.VisibleViewController();

                    var viewModel = chatConversation.DataContext as ChatConversationViewModel;

                    if (viewModel != null && viewModel.Id != _conversationId)
                    {
                        chatConversation.DismissViewController(false, OpenChatView);
                    }

                    return;
                }

                if (AppDelegate.MainWindow.RootViewController.VisibleViewController() is ImageZoomView)
                {
                    var imageZoom = (ImageZoomView)AppDelegate.MainWindow.RootViewController.VisibleViewController();

                    imageZoom.DismissModalViewController(false);
                }

                if (AppDelegate.MainWindow.RootViewController.VisibleViewController() is UserView)
                {
                    var userView = (UserView)AppDelegate.MainWindow.RootViewController.VisibleViewController();

                    userView.DismissModalViewController(false);
                }

                OpenChatView();
            })
            {
                NumberOfTapsRequired = 1
            };

            _swipe = new UISwipeGestureRecognizer(() =>
            {
                HideNotification();
            })
            {
                Direction = UISwipeGestureRecognizerDirection.Up
            };

            // Add gestures to views
            _notificationViewContainer.AddGestureRecognizer(_tap);
            _notificationViewContainer.AddGestureRecognizer(_swipe);
            _avatar.AddGestureRecognizer(_tap);
            _avatar.AddGestureRecognizer(_swipe);
            _displayName.AddGestureRecognizer(_tap);
            _displayName.AddGestureRecognizer(_swipe);
            _text.AddGestureRecognizer(_tap);
            _text.AddGestureRecognizer(_swipe);
            _bottomSwipHandle.AddGestureRecognizer(_swipe);

            // Enable user interaction
            _notificationViewContainer.UserInteractionEnabled = true;
            _avatar.UserInteractionEnabled           = true;
            _displayName.UserInteractionEnabled      = true;
            _text.UserInteractionEnabled             = true;
            _bottomSwipHandle.UserInteractionEnabled = true;
            View.UserInteractionEnabled = true;



            // Add subviews to container
            _notificationViewContainer.AddSubviews(_avatar, _displayName, _text, _bottomSwipHandle);

            // Setup constraints
            _notificationViewContainer.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();

            _notificationViewContainer.AddConstraints(
                _avatar.AtLeftOf(_notificationViewContainer, 10),
                _avatar.WithSameCenterY(_notificationViewContainer),
                _avatar.Width().EqualTo(40),
                _avatar.Height().EqualTo(40),

                _displayName.ToRightOf(_avatar, 10),
                _displayName.AtRightOf(_notificationViewContainer, 10),
                _displayName.WithSameCenterY(_avatar).Minus(8),

                _text.WithSameCenterY(_avatar).Plus(8),
                _text.WithSameLeft(_displayName),
                _text.WithSameRight(_displayName),

                _bottomSwipHandle.AtBottomOf(_notificationViewContainer, 2),
                _bottomSwipHandle.WithSameCenterX(_notificationViewContainer),
                _bottomSwipHandle.Width().EqualTo(20),
                _bottomSwipHandle.Height().EqualTo(5)
                );

            // Add container to viewdontroller
            View.AddSubviews(_notificationViewContainer);

            // Setup timer for hiding
            _timer = new Timer(3000)
            {
                AutoReset = false
            };
            _timer.Elapsed += (sender, args) =>
            {
                UIApplication.SharedApplication.InvokeOnMainThread(HideNotification);
            };
        }