Skip to content

Commit

Permalink
Fixing an issue with the keyboard shifting too far up
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpatarinski committed Jan 4, 2016
1 parent 0ab6e36 commit 40f892f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Expand Up @@ -17,6 +17,7 @@ public class KeyboardOverlapRenderer : PageRenderer
NSObject _keyboardHideObserver;
private bool _pageWasShiftedUp;
private double _activeViewBottom;
private bool _isKeyboardShown;

public static void Init ()
{
Expand Down Expand Up @@ -57,6 +58,7 @@ void RegisterForKeyboardNotifications ()

void UnregisterForKeyboardNotifications ()
{
_isKeyboardShown = false;
if (_keyboardShowObserver != null) {
NSNotificationCenter.DefaultCenter.RemoveObserver (_keyboardShowObserver);
_keyboardShowObserver.Dispose ();
Expand All @@ -72,9 +74,10 @@ void UnregisterForKeyboardNotifications ()

protected virtual void OnKeyboardShow (NSNotification notification)
{
if (!IsViewLoaded)
if (!IsViewLoaded || _isKeyboardShown)
return;


_isKeyboardShown = true;
var activeView = View.FindFirstResponder ();

if (activeView == null)
Expand All @@ -87,7 +90,6 @@ protected virtual void OnKeyboardShow (NSNotification notification)
return;

if (isOverlapping) {

_activeViewBottom = activeView.GetViewRelativeBottom (View);
ShiftPageUp (keyboardFrame.Height, _activeViewBottom);
}
Expand All @@ -98,7 +100,8 @@ private void OnKeyboardHide (NSNotification notification)
if (!IsViewLoaded)
return;

var keyboardFrame = UIKeyboard.FrameBeginFromNotification (notification);
_isKeyboardShown = false;
var keyboardFrame = UIKeyboard.FrameEndFromNotification (notification);

if (_pageWasShiftedUp) {
ShiftPageDown (keyboardFrame.Height, _activeViewBottom);
Expand Down
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>Xam.Plugins.Forms.KeyboardOverlap</id>
<version>1.0.0.2</version>
<version>1.0.0.3</version>
<title>KeyboardOverlap for Xamarin.Forms</title>
<authors>Paul Patarinski</authors>
<owners>Paul Patarinski</owners>
Expand All @@ -12,7 +12,7 @@
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Keyboard Overlap for your Xamarin.Forms project fixes the Keyboard Overlap issue on iOS. Ensure you call KeyboardOverlapRenderer.Init() in your iOS project! VISIT THE PROJECT URL for more info.</description>
<summary>Use an KeyboardOverlap in your Xamarin.Forms projects! Ensure you call KeyboardOverlapRenderer.Init() in your iOS project! VISIT THE PROJECT URL for more info.</summary>
<releaseNotes>Upgrading to Forms 2.0.0.6490</releaseNotes>
<releaseNotes>Fixing an issue with Release mode linking removing the plugin</releaseNotes>
<tags>keyboard, overlap, keyboard overlap, iOS, xamarin, pcl, xam.pcl, xamarin.forms</tags>
<dependencies>
<dependency id="Xamarin.Forms" version="2.0.0.6490" />
Expand Down

0 comments on commit 40f892f

Please sign in to comment.