Skip to content

Commit 8ad27e2

Browse files
Moved scroll fix changes in the iOS platform for bottom sheet
1 parent b8b6f4c commit 8ad27e2

File tree

1 file changed

+96
-6
lines changed

1 file changed

+96
-6
lines changed

maui/src/BottomSheet/BottomSheetBorder.cs

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,23 @@ internal class BottomSheetBorder : SfBorder, ITouchListener
1313
// To store the weak reference of bottom sheet instance.
1414
readonly WeakReference<SfBottomSheet>? _bottomSheetRef;
1515

16-
#endregion
16+
#if IOS
17+
18+
// To store the child count of bottom sheet
19+
double _childLoopCount;
20+
21+
#endif
22+
23+
#endregion
1724

1825
#region Constructor
1926

2027
/// <summary>
21-
/// Initializes a new instance of the <see cref="BottomSheetBorder"/> class.
22-
/// </summary>
23-
/// <param name="bottomSheet">The SfBottomSheet instance.</param>
24-
/// <exception cref="ArgumentNullException">Thrown if bottomSheet is null.</exception>
25-
public BottomSheetBorder(SfBottomSheet bottomSheet)
28+
/// Initializes a new instance of the <see cref="BottomSheetBorder"/> class.
29+
/// </summary>
30+
/// <param name="bottomSheet">The SfBottomSheet instance.</param>
31+
/// <exception cref="ArgumentNullException">Thrown if bottomSheet is null.</exception>
32+
public BottomSheetBorder(SfBottomSheet bottomSheet)
2633
{
2734
if (bottomSheet is not null)
2835
{
@@ -33,6 +40,72 @@ public BottomSheetBorder(SfBottomSheet bottomSheet)
3340

3441
#endregion
3542

43+
#region Private Methods
44+
45+
#if IOS
46+
/// <summary>
47+
/// Gets the X and Y coordinates of the specified element based on the screen.
48+
/// </summary>
49+
/// <param name="element">The current element for which coordinates are requested.</param>
50+
/// <param name="touchPoint">The current element for which coordinates are requested.</param>
51+
bool IsChildElementScrolled(IVisualTreeElement? element, Point touchPoint)
52+
{
53+
if (element is null)
54+
{
55+
return false;
56+
}
57+
58+
var view = element as View;
59+
if (view is null || view.Handler is null || view.Handler.PlatformView is null)
60+
{
61+
return false;
62+
}
63+
64+
if (view is ScrollView || view is ListView || view is CollectionView)
65+
{
66+
return true;
67+
}
68+
69+
foreach (var childView in element.GetVisualChildren().OfType<View>())
70+
{
71+
if (childView is null || childView.Handler is null || childView.Handler.PlatformView is null)
72+
{
73+
return false;
74+
}
75+
76+
var childNativeView = childView.Handler.PlatformView;
77+
78+
// Here items X and Y position converts based on screen.
79+
Point locationOnScreen = ChildLocationToScreen(childNativeView);
80+
var bottom = locationOnScreen.Y + childView.Bounds.Height;
81+
var right = locationOnScreen.X + childView.Bounds.Width;
82+
83+
// We loop through child only 10 times.
84+
if (touchPoint.Y >= locationOnScreen.Y && touchPoint.Y <= bottom && touchPoint.X >= locationOnScreen.X && touchPoint.X <= right && _childLoopCount <= 10)
85+
{
86+
_childLoopCount++;
87+
return IsChildElementScrolled(childView, touchPoint);
88+
}
89+
}
90+
91+
_childLoopCount = 0;
92+
return false;
93+
}
94+
95+
Point ChildLocationToScreen(object child)
96+
{
97+
if (child is UIKit.UIView view && this.Handler is not null)
98+
{
99+
var point = view.ConvertPointToView(view.Bounds.Location, Handler.PlatformView as UIKit.UIView);
100+
return new Microsoft.Maui.Graphics.Point(point.X, point.Y);
101+
}
102+
103+
return new Microsoft.Maui.Graphics.Point(0, 0);
104+
}
105+
#endif
106+
107+
#endregion
108+
36109
#region Interface Implementation
37110

38111
/// <summary>
@@ -42,15 +115,32 @@ public BottomSheetBorder(SfBottomSheet bottomSheet)
42115
public void OnTouch(Toolkit.Internals.PointerEventArgs e)
43116
{
44117
#if IOS || MACCATALYST || ANDROID
118+
119+
#if IOS
120+
if (Content is null)
121+
{
122+
return;
123+
}
124+
125+
var firstDescendant = Content.GetVisualTreeDescendants().FirstOrDefault();
126+
if (firstDescendant is not null && IsChildElementScrolled(firstDescendant, e.TouchPoint))
127+
{
128+
return;
129+
}
130+
131+
#endif
45132
if (e is not null && _bottomSheetRef is not null)
46133
{
47134
if (_bottomSheetRef.TryGetTarget(out var bottomSheet))
48135
{
49136
bottomSheet.OnHandleTouch(e.Action, e.TouchPoint);
50137
}
51138
}
139+
52140
#endif
53141
}
142+
54143
#endregion
144+
55145
}
56146
}

0 commit comments

Comments
 (0)