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
+ }
0 commit comments