Example #1
0
        //This method allows us to update the insets if the Frame changes
        internal void UpdateInsets()
        {
            //being called from LayoutSubviews but keyboard wasn't shown yet
            if (_lastKeyboardRect.IsEmpty)
            {
                return;
            }

            var window = _fetchWindow();

            // Code left verbose to make its operation more obvious
            if (window == null)
            {
                // we are not currently displayed and can safely ignore this
                // most likely this renderer is on a page which is currently not displayed (e.g. in NavController)
                return;
            }

            var field = _targetView.FindFirstResponder();

            //the view that is triggering the keyboard is not inside our UITableView?
            //if (field == null)
            //	return;

            var boundsSize = _targetView.Frame.Size;

            //since our keyboard frame is RVC CoordinateSpace, lets convert it to our targetView CoordinateSpace
            var rect = _targetView.Superview.ConvertRectFromView(_lastKeyboardRect, null);
            //let's see how much does it cover our target view
            var overlay = RectangleF.Intersect(rect, _targetView.Frame);

            _currentInset = _targetView.ContentInset;
            _setInsetAction(new UIEdgeInsets(0, 0, overlay.Height, 0));

            if (field is UITextView && _setContentOffset != null)
            {
                var keyboardTop   = boundsSize.Height - overlay.Height;
                var fieldPosition = field.ConvertPointToView(field.Frame.Location, _targetView.Superview);
                var fieldBottom   = fieldPosition.Y + field.Frame.Height;
                var offset        = fieldBottom - keyboardTop;
                if (offset > 0)
                {
                    _setContentOffset(new PointF(0, offset));
                }
            }
        }