Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,36 @@ public void SafeAreaPerEdgeValidation()
Assert.That(containerPositionWithoutSoftInput.Height, Is.EqualTo(containerPosition.Height), "ContentGrid height should return to original when Soft Input is dismissed with Container edges");
});
}

[Test]
[Category(UITestCategories.SafeAreaEdges)]
public void SafeAreaNoWhiteSpaceAfterKeyboardDismissAndEdgeToggle()
{
App.WaitForElement("ContentGrid");

App.Tap("GridResetAllButton");
var baselinePosition = App.WaitForElement("ContentGrid").GetRect();

App.Tap("SoftInputTestEntry");
App.RetryAssert(() =>
{
var withKeyboard = App.WaitForElement("ContentGrid").GetRect();
Assert.That(withKeyboard.Height, Is.LessThan(baselinePosition.Height),
"ContentGrid should shrink when keyboard is showing with SafeAreaEdges=All");
});

App.Tap("GridSetContainerButton");
App.DismissKeyboard();
App.Tap("GridResetAllButton");

App.RetryAssert(() =>
{
var finalPosition = App.WaitForElement("ContentGrid").GetRect();
Assert.That(finalPosition.Height, Is.EqualTo(baselinePosition.Height).Within(1),
"ContentGrid height should match baseline after toggling edges with keyboard dismiss — no white space (#34846)");
Assert.That(finalPosition.Y, Is.EqualTo(baselinePosition.Y).Within(1),
"ContentGrid Y should match baseline after toggling edges with keyboard dismiss");
});
}
}
#endif
11 changes: 10 additions & 1 deletion src/Core/src/Platform/iOS/MauiView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ void UnsubscribeFromKeyboardNotifications()
NSNotificationCenter.DefaultCenter.RemoveObserver(hideObserver);
_keyboardWillHideObserver = null;
}

// Clear stale keyboard state so that re-subscribing later doesn't
// pick up a phantom keyboard frame from a previous session (#34846).
if (_isKeyboardShowing)
{
ClearKeyboardState();
}
Comment on lines +327 to +332
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearing keyboard state during UnsubscribeFromKeyboardNotifications() fixes the stale-padding case when the keyboard is dismissed while unsubscribed, but it can regress the opposite flow: if SafeAreaEdges toggles back to a SoftInput/All mode while the keyboard is still visible, the view will re-subscribe without receiving a new WillShow notification, leaving _isKeyboardShowing false and _keyboardFrame empty, so no keyboard padding will be applied until the keyboard changes again. Consider keeping keyboard observers active until WillHide is observed (then unsubscribe), or keep the last keyboard frame and rehydrate _isKeyboardShowing on subscribe when a first responder exists.

Copilot uses AI. Check for mistakes.
}

void UpdateKeyboardSubscription()
Expand Down Expand Up @@ -353,7 +360,9 @@ void OnKeyboardWillShow(NSNotification notification)
}
}

void OnKeyboardWillHide(NSNotification notification)
void OnKeyboardWillHide(NSNotification notification) => ClearKeyboardState();

void ClearKeyboardState()
{
_safeAreaInvalidated = true;
_keyboardFrame = CGRect.Empty;
Expand Down
Loading