I Am making a grid that sends its touch events down to its children(So I can have different scrollviews attached all scrolling together)
I made this custom renderer for android
public class ScrollableGridRenderer : ViewRenderer
{
ScrollableGrid? _control;
bool _elementChanged;
readonly IList<Android.Views.View> _children;
public ScrollableGridRenderer(Context context) : base(context)
{
_children = new List<Android.Views.View>();
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.View> e)
{
base.OnElementChanged(e);
if (e.NewElement is ScrollableGrid element)
{
_control = element;
_elementChanged = true;
}
}
public override bool OnInterceptTouchEvent(MotionEvent ev)
{
if (_control == null) return false;
if (!_elementChanged) return true;
_children.Clear();
for (int i = 0; i < _control.Children.Count; i++)
{
Android.Views.View? child = GetChildAt(i);
if (child != null) _children.Add(child);
}
_elementChanged = false;
return true;
public override bool OnTouchEvent(MotionEvent? ev)
{
if (_control == null) return true;
foreach (Android.Views.View child in _children)
{
child.DispatchTouchEvent(ev);
}
return true;
}
}
As you can see all I do is list the children of the grid and then just send forward the touch events(I haven't tried including buttons or any gesture recongnizers but I am aware of how they might screw this up and am not including them, my tests show that for static data it work's great! Other then if the scrollview orientation is set to horizontal it's not working, but that's beside the point)
My Question is how to do the same with iOS?
Thanks!
Edit :
Here is an example of code I might use the Scrollable grid in
<controls:ScrollableGrid Grid.Row="4"
x:Name="dataGrid"
ColumnDefinitions="108,*"
RowDefinitions="48,*"
Margin="6">
<Label Text="Not Moving"/>
<controls:ScrollViewRTLFix Grid.Column="1"
Orientation="Both" <!--Its horizontal but its marked as both because for some reason the touch isn't transferred here-->
x:Name="titleScroll">
<StackLayout Orientation="Horizontal"
Spacing="6">
<Label Text="Header"/>
<Label Text="Header"/>
<Label Text="Header"/>
</StackLayout>
</controls:ScrollViewRTLFix>
<controls:ScrollViewRTLFix Grid.Row="1"
Margin="4,0"
Orientation="Vertical"
x:Name="dayScroll">
<StackLayout x:Name="dayList"/> <!-- dataTable and dayList are updated dinamically in the code behind which is why they are empty here -->
</controls:ScrollViewRTLFix>
<controls:ScrollViewRTLFix Orientation="Both"
Grid.Row="1" Grid.Column="1"
x:Name="dataScroll">
<Grid ColumnDefinitions="108,108,108"
x:Name="dataTable"/> <!-- dataTable and dayList are updated dinamically in the code behind which is why they are empty here -->
</controls:ScrollViewRTLFix>
</controls:ScrollableGrid>