Skip to content

Commit 7cb6532

Browse files
Merge pull request #46 from naveenkumar-sanjeevirayan/BottomSheetChanges
Implementation of the SfBottomSheet Control in MAUI Toolkit
2 parents d9c24df + 6e8de01 commit 7cb6532

File tree

10 files changed

+2906
-4
lines changed

10 files changed

+2906
-4
lines changed

maui/src/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Runtime.CompilerServices;
22

33
[assembly: InternalsVisibleTo("Syncfusion.Maui.Toolkit.UnitTest")]
4+
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.BottomSheet")]
45
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.Calendar")]
56
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.Carousel")]
67
[assembly: XmlnsDefinition("http://schemas.syncfusion.com/maui/toolkit", "Syncfusion.Maui.Toolkit.Charts")]
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
using Syncfusion.Maui.Toolkit.Helper;
2+
using Syncfusion.Maui.Toolkit.Internals;
3+
4+
namespace Syncfusion.Maui.Toolkit.BottomSheet
5+
{
6+
/// <summary>
7+
/// Represents the <see cref="BottomSheetBorder"/> that defines the layout of bottom sheet.
8+
/// </summary>
9+
internal class BottomSheetBorder : SfBorder, ITouchListener
10+
{
11+
#region Fields
12+
13+
// To store the weak reference of bottom sheet instance.
14+
readonly WeakReference<SfBottomSheet>? _bottomSheetRef;
15+
16+
#if IOS
17+
18+
// To store the child count of bottom sheet
19+
double _childLoopCount;
20+
21+
#endif
22+
23+
#endregion
24+
25+
#region Constructor
26+
27+
/// <summary>
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)
33+
{
34+
if (bottomSheet is not null)
35+
{
36+
_bottomSheetRef = new WeakReference<SfBottomSheet>(bottomSheet);
37+
this.AddTouchListener(this);
38+
}
39+
}
40+
41+
#endregion
42+
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+
109+
#region Interface Implementation
110+
111+
/// <summary>
112+
/// Method to invoke swiping in bottom sheet.
113+
/// </summary>
114+
/// <param name="e">e.</param>
115+
public void OnTouch(Toolkit.Internals.PointerEventArgs e)
116+
{
117+
#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
132+
if (e is not null && _bottomSheetRef is not null)
133+
{
134+
if (_bottomSheetRef.TryGetTarget(out var bottomSheet))
135+
{
136+
bottomSheet.OnHandleTouch(e.Action, e.TouchPoint);
137+
}
138+
}
139+
140+
#endif
141+
}
142+
143+
#endregion
144+
145+
}
146+
}

maui/src/BottomSheet/Enum.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
namespace Syncfusion.Maui.Toolkit.BottomSheet
2+
{
3+
/// <summary>
4+
/// Specifies the current display state of the SfBottomSheet control.
5+
/// </summary>
6+
/// <remarks>
7+
/// This enum is used to represent the various possible states of the bottom sheet,
8+
/// allowing for precise control and state management of the UI component.
9+
/// </remarks>
10+
public enum BottomSheetState
11+
{
12+
/// <summary>
13+
/// Indicates that the bottom sheet is fully expanded to cover the entire screen.
14+
/// </summary>
15+
FullExpanded,
16+
17+
/// <summary>
18+
/// Represents the state where the bottom sheet is expanded to cover approximately half of the screen.
19+
/// </summary>
20+
HalfExpanded,
21+
22+
/// <summary>
23+
/// Denotes that the bottom sheet is in its minimized or collapsed state, typically showing only a small portion or header.
24+
/// </summary>
25+
Collapsed,
26+
27+
/// <summary>
28+
/// Signifies that the bottom sheet is completely hidden from view.
29+
/// </summary>
30+
Hidden
31+
}
32+
33+
/// <summary>
34+
/// Defines the allowable states for the SfBottomSheet control.
35+
/// </summary>
36+
/// <remarks>
37+
/// This enum is used to configure the permitted states of the bottom sheet,
38+
/// enabling developers to restrict or allow specific display modes.
39+
/// </remarks>
40+
public enum BottomSheetAllowedState
41+
{
42+
/// <summary>
43+
/// Configures the bottom sheet to only allow full screen expansion.
44+
/// When set, the bottom sheet can only be fully expanded or hidden.
45+
/// </summary>
46+
FullExpanded,
47+
48+
/// <summary>
49+
/// Restricts the bottom sheet to only permit half screen expansion.
50+
/// When set, the bottom sheet can only be half expanded or hidden.
51+
/// </summary>
52+
HalfExpanded,
53+
54+
/// <summary>
55+
/// Allows the bottom sheet to be displayed in both full screen and half screen modes.
56+
/// This option provides the most flexibility, permitting all possible states.
57+
/// </summary>
58+
All
59+
}
60+
61+
/// <summary>
62+
/// Defines the content width mode for the SfBottomSheet control.
63+
/// </summary>
64+
public enum BottomSheetContentWidthMode
65+
{
66+
/// <summary>
67+
/// The BottomSheet will span the full width of the parent container.
68+
/// </summary>
69+
Full,
70+
71+
/// <summary>
72+
/// The BottomSheet will use a custom width value, centered if not full width.
73+
/// </summary>
74+
Custom
75+
}
76+
}

0 commit comments

Comments
 (0)