Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch '3.0.0' into 3.1.0
  • Loading branch information
StephaneDelcroix committed May 7, 2018
2 parents a9eb61c + 9e54d6d commit 713ed70
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
1 change: 1 addition & 0 deletions .nuspec/Xamarin.Forms.targets
Expand Up @@ -6,6 +6,7 @@
<UsingTask TaskName="Xamarin.Forms.Build.Tasks.GetTasksAbi" AssemblyFile="$(MSBuildThisFileDirectory)Xamarin.Forms.Build.Tasks.dll" />

<PropertyGroup>
<SynthesizeLinkMetadata>true</SynthesizeLinkMetadata>
<EnableDefaultXamlItems Condition="'$(EnableDefaultXamlItems)'==''">True</EnableDefaultXamlItems>
<_DefaultXamlItemsEnabled>False</_DefaultXamlItemsEnabled>
<EnableDefaultCssItems Condition="'$(EnableDefaultCssItems)'==''">True</EnableDefaultCssItems>
Expand Down
8 changes: 6 additions & 2 deletions Xamarin.Flex/Flex.cs
Expand Up @@ -262,7 +262,7 @@ class Item : IEnumerable<Item>

/// <summary>This property defines the bottom edge absolute position of the item. It also defines the item's height if <see cref="P:Xamarin.Flex.Item.Top" /> is also set and if <see cref="P:Xamarin.Flex.Item.Height" /> isn't set. It is ignored if <see cref="P:Xamarin.Flex.Item.Position" /> isn't set to Absolute.</summary>
/// <value>The value for the property.</value>
/// <remarks>The default value for this property is NaN.</remarks>
/// <remarks>The default value for this property is NaN.</remarks>
public float Bottom { get; set; } = float.NaN;

/// <summary>This property defines the direction and main-axis of child items. If set to Column (or ColumnReverse), the main-axis will be the y-axis and items will be stacked vertically. If set to Row (or RowReverse), the main-axis will be the x-axis and items will be stacked horizontally.</summary>
Expand All @@ -280,6 +280,8 @@ class Item : IEnumerable<Item>
/// <remarks>The default value for this property is NaN.</remarks>
public float Height { get; set; } = float.NaN;

public bool IsVisible { get; set; } = true;

/// <summary>This property defines how the layout engine will distribute space between and around child items along the main-axis.</summary>
/// <value>Any value part of the<see cref="T:Xamarin.Flex.Align" /> enumeration, with the exception of Stretch and Auto.</value>
/// <remarks>The default value for this property is Start.</remarks>
Expand Down Expand Up @@ -472,6 +474,8 @@ static void layout_item(Item item, float width, float height)
int relative_children_count = 0;
for (int i = 0; i < item.Count; i++) {
var child = layout.child_at(item, i);
if (!child.IsVisible) continue;

// Items with an absolute position have their frames determined
// directly and are skipped during layout.
if (child.Position == Position.Absolute) {
Expand Down Expand Up @@ -738,8 +742,8 @@ static void layout_items(Item item, int child_begin, int child_end, int children
}

for (int i = child_begin; i < child_end; i++) {

Item child = layout.child_at(item, i);
if (!child.IsVisible) continue;
if (child.Position == Position.Absolute) {
// Already positioned.
continue;
Expand Down
45 changes: 44 additions & 1 deletion Xamarin.Forms.Core.UnitTests/FlexLayoutTests.cs
Expand Up @@ -427,5 +427,48 @@ public void TestReverseWithGrow()
layout.Layout(new Rectangle(0, 0, 300, 300));
Assert.That(label0.Bounds, Is.EqualTo(new Rectangle(0, 0, 300, 300)));
}

[Test]
public void TestIsVisible()
//https://github.com/xamarin/Xamarin.Forms/issues/2593
{
var platform = new UnitPlatform();
var label0 = new Label {
Platform = platform,
IsPlatformEnabled = true,
};
var label1 = new Label {
Platform = platform,
IsPlatformEnabled = true,
};
var label2 = new Label {
Platform = platform,
IsPlatformEnabled = true,
};
var layout = new FlexLayout {
Platform = platform,
IsPlatformEnabled = true,
Direction = FlexDirection.Column,
Children = {
label0,
label1,
label2,
}
};

layout.Layout(new Rectangle(0, 0, 300, 300));
Assert.That(label0.Bounds, Is.EqualTo(new Rectangle(0, 0, 300, 20)));
Assert.That(label1.Bounds, Is.EqualTo(new Rectangle(0, 20, 300, 20)));
Assert.That(label2.Bounds, Is.EqualTo(new Rectangle(0, 40, 300, 20)));

label1.IsVisible = false;
Assert.That(label0.Bounds, Is.EqualTo(new Rectangle(0, 0, 300, 20)));
Assert.That(label2.Bounds, Is.EqualTo(new Rectangle(0, 20, 300, 20)));

label0.IsVisible = false;
label1.IsVisible = true;
Assert.That(label1.Bounds, Is.EqualTo(new Rectangle(0, 0, 300, 20)));
Assert.That(label2.Bounds, Is.EqualTo(new Rectangle(0, 20, 300, 20)));
}
}
}
}
11 changes: 10 additions & 1 deletion Xamarin.Forms.Core/FlexLayout.cs
Expand Up @@ -302,7 +302,8 @@ void InitItemProperties(View view, Flex.Item item)
AlignSelfProperty,
MarginProperty,
WidthRequestProperty,
HeightRequestProperty);
HeightRequestProperty,
IsVisibleProperty);
item.Order = (int)values[0];
item.Grow = (float)values[1];
item.Shrink = (float)values[2];
Expand All @@ -314,6 +315,7 @@ void InitItemProperties(View view, Flex.Item item)
item.MarginBottom = (float)((Thickness)values[5]).Bottom;
item.Width = (double)values[6] < 0 ? float.NaN : (float)(double)values[6];
item.Height = (double)values[7] < 0 ? float.NaN : (float)(double)values[7];
item.IsVisible = (bool)values[8];
if (view is FlexLayout) {
var padding = view.GetValue(PaddingProperty);
item.PaddingLeft = (float)((Thickness)padding).Left;
Expand Down Expand Up @@ -372,6 +374,13 @@ void OnChildPropertyChanged(object sender, PropertyChangedEventArgs e)
return;
}

if (e.PropertyName == IsVisibleProperty.PropertyName) {
var item = (sender as FlexLayout)?._root ?? GetFlexItem((BindableObject)sender);
if (item == null)
return;
item.IsVisible = (bool)((View)sender).GetValue(IsVisibleProperty);
}

if ( e.PropertyName == OrderProperty.PropertyName
|| e.PropertyName == GrowProperty.PropertyName
|| e.PropertyName == ShrinkProperty.PropertyName
Expand Down

0 comments on commit 713ed70

Please sign in to comment.