Skip to content

Commit 4a9ee41

Browse files
tj-devel709rmarinho
authored andcommitted
Fix Crashing issue with keyboard scrolling iOS (#28148)
* check the window * check each responders window * check LastScrollView Window
1 parent 52b0557 commit 4a9ee41

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ static void WillHideKeyboard(NSNotification notification)
184184
{
185185
notification.UserInfo?.SetAnimationDuration();
186186

187-
if (LastScrollView is not null)
187+
if (LastScrollView?.Window is not null)
188188
{
189189
UIView.Animate(AnimationDuration, 0, UIViewAnimationOptions.CurveEaseOut, AnimateHidingKeyboard, () => { });
190190
}

src/Core/src/Platform/iOS/ViewExtensions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,13 @@ internal static void UpdateLayerBorder(this CoreAnimation.CALayer layer, IButton
821821
var nextResponder = view as UIResponder;
822822
while (nextResponder is not null)
823823
{
824+
// We check for Window to avoid scenarios where an invalidate might propagate up the tree
825+
// To a SuperView that's been disposed which will cause a crash when trying to access it
826+
if (nextResponder is UIView uiview && uiview.Window is null)
827+
{
828+
return null;
829+
}
830+
824831
nextResponder = nextResponder.NextResponder;
825832

826833
if (nextResponder is T responder)
@@ -834,6 +841,13 @@ internal static void UpdateLayerBorder(this CoreAnimation.CALayer layer, IButton
834841
var nextResponder = controller.View as UIResponder;
835842
while (nextResponder is not null)
836843
{
844+
// We check for Window to avoid scenarios where an invalidate might propagate up the tree
845+
// To a SuperView that's been disposed which will cause a crash when trying to access it
846+
if (nextResponder is UIView uiview && uiview.Window is null)
847+
{
848+
return null;
849+
}
850+
837851
nextResponder = nextResponder.NextResponder;
838852

839853
if (nextResponder is T responder && responder != controller)

0 commit comments

Comments
 (0)