Example #1
0
        public void Handle(UIView view, T viewModel)
        {
            _viewModel = viewModel;
            _lastContextMenuComponent = _contextMenuComponentFunc.Execute(viewModel);

            if (_lastContextMenuComponent == null)
            {
                return;
            }

            var menuController = UIMenuController.SharedMenuController;

            if (menuController.MenuVisible)
            {
                return;
            }

            _notification?.Dispose();
            _notification = UIMenuController.Notifications.ObserveWillHideMenu(menuController, HideNotificationHandler);

            Execute.BeginOnUIThread(() =>
            {
                if (!menuController.MenuVisible)
                {
                    var targetRect = CalculateMenuPosition(view);

                    menuController.MenuItems = _lastContextMenuComponent.BuildMenuItems();
                    menuController.Update();
                    menuController.SetTargetRect(targetRect, view);
                    menuController.SetMenuVisible(true, true);
                }
            });
        }