Skip to content

Commit 104f814

Browse files
author
Copilot CI
committed
Compare keyboard overlap at pixel boundaries
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: de9c7c01-82c4-42fd-9ab7-882279aadd15
1 parent 542e0e9 commit 104f814

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

src/Controls/tests/DeviceTests/Elements/View/ViewTests.iOS.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,21 @@ await parentPlatformView.AttachAndRun(() =>
644644
childPlatformView.LayoutSubviews();
645645

646646
Assert.Equal(0, parentPlatformView.SafeAreaInsetsReadCount);
647+
648+
var subPixelStep = 0.4 / (double)parentPlatformView.Window!.Screen.Scale;
649+
childPlatformView.Transform = CGAffineTransform.MakeTranslation(0, (nfloat)subPixelStep);
650+
childPlatformView.LayoutSubviews();
651+
652+
Assert.Equal(0, parentPlatformView.SafeAreaInsetsReadCount);
653+
654+
childPlatformView.Transform = CGAffineTransform.MakeTranslation(0, (nfloat)(subPixelStep * 2));
655+
childPlatformView.LayoutSubviews();
656+
657+
Assert.True(parentPlatformView.SafeAreaInsetsReadCount > 0);
647658
}
648659
finally
649660
{
661+
childPlatformView.Transform = CGAffineTransform.MakeIdentity();
650662
NSNotificationCenter.DefaultCenter.PostNotificationName(
651663
UIKeyboard.WillHideNotification,
652664
null);

src/Core/src/Platform/iOS/MauiView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ bool HasSoftInputBottomOverlapChanged()
414414
return previousOverlap.HasValue != overlap.HasValue;
415415

416416
var displayScale = (double)(Window?.Screen.Scale ?? UIScreen.MainScreen.Scale);
417-
return !SafeAreaPadding.IsZeroAtPixelLevel(overlap.Value - previousOverlap.Value, displayScale);
417+
return !SafeAreaPadding.AreEqualAtPixelLevel(previousOverlap.Value, overlap.Value, displayScale);
418418
}
419419

420420
SafeAreaPadding GetAdjustedSafeAreaInsets() => GetAdjustedSafeAreaInsets(out _);

src/Core/src/Platform/iOS/SafeAreaPadding.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@ public CGRect ToCGRect() =>
3737
public bool EqualsAtPixelLevel(SafeAreaPadding other)
3838
{
3939
var scale = (double)UIScreen.MainScreen.Scale;
40-
return RoundToPixel(Left, scale) == RoundToPixel(other.Left, scale)
41-
&& RoundToPixel(Right, scale) == RoundToPixel(other.Right, scale)
42-
&& RoundToPixel(Top, scale) == RoundToPixel(other.Top, scale)
43-
&& RoundToPixel(Bottom, scale) == RoundToPixel(other.Bottom, scale);
40+
return AreEqualAtPixelLevel(Left, other.Left, scale)
41+
&& AreEqualAtPixelLevel(Right, other.Right, scale)
42+
&& AreEqualAtPixelLevel(Top, other.Top, scale)
43+
&& AreEqualAtPixelLevel(Bottom, other.Bottom, scale);
4444
}
4545

46+
public static bool AreEqualAtPixelLevel(double first, double second, double scale)
47+
=> RoundToPixel(first, scale) == RoundToPixel(second, scale);
48+
4649
public static bool IsZeroAtPixelLevel(double value, double scale)
47-
=> RoundToPixel(value, scale) == 0;
50+
=> AreEqualAtPixelLevel(value, 0, scale);
4851

4952
static double RoundToPixel(double value, double scale)
5053
=> Math.Round(value * scale, MidpointRounding.AwayFromZero);

0 commit comments

Comments
 (0)