Update with recovered code from VM binaries (Jan 1)
Recovered from decompiled OpenMaui.Controls.Linux.dll: - SkiaShell.cs: FlyoutHeader, FlyoutFooter, scroll support (918 -> 1325 lines) - X11Window.cs: Cursor support (XCreateFontCursor, XDefineCursor) - All handlers with dark mode support - All services with latest implementations - LinuxApplication with theme change handling
This commit is contained in:
@@ -1,374 +1,458 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using Microsoft.Maui.Handlers;
|
||||
using Microsoft.Maui.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Maui.Controls;
|
||||
using Microsoft.Maui.Platform;
|
||||
using SkiaSharp;
|
||||
using Microsoft.Maui.Handlers;
|
||||
using Microsoft.Maui.Platform.Linux.Hosting;
|
||||
|
||||
namespace Microsoft.Maui.Platform.Linux.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for CollectionView on Linux using Skia rendering.
|
||||
/// Maps CollectionView to SkiaCollectionView platform view.
|
||||
/// </summary>
|
||||
public partial class CollectionViewHandler : ViewHandler<CollectionView, SkiaCollectionView>
|
||||
public class CollectionViewHandler : ViewHandler<CollectionView, SkiaCollectionView>
|
||||
{
|
||||
private bool _isUpdatingSelection;
|
||||
private bool _isUpdatingSelection;
|
||||
|
||||
public static IPropertyMapper<CollectionView, CollectionViewHandler> Mapper =
|
||||
new PropertyMapper<CollectionView, CollectionViewHandler>(ViewHandler.ViewMapper)
|
||||
{
|
||||
// ItemsView properties
|
||||
[nameof(ItemsView.ItemsSource)] = MapItemsSource,
|
||||
[nameof(ItemsView.ItemTemplate)] = MapItemTemplate,
|
||||
[nameof(ItemsView.EmptyView)] = MapEmptyView,
|
||||
[nameof(ItemsView.HorizontalScrollBarVisibility)] = MapHorizontalScrollBarVisibility,
|
||||
[nameof(ItemsView.VerticalScrollBarVisibility)] = MapVerticalScrollBarVisibility,
|
||||
public static IPropertyMapper<CollectionView, CollectionViewHandler> Mapper = (IPropertyMapper<CollectionView, CollectionViewHandler>)(object)new PropertyMapper<CollectionView, CollectionViewHandler>((IPropertyMapper[])(object)new IPropertyMapper[1] { (IPropertyMapper)ViewHandler.ViewMapper })
|
||||
{
|
||||
["ItemsSource"] = MapItemsSource,
|
||||
["ItemTemplate"] = MapItemTemplate,
|
||||
["EmptyView"] = MapEmptyView,
|
||||
["HorizontalScrollBarVisibility"] = MapHorizontalScrollBarVisibility,
|
||||
["VerticalScrollBarVisibility"] = MapVerticalScrollBarVisibility,
|
||||
["SelectedItem"] = MapSelectedItem,
|
||||
["SelectedItems"] = MapSelectedItems,
|
||||
["SelectionMode"] = MapSelectionMode,
|
||||
["Header"] = MapHeader,
|
||||
["Footer"] = MapFooter,
|
||||
["ItemsLayout"] = MapItemsLayout,
|
||||
["Background"] = MapBackground,
|
||||
["BackgroundColor"] = MapBackgroundColor
|
||||
};
|
||||
|
||||
// SelectableItemsView properties
|
||||
[nameof(SelectableItemsView.SelectedItem)] = MapSelectedItem,
|
||||
[nameof(SelectableItemsView.SelectedItems)] = MapSelectedItems,
|
||||
[nameof(SelectableItemsView.SelectionMode)] = MapSelectionMode,
|
||||
public static CommandMapper<CollectionView, CollectionViewHandler> CommandMapper = new CommandMapper<CollectionView, CollectionViewHandler>((CommandMapper)(object)ViewHandler.ViewCommandMapper) { ["ScrollTo"] = MapScrollTo };
|
||||
|
||||
// StructuredItemsView properties
|
||||
[nameof(StructuredItemsView.Header)] = MapHeader,
|
||||
[nameof(StructuredItemsView.Footer)] = MapFooter,
|
||||
[nameof(StructuredItemsView.ItemsLayout)] = MapItemsLayout,
|
||||
public CollectionViewHandler()
|
||||
: base((IPropertyMapper)(object)Mapper, (CommandMapper)(object)CommandMapper)
|
||||
{
|
||||
}
|
||||
|
||||
[nameof(IView.Background)] = MapBackground,
|
||||
[nameof(CollectionView.BackgroundColor)] = MapBackgroundColor,
|
||||
};
|
||||
public CollectionViewHandler(IPropertyMapper? mapper, CommandMapper? commandMapper = null)
|
||||
: base((IPropertyMapper)(((object)mapper) ?? ((object)Mapper)), (CommandMapper)(((object)commandMapper) ?? ((object)CommandMapper)))
|
||||
{
|
||||
}
|
||||
|
||||
public static CommandMapper<CollectionView, CollectionViewHandler> CommandMapper =
|
||||
new(ViewHandler.ViewCommandMapper)
|
||||
{
|
||||
["ScrollTo"] = MapScrollTo,
|
||||
};
|
||||
protected override SkiaCollectionView CreatePlatformView()
|
||||
{
|
||||
return new SkiaCollectionView();
|
||||
}
|
||||
|
||||
public CollectionViewHandler() : base(Mapper, CommandMapper)
|
||||
{
|
||||
}
|
||||
protected override void ConnectHandler(SkiaCollectionView platformView)
|
||||
{
|
||||
base.ConnectHandler(platformView);
|
||||
platformView.SelectionChanged += OnSelectionChanged;
|
||||
platformView.Scrolled += OnScrolled;
|
||||
platformView.ItemTapped += OnItemTapped;
|
||||
}
|
||||
|
||||
public CollectionViewHandler(IPropertyMapper? mapper, CommandMapper? commandMapper = null)
|
||||
: base(mapper ?? Mapper, commandMapper ?? CommandMapper)
|
||||
{
|
||||
}
|
||||
protected override void DisconnectHandler(SkiaCollectionView platformView)
|
||||
{
|
||||
platformView.SelectionChanged -= OnSelectionChanged;
|
||||
platformView.Scrolled -= OnScrolled;
|
||||
platformView.ItemTapped -= OnItemTapped;
|
||||
base.DisconnectHandler(platformView);
|
||||
}
|
||||
|
||||
protected override SkiaCollectionView CreatePlatformView()
|
||||
{
|
||||
return new SkiaCollectionView();
|
||||
}
|
||||
private void OnSelectionChanged(object? sender, CollectionSelectionChangedEventArgs e)
|
||||
{
|
||||
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_0025: Invalid comparison between Unknown and I4
|
||||
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_0060: Invalid comparison between Unknown and I4
|
||||
if (base.VirtualView == null || _isUpdatingSelection)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_isUpdatingSelection = true;
|
||||
if ((int)((SelectableItemsView)base.VirtualView).SelectionMode == 1)
|
||||
{
|
||||
object obj = e.CurrentSelection.FirstOrDefault();
|
||||
if (!object.Equals(((SelectableItemsView)base.VirtualView).SelectedItem, obj))
|
||||
{
|
||||
((SelectableItemsView)base.VirtualView).SelectedItem = obj;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((int)((SelectableItemsView)base.VirtualView).SelectionMode != 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
((SelectableItemsView)base.VirtualView).SelectedItems.Clear();
|
||||
{
|
||||
foreach (object item in e.CurrentSelection)
|
||||
{
|
||||
((SelectableItemsView)base.VirtualView).SelectedItems.Add(item);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isUpdatingSelection = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ConnectHandler(SkiaCollectionView platformView)
|
||||
{
|
||||
base.ConnectHandler(platformView);
|
||||
platformView.SelectionChanged += OnSelectionChanged;
|
||||
platformView.Scrolled += OnScrolled;
|
||||
platformView.ItemTapped += OnItemTapped;
|
||||
}
|
||||
private void OnScrolled(object? sender, ItemsScrolledEventArgs e)
|
||||
{
|
||||
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_004f: Expected O, but got Unknown
|
||||
CollectionView virtualView = base.VirtualView;
|
||||
if (virtualView != null)
|
||||
{
|
||||
((ItemsView)virtualView).SendScrolled(new ItemsViewScrolledEventArgs
|
||||
{
|
||||
VerticalOffset = e.ScrollOffset,
|
||||
VerticalDelta = 0.0,
|
||||
HorizontalOffset = 0.0,
|
||||
HorizontalDelta = 0.0
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DisconnectHandler(SkiaCollectionView platformView)
|
||||
{
|
||||
platformView.SelectionChanged -= OnSelectionChanged;
|
||||
platformView.Scrolled -= OnScrolled;
|
||||
platformView.ItemTapped -= OnItemTapped;
|
||||
base.DisconnectHandler(platformView);
|
||||
}
|
||||
private void OnItemTapped(object? sender, ItemsViewItemTappedEventArgs e)
|
||||
{
|
||||
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_01d8: Invalid comparison between Unknown and I4
|
||||
//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_01f9: Invalid comparison between Unknown and I4
|
||||
if (base.VirtualView == null || _isUpdatingSelection)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_isUpdatingSelection = true;
|
||||
Console.WriteLine($"[CollectionViewHandler] OnItemTapped index={e.Index}, item={e.Item}, SelectionMode={((SelectableItemsView)base.VirtualView).SelectionMode}");
|
||||
SkiaView skiaView = base.PlatformView?.GetItemView(e.Index);
|
||||
Console.WriteLine($"[CollectionViewHandler] GetItemView({e.Index}) returned: {((object)skiaView)?.GetType().Name ?? "null"}, MauiView={((object)skiaView?.MauiView)?.GetType().Name ?? "null"}");
|
||||
if (skiaView?.MauiView != null)
|
||||
{
|
||||
Console.WriteLine($"[CollectionViewHandler] Found MauiView: {((object)skiaView.MauiView).GetType().Name}, GestureRecognizers={skiaView.MauiView.GestureRecognizers?.Count ?? 0}");
|
||||
if (GestureManager.ProcessTap(skiaView.MauiView, 0.0, 0.0))
|
||||
{
|
||||
Console.WriteLine("[CollectionViewHandler] Gesture processed successfully");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ((int)((SelectableItemsView)base.VirtualView).SelectionMode == 1)
|
||||
{
|
||||
((SelectableItemsView)base.VirtualView).SelectedItem = e.Item;
|
||||
}
|
||||
else if ((int)((SelectableItemsView)base.VirtualView).SelectionMode == 2)
|
||||
{
|
||||
if (((SelectableItemsView)base.VirtualView).SelectedItems.Contains(e.Item))
|
||||
{
|
||||
((SelectableItemsView)base.VirtualView).SelectedItems.Remove(e.Item);
|
||||
}
|
||||
else
|
||||
{
|
||||
((SelectableItemsView)base.VirtualView).SelectedItems.Add(e.Item);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isUpdatingSelection = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSelectionChanged(object? sender, CollectionSelectionChangedEventArgs e)
|
||||
{
|
||||
if (VirtualView is null || _isUpdatingSelection) return;
|
||||
public static void MapItemsSource(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView != null)
|
||||
{
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.ItemsSource = ((ItemsView)collectionView).ItemsSource;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_isUpdatingSelection = true;
|
||||
public static void MapItemTemplate(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView == null || ((ElementHandler)handler).MauiContext == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DataTemplate template = ((ItemsView)collectionView).ItemTemplate;
|
||||
if (template != null)
|
||||
{
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.ItemViewCreator = delegate(object item)
|
||||
{
|
||||
try
|
||||
{
|
||||
object obj = ((ElementTemplate)template).CreateContent();
|
||||
View val = (View)((obj is View) ? obj : null);
|
||||
if (val != null)
|
||||
{
|
||||
((BindableObject)val).BindingContext = item;
|
||||
PropagateBindingContext(val, item);
|
||||
if (((VisualElement)val).Handler == null && ((ElementHandler)handler).MauiContext != null)
|
||||
{
|
||||
((VisualElement)val).Handler = ((IView)(object)val).ToViewHandler(((ElementHandler)handler).MauiContext);
|
||||
}
|
||||
IViewHandler handler2 = ((VisualElement)val).Handler;
|
||||
if (((handler2 != null) ? ((IElementHandler)handler2).PlatformView : null) is SkiaView skiaView)
|
||||
{
|
||||
skiaView.MauiView = val;
|
||||
Console.WriteLine($"[CollectionViewHandler.ItemViewCreator] Set MauiView={((object)val).GetType().Name} on {((object)skiaView).GetType().Name}, GestureRecognizers={val.GestureRecognizers?.Count ?? 0}");
|
||||
return skiaView;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewCell val2 = (ViewCell)((obj is ViewCell) ? obj : null);
|
||||
if (val2 != null)
|
||||
{
|
||||
((BindableObject)val2).BindingContext = item;
|
||||
View view = val2.View;
|
||||
if (view != null)
|
||||
{
|
||||
if (((VisualElement)view).Handler == null && ((ElementHandler)handler).MauiContext != null)
|
||||
{
|
||||
((VisualElement)view).Handler = ((IView)(object)view).ToViewHandler(((ElementHandler)handler).MauiContext);
|
||||
}
|
||||
IViewHandler handler3 = ((VisualElement)view).Handler;
|
||||
if (((handler3 != null) ? ((IElementHandler)handler3).PlatformView : null) is SkiaView result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return (SkiaView?)null;
|
||||
};
|
||||
}
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.Invalidate();
|
||||
}
|
||||
|
||||
// Update virtual view selection
|
||||
if (VirtualView.SelectionMode == SelectionMode.Single)
|
||||
{
|
||||
var newItem = e.CurrentSelection.FirstOrDefault();
|
||||
if (!Equals(VirtualView.SelectedItem, newItem))
|
||||
{
|
||||
VirtualView.SelectedItem = newItem;
|
||||
}
|
||||
}
|
||||
else if (VirtualView.SelectionMode == SelectionMode.Multiple)
|
||||
{
|
||||
// Clear and update selected items
|
||||
VirtualView.SelectedItems.Clear();
|
||||
foreach (var item in e.CurrentSelection)
|
||||
{
|
||||
VirtualView.SelectedItems.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isUpdatingSelection = false;
|
||||
}
|
||||
}
|
||||
public static void MapEmptyView(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView != null)
|
||||
{
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.EmptyView = ((ItemsView)collectionView).EmptyView;
|
||||
if (((ItemsView)collectionView).EmptyView is string emptyViewText)
|
||||
{
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.EmptyViewText = emptyViewText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnScrolled(object? sender, ItemsScrolledEventArgs e)
|
||||
{
|
||||
VirtualView?.SendScrolled(new ItemsViewScrolledEventArgs
|
||||
{
|
||||
VerticalOffset = e.ScrollOffset,
|
||||
VerticalDelta = 0,
|
||||
HorizontalOffset = 0,
|
||||
HorizontalDelta = 0
|
||||
});
|
||||
}
|
||||
public static void MapHorizontalScrollBarVisibility(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_001a: Expected I4, but got Unknown
|
||||
if (((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView != null)
|
||||
{
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.HorizontalScrollBarVisibility = (ScrollBarVisibility)((ItemsView)collectionView).HorizontalScrollBarVisibility;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnItemTapped(object? sender, ItemsViewItemTappedEventArgs e)
|
||||
{
|
||||
// Item tap is handled through selection
|
||||
}
|
||||
public static void MapVerticalScrollBarVisibility(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_001a: Expected I4, but got Unknown
|
||||
if (((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView != null)
|
||||
{
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.VerticalScrollBarVisibility = (ScrollBarVisibility)((ItemsView)collectionView).VerticalScrollBarVisibility;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapItemsSource(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (handler.PlatformView is null) return;
|
||||
handler.PlatformView.ItemsSource = collectionView.ItemsSource;
|
||||
}
|
||||
public static void MapSelectedItem(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView == null || handler._isUpdatingSelection)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
handler._isUpdatingSelection = true;
|
||||
if (!object.Equals(((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.SelectedItem, ((SelectableItemsView)collectionView).SelectedItem))
|
||||
{
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.SelectedItem = ((SelectableItemsView)collectionView).SelectedItem;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
handler._isUpdatingSelection = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapItemTemplate(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (handler.PlatformView is null || handler.MauiContext is null) return;
|
||||
public static void MapSelectedItems(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView == null || handler._isUpdatingSelection)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
handler._isUpdatingSelection = true;
|
||||
IList<object> selectedItems = ((SelectableItemsView)collectionView).SelectedItems;
|
||||
if (selectedItems != null && selectedItems.Count > 0)
|
||||
{
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.SelectedItem = selectedItems.First();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
handler._isUpdatingSelection = false;
|
||||
}
|
||||
}
|
||||
|
||||
var template = collectionView.ItemTemplate;
|
||||
if (template != null)
|
||||
{
|
||||
// Set up a renderer that creates views from the DataTemplate
|
||||
handler.PlatformView.ItemViewCreator = (item) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
// Create view from template
|
||||
var content = template.CreateContent();
|
||||
if (content is View view)
|
||||
{
|
||||
// Set binding context FIRST so bindings evaluate
|
||||
view.BindingContext = item;
|
||||
public static void MapSelectionMode(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_0029: Expected I4, but got Unknown
|
||||
if (((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView != null)
|
||||
{
|
||||
SkiaCollectionView platformView = ((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView;
|
||||
SelectionMode selectionMode = ((SelectableItemsView)collectionView).SelectionMode;
|
||||
platformView.SelectionMode = (int)selectionMode switch
|
||||
{
|
||||
0 => SkiaSelectionMode.None,
|
||||
1 => SkiaSelectionMode.Single,
|
||||
2 => SkiaSelectionMode.Multiple,
|
||||
_ => SkiaSelectionMode.None,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Force binding evaluation by accessing the visual tree
|
||||
// This ensures child bindings are evaluated before handler creation
|
||||
PropagateBindingContext(view, item);
|
||||
public static void MapHeader(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView != null)
|
||||
{
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.Header = ((StructuredItemsView)collectionView).Header;
|
||||
}
|
||||
}
|
||||
|
||||
// Create handler for the view
|
||||
if (view.Handler == null && handler.MauiContext != null)
|
||||
{
|
||||
view.Handler = view.ToHandler(handler.MauiContext);
|
||||
}
|
||||
public static void MapFooter(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView != null)
|
||||
{
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.Footer = ((StructuredItemsView)collectionView).Footer;
|
||||
}
|
||||
}
|
||||
|
||||
if (view.Handler?.PlatformView is SkiaView skiaView)
|
||||
{
|
||||
return skiaView;
|
||||
}
|
||||
}
|
||||
else if (content is ViewCell cell)
|
||||
{
|
||||
cell.BindingContext = item;
|
||||
var cellView = cell.View;
|
||||
if (cellView != null)
|
||||
{
|
||||
if (cellView.Handler == null && handler.MauiContext != null)
|
||||
{
|
||||
cellView.Handler = cellView.ToHandler(handler.MauiContext);
|
||||
}
|
||||
public static void MapItemsLayout(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
|
||||
if (((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
IItemsLayout itemsLayout = ((StructuredItemsView)collectionView).ItemsLayout;
|
||||
LinearItemsLayout val = (LinearItemsLayout)(object)((itemsLayout is LinearItemsLayout) ? itemsLayout : null);
|
||||
if (val != null)
|
||||
{
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.Orientation = (((int)((ItemsLayout)val).Orientation != 0) ? ItemsLayoutOrientation.Horizontal : ItemsLayoutOrientation.Vertical);
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.SpanCount = 1;
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.ItemSpacing = (float)val.ItemSpacing;
|
||||
return;
|
||||
}
|
||||
GridItemsLayout val2 = (GridItemsLayout)(object)((itemsLayout is GridItemsLayout) ? itemsLayout : null);
|
||||
if (val2 != null)
|
||||
{
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.Orientation = (((int)((ItemsLayout)val2).Orientation != 0) ? ItemsLayoutOrientation.Horizontal : ItemsLayoutOrientation.Vertical);
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.SpanCount = val2.Span;
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.ItemSpacing = (float)val2.VerticalItemSpacing;
|
||||
}
|
||||
}
|
||||
|
||||
if (cellView.Handler?.PlatformView is SkiaView skiaView)
|
||||
{
|
||||
return skiaView;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore template creation errors
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
public static void MapBackground(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
|
||||
if (((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView != null && ((VisualElement)collectionView).BackgroundColor == null)
|
||||
{
|
||||
Brush background = ((VisualElement)collectionView).Background;
|
||||
SolidColorBrush val = (SolidColorBrush)(object)((background is SolidColorBrush) ? background : null);
|
||||
if (val != null)
|
||||
{
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.BackgroundColor = val.Color.ToSKColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handler.PlatformView.Invalidate();
|
||||
}
|
||||
public static void MapBackgroundColor(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
|
||||
if (((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView != null && ((VisualElement)collectionView).BackgroundColor != null)
|
||||
{
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.BackgroundColor = ((VisualElement)collectionView).BackgroundColor.ToSKColor();
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapEmptyView(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (handler.PlatformView is null) return;
|
||||
public static void MapScrollTo(CollectionViewHandler handler, CollectionView collectionView, object? args)
|
||||
{
|
||||
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
|
||||
//IL_001a: Invalid comparison between Unknown and I4
|
||||
if (((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ScrollToRequestEventArgs e = (ScrollToRequestEventArgs)((args is ScrollToRequestEventArgs) ? args : null);
|
||||
if (e != null)
|
||||
{
|
||||
if ((int)e.Mode == 1)
|
||||
{
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.ScrollToIndex(e.Index, e.IsAnimated);
|
||||
}
|
||||
else if (e.Item != null)
|
||||
{
|
||||
((ViewHandler<CollectionView, SkiaCollectionView>)(object)handler).PlatformView.ScrollToItem(e.Item, e.IsAnimated);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handler.PlatformView.EmptyView = collectionView.EmptyView;
|
||||
if (collectionView.EmptyView is string text)
|
||||
{
|
||||
handler.PlatformView.EmptyViewText = text;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapHorizontalScrollBarVisibility(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (handler.PlatformView is null) return;
|
||||
handler.PlatformView.HorizontalScrollBarVisibility = (ScrollBarVisibility)collectionView.HorizontalScrollBarVisibility;
|
||||
}
|
||||
|
||||
public static void MapVerticalScrollBarVisibility(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (handler.PlatformView is null) return;
|
||||
handler.PlatformView.VerticalScrollBarVisibility = (ScrollBarVisibility)collectionView.VerticalScrollBarVisibility;
|
||||
}
|
||||
|
||||
public static void MapSelectedItem(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (handler.PlatformView is null || handler._isUpdatingSelection) return;
|
||||
|
||||
try
|
||||
{
|
||||
handler._isUpdatingSelection = true;
|
||||
if (!Equals(handler.PlatformView.SelectedItem, collectionView.SelectedItem))
|
||||
{
|
||||
handler.PlatformView.SelectedItem = collectionView.SelectedItem;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
handler._isUpdatingSelection = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapSelectedItems(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (handler.PlatformView is null || handler._isUpdatingSelection) return;
|
||||
|
||||
try
|
||||
{
|
||||
handler._isUpdatingSelection = true;
|
||||
|
||||
// Sync selected items
|
||||
var selectedItems = collectionView.SelectedItems;
|
||||
if (selectedItems != null && selectedItems.Count > 0)
|
||||
{
|
||||
handler.PlatformView.SelectedItem = selectedItems.First();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
handler._isUpdatingSelection = false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapSelectionMode(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (handler.PlatformView is null) return;
|
||||
|
||||
handler.PlatformView.SelectionMode = collectionView.SelectionMode switch
|
||||
{
|
||||
SelectionMode.None => SkiaSelectionMode.None,
|
||||
SelectionMode.Single => SkiaSelectionMode.Single,
|
||||
SelectionMode.Multiple => SkiaSelectionMode.Multiple,
|
||||
_ => SkiaSelectionMode.None
|
||||
};
|
||||
}
|
||||
|
||||
public static void MapHeader(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (handler.PlatformView is null) return;
|
||||
handler.PlatformView.Header = collectionView.Header;
|
||||
}
|
||||
|
||||
public static void MapFooter(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (handler.PlatformView is null) return;
|
||||
handler.PlatformView.Footer = collectionView.Footer;
|
||||
}
|
||||
|
||||
public static void MapItemsLayout(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (handler.PlatformView is null) return;
|
||||
|
||||
var layout = collectionView.ItemsLayout;
|
||||
if (layout is LinearItemsLayout linearLayout)
|
||||
{
|
||||
handler.PlatformView.Orientation = linearLayout.Orientation == Controls.ItemsLayoutOrientation.Vertical
|
||||
? Platform.ItemsLayoutOrientation.Vertical
|
||||
: Platform.ItemsLayoutOrientation.Horizontal;
|
||||
handler.PlatformView.SpanCount = 1;
|
||||
handler.PlatformView.ItemSpacing = (float)linearLayout.ItemSpacing;
|
||||
}
|
||||
else if (layout is GridItemsLayout gridLayout)
|
||||
{
|
||||
handler.PlatformView.Orientation = gridLayout.Orientation == Controls.ItemsLayoutOrientation.Vertical
|
||||
? Platform.ItemsLayoutOrientation.Vertical
|
||||
: Platform.ItemsLayoutOrientation.Horizontal;
|
||||
handler.PlatformView.SpanCount = gridLayout.Span;
|
||||
handler.PlatformView.ItemSpacing = (float)gridLayout.VerticalItemSpacing;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapBackground(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (handler.PlatformView is null) return;
|
||||
|
||||
// Don't override if BackgroundColor is explicitly set
|
||||
if (collectionView.BackgroundColor is not null)
|
||||
return;
|
||||
|
||||
if (collectionView.Background is SolidColorBrush solidBrush)
|
||||
{
|
||||
handler.PlatformView.BackgroundColor = solidBrush.Color.ToSKColor();
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapBackgroundColor(CollectionViewHandler handler, CollectionView collectionView)
|
||||
{
|
||||
if (handler.PlatformView is null) return;
|
||||
|
||||
if (collectionView.BackgroundColor is not null)
|
||||
{
|
||||
handler.PlatformView.BackgroundColor = collectionView.BackgroundColor.ToSKColor();
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapScrollTo(CollectionViewHandler handler, CollectionView collectionView, object? args)
|
||||
{
|
||||
if (handler.PlatformView is null || args is not ScrollToRequestEventArgs scrollArgs)
|
||||
return;
|
||||
|
||||
if (scrollArgs.Mode == ScrollToMode.Position)
|
||||
{
|
||||
handler.PlatformView.ScrollToIndex(scrollArgs.Index, scrollArgs.IsAnimated);
|
||||
}
|
||||
else if (scrollArgs.Item != null)
|
||||
{
|
||||
handler.PlatformView.ScrollToItem(scrollArgs.Item, scrollArgs.IsAnimated);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recursively propagates binding context to all child views to force binding evaluation.
|
||||
/// </summary>
|
||||
private static void PropagateBindingContext(View view, object? bindingContext)
|
||||
{
|
||||
view.BindingContext = bindingContext;
|
||||
|
||||
// Propagate to children
|
||||
if (view is Layout layout)
|
||||
{
|
||||
foreach (var child in layout.Children)
|
||||
{
|
||||
if (child is View childView)
|
||||
{
|
||||
PropagateBindingContext(childView, bindingContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (view is ContentView contentView && contentView.Content != null)
|
||||
{
|
||||
PropagateBindingContext(contentView.Content, bindingContext);
|
||||
}
|
||||
else if (view is Border border && border.Content is View borderContent)
|
||||
{
|
||||
PropagateBindingContext(borderContent, bindingContext);
|
||||
}
|
||||
}
|
||||
private static void PropagateBindingContext(View view, object? bindingContext)
|
||||
{
|
||||
((BindableObject)view).BindingContext = bindingContext;
|
||||
Layout val = (Layout)(object)((view is Layout) ? view : null);
|
||||
if (val != null)
|
||||
{
|
||||
foreach (IView child in val.Children)
|
||||
{
|
||||
View val2 = (View)(object)((child is View) ? child : null);
|
||||
if (val2 != null)
|
||||
{
|
||||
PropagateBindingContext(val2, bindingContext);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
ContentView val3 = (ContentView)(object)((view is ContentView) ? view : null);
|
||||
if (val3 != null && val3.Content != null)
|
||||
{
|
||||
PropagateBindingContext(val3.Content, bindingContext);
|
||||
return;
|
||||
}
|
||||
Border val4 = (Border)(object)((view is Border) ? view : null);
|
||||
if (val4 != null)
|
||||
{
|
||||
View content = val4.Content;
|
||||
if (content != null)
|
||||
{
|
||||
PropagateBindingContext(content, bindingContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user