Skip to content

Commit

Permalink
Fix TableView (dotnet#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
myroot committed Aug 25, 2022
1 parent 973d6ec commit 54c98c3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static View CreateContent(TextCell textcell)
detail.SetBinding(Label.TextProperty, new Binding("Detail", source: textcell));
detail.SetBinding(Label.TextColorProperty, new Binding("DetailColor", source: textcell));
#pragma warning disable CS0612 // Type or member is obsolete
detail.FontSize = Device.GetNamedSize(NamedSize.Default, typeof(Label)) / 2;
detail.FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label));
#pragma warning restore CS0612 // Type or member is obsolete
detail.Margin = new Thickness(10, 0, 0, 0);

Expand Down Expand Up @@ -162,7 +162,7 @@ static View CreateContent(EntryCell entryCell)
label.SetBinding(Label.TextProperty, new Binding("Label", source: entryCell));
label.SetBinding(Label.TextColorProperty, new Binding("LabelColor", source: entryCell));
#pragma warning disable CS0612 // Type or member is obsolete
label.FontSize = Device.GetNamedSize(NamedSize.Default, typeof(Label)) / 2;
label.FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label));
#pragma warning restore CS0612 // Type or member is obsolete
label.Margin = new Thickness(20, 0, 0, 0);
var layout = new Controls.StackLayout
Expand Down Expand Up @@ -277,6 +277,7 @@ public CellContentView(BindableObject target, BindableObject container = null, b
void SetupVisualState()
{
VisualStateGroup stateGroup = new VisualStateGroup();

var selected = new VisualState
{
Name = VisualStateManager.CommonStates.Selected,
Expand Down Expand Up @@ -318,22 +319,9 @@ void SetupVisualState()
}
};

var unfocused = new VisualState
{
Name = VisualStateManager.CommonStates.Normal,
TargetType = typeof(View),
Setters =
{
new Setter
{
Property = View.BackgroundColorProperty,
Value = Colors.Transparent
}
}
};
stateGroup.States.Add(normal);
stateGroup.States.Add(focused);
stateGroup.States.Add(selected);
stateGroup.States.Add(unfocused);
VisualStateManager.GetVisualStateGroups(this).Add(stateGroup);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public override TSize MeasureItem(int index, double widthConstraint, double heig

if (_dataBindedViewTable.TryGetValue(this[index], out View createdView) && createdView != null)
{
return createdView.Measure(widthConstraint, heightConstraint, MeasureFlags.IncludeMargins).Request.ToPixel();
return (createdView as IView).Measure(widthConstraint, heightConstraint).ToPixel();
}

View view = null;
Expand All @@ -221,8 +221,7 @@ public override TSize MeasureItem(int index, double widthConstraint, double heig
view.Parent = Element;
if (Count > index)
view.BindingContext = this[index];
var request = view.Measure(widthConstraint, heightConstraint, MeasureFlags.IncludeMargins).Request;
return request.ToPixel();
return (view as IView).Measure(widthConstraint, heightConstraint).ToPixel();
}
}

Expand Down
20 changes: 20 additions & 0 deletions src/Compatibility/Core/src/Tizen/Renderers/TableViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using Microsoft.Maui.Controls.Platform;
using Tizen.UIExtensions.NUI;
using Size = Microsoft.Maui.Graphics.Size;
using TCollectionView = Tizen.UIExtensions.NUI.CollectionView;
using TItemSizingStrategy = Tizen.UIExtensions.NUI.ItemSizingStrategy;

Expand Down Expand Up @@ -36,6 +37,25 @@ protected override void OnElementChanged(ElementChangedEventArgs<TableView> e)
ApplyTableRoot();
}

protected override Size Measure(double availableWidth, double availableHeight)
{
if (Control.Adaptor == null || Control.LayoutManager == null || Control.LayoutManager.GetScrollCanvasSize().Height == 0 || Control.LayoutManager.GetScrollCanvasSize().Width == 0)
{
var scaled = Devices.DeviceDisplay.MainDisplayInfo.GetScaledScreenSize();
var size = new Size(availableWidth, availableHeight);
if (size.Width == double.PositiveInfinity)
size.Width = scaled.Width;
if (size.Height == double.PositiveInfinity)
size.Height = scaled.Height;
return size;
}

var canvasSize = Control.LayoutManager.GetScrollCanvasSize();
canvasSize.Width = Math.Min(canvasSize.Width, availableWidth.ToScaledPixel());
canvasSize.Height = Math.Min(canvasSize.Height, availableHeight.ToScaledPixel());
return canvasSize.ToDP();
}

protected override void Dispose(bool disposing)
{
if (disposing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public SizeRequest GetDesiredSize(double widthConstraint, double heightConstrain
}
else
{
measured = Measure(availableWidth, availableHeight);
measured = Measure(widthConstraint, heightConstraint);
}

return new SizeRequest(measured, MinimumSize());
Expand Down Expand Up @@ -560,7 +560,7 @@ protected virtual Size MinimumSize()
/// Calculates how much space this element should take, given how much room there is.
/// </summary>
/// <returns>a desired dimensions of the element</returns>
protected virtual Size Measure(int availableWidth, int availableHeight)
protected virtual Size Measure(double availableWidth, double availableHeight)
{
return MinimumSize();
}
Expand Down

0 comments on commit 54c98c3

Please sign in to comment.