Skip to content

Commit

Permalink
feat: Share WASM ListView implementation with MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjohnoliver committed Mar 18, 2020
1 parent 812dd55 commit 1c3541b
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public int FirstCacheIndex
throw new global::System.NotImplementedException("The member int ItemsStackPanel.FirstCacheIndex is not implemented in Uno.");
}
}
#endif
#if false || false || NET461 || false || __MACOS__
#endif
#if false || false || NET461 || false || false
[global::Uno.NotImplemented]
public int FirstVisibleIndex
{
Expand All @@ -57,8 +57,8 @@ public int FirstVisibleIndex
throw new global::System.NotImplementedException("The member int ItemsStackPanel.FirstVisibleIndex is not implemented in Uno.");
}
}
#endif
#if false || __IOS__ || NET461 || __WASM__ || __MACOS__
#endif
#if false || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
public int LastCacheIndex
{
Expand All @@ -67,8 +67,8 @@ public int LastCacheIndex
throw new global::System.NotImplementedException("The member int ItemsStackPanel.LastCacheIndex is not implemented in Uno.");
}
}
#endif
#if false || false || NET461 || false || __MACOS__
#endif
#if false || false || NET461 || false || false
[global::Uno.NotImplemented]
public int LastVisibleIndex
{
Expand All @@ -77,8 +77,8 @@ public int LastVisibleIndex
throw new global::System.NotImplementedException("The member int ItemsStackPanel.LastVisibleIndex is not implemented in Uno.");
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __MACOS__
[global::Uno.NotImplemented]
public global::Windows.UI.Xaml.Controls.PanelScrollingDirection ScrollingDirection
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !XAMARIN_IOS && !XAMARIN_ANDROID && !__WASM__
#if !XAMARIN_IOS && !XAMARIN_ANDROID && !__WASM__ && !__MACOS__
#pragma warning disable 108 // new keyword hiding
#pragma warning disable 114 // new keyword hiding
namespace Windows.UI.Xaml.Controls
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !NET461 && !__MACOS__
#if !NET461
using System;
using System.Collections.Generic;
using System.Text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#if __WASM__ || __MACOS__
using System;
using System.Collections.Generic;
using System.Text;
using Uno.UI.DataBinding;
Expand All @@ -13,3 +14,4 @@ public partial class ItemsStackPanel
protected override Size ArrangeOverride(Size finalSize) => _layout.ArrangeOverride(finalSize);
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#if __WASM__ || __MACOS__
using System;
using System.Collections.Generic;
using System.Text;
using Uno.UI;
Expand All @@ -21,3 +22,4 @@ protected override Line CreateLine(GeneratorDirection fillDirection, double exte
protected override int GetItemsPerLine() => 1;
}
}
#endif
41 changes: 0 additions & 41 deletions src/Uno.UI/UI/Xaml/Controls/ListViewBase/ListViewBase.macOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,5 @@ namespace Windows.UI.Xaml.Controls
{
public partial class ListViewBase : Selector
{

private int PageSize => throw new NotImplementedException();

private protected override bool ShouldItemsControlManageChildren => !(ItemsPanelRoot is IVirtualizingPanel);

private void Refresh()
{
InvalidateMeasure();
}

private void AddItems(int firstItem, int count, int section)
{
Refresh();
}

private void RemoveItems(int firstItem, int count, int section)
{
Refresh();
}

private void AddGroup(int groupIndexInView)
{
Refresh();
}

private void RemoveGroup(int groupIndexInView)
{
Refresh();
}

private void ReplaceGroup(int groupIndexInView)
{
Refresh();
}

private ContentControl ContainerFromGroupIndex(int groupIndex) => throw new NotImplementedException();

private void TryLoadMoreItems()
{
//TODO: ISupportIncrementalLoading
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma warning disable 108 // new keyword hiding
#if __WASM__ || __MACOS__
#pragma warning disable 108 // new keyword hiding
#pragma warning disable 114 // new keyword hiding
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -58,3 +59,4 @@ private void TryLoadMoreItems()
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#if __WASM__ || __MACOS__
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
Expand Down Expand Up @@ -195,3 +196,4 @@ internal void ClearIdCache()
}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NET461 || __MACOS__
#if NET461
using System;
using System.Collections.Generic;
using System.Text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !NET461 && !__MACOS__
#if !NET461
using System;
using System.Collections.Generic;
using System.Text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#if __WASM__ || __MACOS__
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
Expand All @@ -10,6 +11,9 @@
using Windows.UI.Xaml.Controls.Primitives;
using static System.Math;
using static Windows.UI.Xaml.Controls.Primitives.GeneratorDirection;
#if __MACOS__
using AppKit;
#endif

namespace Windows.UI.Xaml.Controls
{
Expand Down Expand Up @@ -446,7 +450,11 @@ private double EstimatePanelExtent()
}

private double CalculatePanelMeasureBreadth() => ShouldMeasuredBreadthStretch ? AvailableBreadth :
_materializedLines.Select(l => GetDesiredBreadth(l.FirstView)).MaxOrDefault() + GetBreadth(XamlParent.ScrollViewer.ScrollBarSize);
_materializedLines.Select(l => GetDesiredBreadth(l.FirstView)).MaxOrDefault()
#if __WASM__
+ GetBreadth(XamlParent.ScrollViewer.ScrollBarSize)
#endif
;

private double CalculatePanelArrangeBreadth() => ShouldMeasuredBreadthStretch ? AvailableBreadth :
_materializedLines.Select(l => GetActualBreadth(l.FirstView)).MaxOrDefault();
Expand Down Expand Up @@ -647,15 +655,15 @@ protected void AddView(FrameworkElement view, GeneratorDirection fillDirection,

private double GetStart(FrameworkElement child)
{
var offset = child.RelativePosition;
var offset = GetRelativePosition(child);
return ScrollOrientation == Orientation.Vertical ?
offset.Y - child.Margin.Top :
offset.X - child.Margin.Left;
}

private double GetEnd(FrameworkElement child)
{
var offset = child.RelativePosition;
var offset = GetRelativePosition(child);
return ScrollOrientation == Orientation.Vertical ?
offset.Y + child.ActualHeight + child.Margin.Bottom :
offset.X + child.ActualWidth + child.Margin.Right;
Expand Down Expand Up @@ -692,6 +700,12 @@ private string GetDebugInfo()
return $"Parent ItemsControl={ItemsControl} ItemsSource={ItemsControl?.ItemsSource} NoOfItems={ItemsControl?.NumberOfItems} FirstMaterialized={GetFirstMaterializedIndexPath()} LastMaterialized={GetLastMaterializedIndexPath()} ExtendedViewportStart={ExtendedViewportStart} ExtendedViewportEnd={ExtendedViewportEnd} GetItemsStart()={GetItemsStart()} GetItemsEnd()={GetItemsEnd()}";
}

#if __WASM__
private static Point GetRelativePosition(FrameworkElement child) => child.RelativePosition;
#elif __MACOS__
private static Point GetRelativePosition(FrameworkElement child) => child.Frame.Location;
#endif

/// <summary>
/// Represents a single row in a vertically-scrolling panel, or a column in a horizontally-scrolling panel.
/// </summary>
Expand Down Expand Up @@ -721,3 +735,4 @@ public Line(FrameworkElement[] containerViews, IndexPath firstItem, IndexPath la
}
}
}
#endif
15 changes: 13 additions & 2 deletions src/Uno.UI/UI/Xaml/FrameworkElement.macOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,21 @@ public override bool NeedsLayout
RequiresMeasure = true;
RequiresArrange = true;

if (ShouldInterceptInvalidate)
{
return;
}

SetSuperviewNeedsLayout();
}
}

/// <summary>
/// When set, measure and invalidate requests will not be propagated further up the visual tree, ie they won't trigger a relayout.
/// Used where repeated unnecessary measure/arrange passes would be unacceptable for performance (eg scrolling in a list).
/// </summary>
internal bool ShouldInterceptInvalidate { get; set; }

public FrameworkElement()
{
Initialize();
Expand Down Expand Up @@ -67,7 +78,7 @@ public override void Layout()
RequiresArrange = false;
}
}
catch(Exception e)
catch (Exception e)
{
this.Log().Error($"Layout failed in {GetType()}", e);
}
Expand Down Expand Up @@ -125,7 +136,7 @@ public CGSize SizeThatFits(CGSize size)

var xamlMeasure = XamlMeasure(size);

if(xamlMeasure != null)
if (xamlMeasure != null)
{
return _lastMeasure = xamlMeasure.Value;
}
Expand Down

0 comments on commit 1c3541b

Please sign in to comment.