From 33222829a2f8c2cba867d72858acd77e7fb7a364 Mon Sep 17 00:00:00 2001 From: Axemasta <33064621+Axemasta@users.noreply.github.com> Date: Wed, 10 Apr 2024 11:29:41 +0100 Subject: [PATCH 1/9] Fix null reference when window is null When using certain controls ie bottom sheets and search bars there can be a crash when the keyboard displays. Check for null & return early if it is. --- src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs b/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs index eb91ef75040f..c4eca913b0cf 100644 --- a/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs +++ b/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs @@ -1,4 +1,4 @@ -/* +/* * This class is adapted from IQKeyboardManager which is an open-source * library implemented for iOS to handle Keyboard interactions with * UITextFields/UITextViews. Link to their MIT License can be found here: @@ -311,6 +311,11 @@ internal static void AdjustPosition() var rootViewOrigin = new CGPoint(ContainerView.Frame.GetMinX(), ContainerView.Frame.GetMinY()); var window = ContainerView.Window; + if (window is null) + { + return; + } + var intersectRect = CGRect.Intersect(KeyboardFrame, window.Frame); var kbSize = intersectRect == CGRect.Empty ? new CGSize(KeyboardFrame.Width, 0) : intersectRect.Size; From 33518148702f4fb24e6ded06547f6c3ce220e024 Mon Sep 17 00:00:00 2001 From: tj-devel709 Date: Thu, 18 Apr 2024 09:21:21 -0500 Subject: [PATCH 2/9] set flag to false if returning --- src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs b/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs index c4eca913b0cf..d2da64137f4d 100644 --- a/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs +++ b/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs @@ -313,6 +313,7 @@ internal static void AdjustPosition() if (window is null) { + IsKeyboardAutoScrollHandling = false; return; } @@ -412,7 +413,10 @@ internal static void AdjustPosition() } else if (cursorRect.Y >= topBoundary && cursorRect.Y < bottomBoundary) + { + IsKeyboardAutoScrollHandling = false; return; + } else if (cursorRect.Y > bottomBoundary) move = cursorRect.Y - (nfloat)bottomBoundary; From f1acf9f7068cad325e9042343e5bc886ccd08760 Mon Sep 17 00:00:00 2001 From: tj-devel709 Date: Thu, 18 Apr 2024 09:27:12 -0500 Subject: [PATCH 3/9] remove change on line 1 --- src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs b/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs index d2da64137f4d..312d2c66f6c4 100644 --- a/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs +++ b/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs @@ -1,4 +1,4 @@ -/* +/* * This class is adapted from IQKeyboardManager which is an open-source * library implemented for iOS to handle Keyboard interactions with * UITextFields/UITextViews. Link to their MIT License can be found here: From dd681083b4a568b7101dc670346b093fb98f51f2 Mon Sep 17 00:00:00 2001 From: tj-devel709 Date: Fri, 19 Apr 2024 10:28:24 -0500 Subject: [PATCH 4/9] Add IsDescendant of ContainerVC --- src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs b/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs index 312d2c66f6c4..d4d33507e614 100644 --- a/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs +++ b/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs @@ -299,7 +299,8 @@ internal static async Task AdjustPositionDebounce() internal static void AdjustPosition() { if (ContainerView is null - || (View is not UITextField && View is not UITextView)) + || (View is not UITextField && View is not UITextView) + || !View.IsDescendantOfView(ContainerView)) { IsKeyboardAutoScrollHandling = false; return; From d5066639a5e599a4aec73facc881400c7c4144e1 Mon Sep 17 00:00:00 2001 From: tj-devel709 Date: Fri, 19 Apr 2024 14:04:20 -0500 Subject: [PATCH 5/9] remove the extra IsKeyboardAutoScrollHandling flag --- src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs b/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs index d4d33507e614..96606e9548ee 100644 --- a/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs +++ b/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs @@ -415,7 +415,6 @@ internal static void AdjustPosition() else if (cursorRect.Y >= topBoundary && cursorRect.Y < bottomBoundary) { - IsKeyboardAutoScrollHandling = false; return; } From bc5b351ccb935b1bf9a55a6f98384bec66b3e6f0 Mon Sep 17 00:00:00 2001 From: tj-devel709 Date: Fri, 19 Apr 2024 14:11:13 -0500 Subject: [PATCH 6/9] remove extra style changes --- src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs b/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs index 96606e9548ee..729bd2cf66c8 100644 --- a/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs +++ b/src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs @@ -414,9 +414,7 @@ internal static void AdjustPosition() } else if (cursorRect.Y >= topBoundary && cursorRect.Y < bottomBoundary) - { return; - } else if (cursorRect.Y > bottomBoundary) move = cursorRect.Y - (nfloat)bottomBoundary; From 67e5f2cc7d7db5af068222962288810659cf7ede Mon Sep 17 00:00:00 2001 From: tj-devel709 Date: Thu, 25 Apr 2024 09:45:26 -0500 Subject: [PATCH 7/9] Add UITest --- .../Issues/Issue21726.xaml | 10 ++ .../Issues/Issue21726.xaml.cs | 103 ++++++++++++++++++ .../tests/UITests/Tests/Issues/Issue21726.cs | 37 +++++++ 3 files changed, 150 insertions(+) create mode 100644 src/Controls/samples/Controls.Sample.UITests/Issues/Issue21726.xaml create mode 100644 src/Controls/samples/Controls.Sample.UITests/Issues/Issue21726.xaml.cs create mode 100644 src/Controls/tests/UITests/Tests/Issues/Issue21726.cs diff --git a/src/Controls/samples/Controls.Sample.UITests/Issues/Issue21726.xaml b/src/Controls/samples/Controls.Sample.UITests/Issues/Issue21726.xaml new file mode 100644 index 000000000000..5c2a7f96439c --- /dev/null +++ b/src/Controls/samples/Controls.Sample.UITests/Issues/Issue21726.xaml @@ -0,0 +1,10 @@ + + + +