Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[.NET][WPF][HTML] Fix toggle visibility spacing #2767

Merged
merged 24 commits into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f507186
Fix visibility issue for columns
almedina-ms Apr 24, 2019
63f4f65
Fix separator issue in WPF
almedina-ms Apr 25, 2019
59ec280
Almost fix HTML renderer
almedina-ms Apr 26, 2019
e4afa05
Fix toggle visibility select actions
almedina-ms Apr 26, 2019
1e4d4f1
Merge branch 'master' into user/almedina-ms/WPFFixToggleVisibilitySpa…
almedina-ms Apr 26, 2019
fdf5745
Add test for checking initial state of separators
almedina-ms Apr 26, 2019
483e620
Fix html for hiding separators in initial state
almedina-ms Apr 26, 2019
92f5d34
Merge branch 'master' into user/almedina-ms/WPFFixToggleVisibilitySpa…
almedina-ms Apr 26, 2019
f5de980
Fix logic in column separators
almedina-ms Apr 26, 2019
549c969
Merge branch 'master' into user/almedina-ms/WPFFixToggleVisibilitySpa…
almedina-ms Apr 29, 2019
b9578ac
Fix sample app to render tall cards
almedina-ms Apr 30, 2019
be2cbab
Fix PR Comments
almedina-ms Apr 30, 2019
86e9139
Fix test files
almedina-ms Apr 30, 2019
cec3a75
Fix test results
almedina-ms Apr 30, 2019
76533f4
Merge branch 'master' into user/almedina-ms/WPFFixToggleVisibilitySpa…
almedina-ms Apr 30, 2019
aebaadc
Fix comments
almedina-ms May 2, 2019
9943a69
Add test app results
almedina-ms May 2, 2019
2689e51
Fix more comments
almedina-ms May 2, 2019
38e45e4
Add results for new card
almedina-ms May 2, 2019
ced1f98
Merge branch 'master' into user/almedina-ms/WPFFixToggleVisibilitySpa…
almedina-ms May 2, 2019
4172253
Merge branch 'master' into user/almedina-ms/WPFFixToggleVisibilitySpa…
almedina-ms May 2, 2019
74c68a9
Merge branch 'master' into user/almedina-ms/WPFFixToggleVisibilitySpa…
May 10, 2019
e2f15be
Merge branch 'master' into user/almedina-ms/WPFFixToggleVisibilitySpa…
May 10, 2019
385cf0c
Merge branch 'master' into user/almedina-ms/WPFFixToggleVisibilitySpa…
almedina-ms May 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions samples/Tests/Container.HideAndShowElement.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
"$schema": "https://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"height": "stretch",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "This test checks if showing an element inside a container that is hiding, will behave correctly by not showing the container",
"wrap": true
},
{
"type": "TextBlock",
"text": "Container (id1)",
"wrap": true
},
{
"type": "Container",
"id": "id1",
"style": "emphasis",
"items": [
{
"type": "TextBlock",
"id": "id2",
"text": "TextBlock (id2) inside a container",
"wrap": true
}
]
},
{
"type": "TextBlock",
"text": "Column (id3)",
"wrap": true
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"spacing": "large",
"id": "id3",
"style": "emphasis",
"items": [
{
"type": "TextBlock",
"id": "id4",
"text": "TextBlock (id4) inside a columnSet",
"wrap": true
}
]
}
]
}
],
"actions": [
{
"type": "Action.ToggleVisibility",
"title": "Hide containers, show element",
"targetElements": [
{
"elementId": "id1",
"isVisible": false
},
{
"elementId": "id2",
"isVisible": true
},
{
"elementId": "id3",
"isVisible": false
},
{
"elementId": "id4",
"isVisible": true
}
]
},
{
"type": "Action.ToggleVisibility",
"title": "Show element, hide containers",
"targetElements": [
{
"elementId": "id2",
"isVisible": true
},
{
"elementId": "id1",
"isVisible": false
},
{
"elementId": "id4",
"isVisible": true
},
{
"elementId": "id3",
"isVisible": false
}
]
},
{
"type": "Action.ToggleVisibility",
"title": "Show everything",
"targetElements": [
{
"elementId": "id1",
"isVisible": true
},
{
"elementId": "id2",
"isVisible": true
},
{
"elementId": "id3",
"isVisible": true
},
{
"elementId": "id4",
"isVisible": true
}
]
}
]
}
77 changes: 77 additions & 0 deletions samples/Tests/HideFirstVisibleElementSeparator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"$schema": "https://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "Image",
"url": "https://adaptivecards.io/content/cats/1.png",
"id": "id1",
"isVisible": false,
"selectAction": {
"type": "Action.ToggleVisibility",
"targetElements": [
"id2"
]
}
},
{
"type": "Container",
"id": "id2",
"spacing": "large",
"selectAction": {
"type": "Action.ToggleVisibility",
"targetElements": [
"id3"
]
},
"items": [
{
"type": "TextBlock",
"text": "There's an image above this but the visibility is set to false. There shouldn't be a spacing above",
"wrap": true
},
{
"type": "Image",
"url": "https://adaptivecards.io/content/cats/1.png"
}
]
},
{
"type": "ColumnSet",
"height": "stretch",
"spacing": "default",
"id": "id3",
"selectAction": {
"type": "Action.ToggleVisibility",
"targetElements": [
"id1"
]
},
"columns": [
{
"type": "Column",
"isVisible": false,
"items": [
{
"type": "TextBlock",
"text": "Column 1"
}
]
},
{
"type": "Column",
"spacing": "large",
"items": [
{
"type": "TextBlock",
"wrap": true,
"text": "This is the second column. There shouldn't be spacing before this"
}
]
}
]
}
],
"actions": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ protected static void AddContainerElements(HtmlTag uiContainer, IList<AdaptiveEl
{
if (elements != null)
{
bool isFirstElement = true;

foreach (var cardElement in elements)
{
// each element has a row
Expand Down Expand Up @@ -489,8 +491,21 @@ protected static void AddContainerElements(HtmlTag uiContainer, IList<AdaptiveEl
uiSeparator.Style("display", "none");
}
}
else
{
// if it's visible and it's the first element, hide the separator
if (isFirstElement)
{
if (uiSeparator != null)
Copy link
Contributor

@RebeccaAnne RebeccaAnne May 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change null checks from "element != null" to "element" #Resolved

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you are right! my bad


In reply to: 280227777 [](ancestors = 280227777)

{
uiSeparator.Style("display", "none");
}

isFirstElement = false;
}
}

if (!String.IsNullOrEmpty(cardElement.Id))
if (!String.IsNullOrWhiteSpace(cardElement.Id))
{
uiElement.Attr("name", cardElement.Id);
}
Expand Down Expand Up @@ -648,6 +663,7 @@ protected static HtmlTag ColumnSetRender(AdaptiveColumnSet columnSet, AdaptiveRe
return 0;
}).Sum());

bool isFirstVisibleColumn = true;
for (int i = 0; i < columnSet.Columns.Count; ++i)
{
var column = columnSet.Columns[i];
Expand Down Expand Up @@ -719,19 +735,30 @@ protected static HtmlTag ColumnSetRender(AdaptiveColumnSet columnSet, AdaptiveRe
int spacing = context.Config.GetSpacing(column.Spacing) / 2;
int lineThickness = column.Separator ? sep.LineThickness : 0;

separator = new DivTag()
.AddClass($"ac-columnseparator")
.Style("flex", "0 0 auto")
.Style("padding-left", $"{spacing}px")
.Style("margin-left", $"{spacing}px")
.Style("border-left-style", $"solid");

// This are the only two properties for separator
if (sep != null)
{
separator = new DivTag()
.AddClass($"ac-columnseparator")
.Style("flex", "0 0 auto")
.Style("padding-left", $"{spacing}px")
.Style("margin-left", $"{spacing}px")
.Style("border-left-color", $"{context.GetRGBColor(sep.LineColor)}")
.Style("border-left-width", $"{lineThickness}px")
.Style("border-left-style", $"solid");

uiColumnSet.Children.Add(separator);
separator.Style("border-left-color", $"{context.GetRGBColor(sep.LineColor)}")
.Style("border-left-width", $"{lineThickness}px");
}

uiColumnSet.Children.Add(separator);
}

if (column.IsVisible && isFirstVisibleColumn)
{
if (separator != null)
{
separator.Style("display", "none");
}
isFirstVisibleColumn = false;
}

// do some sizing magic
Expand Down Expand Up @@ -1096,7 +1123,7 @@ protected static HtmlTag ImageRender(AdaptiveImage image, AdaptiveRenderContext
.Style("flex", "1 1 100%");
}

// if explicit image size is not used, use Adpative Image size
// if explicit image size is not used, use Adaptive Image size
if (image.PixelWidth == 0 && image.PixelHeight == 0)
{
switch (image.Size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static FrameworkElement Render(AdaptiveColumnSet columnSet, AdaptiveRende

FrameworkElement uiContainer = context.Render(column);

TagContent tag = new TagContent(AdaptiveSpacing.None, uiColumnSet);
TagContent tag = null;

// Add vertical Separator
if (uiColumnSet.ColumnDefinitions.Count > 0)
Expand All @@ -126,7 +126,14 @@ public static FrameworkElement Render(AdaptiveColumnSet columnSet, AdaptiveRende
Grid.SetColumn(uiSep, uiColumnSet.ColumnDefinitions.Count - 1);
uiColumnSet.Children.Add(uiSep);
}

else
{
tag = new TagContent(null, uiColumnSet);
}
}
else
{
tag = new TagContent(null, uiColumnSet);
}

// do some sizing magic using the magic GridUnitType.Star
Expand All @@ -135,42 +142,47 @@ public static FrameworkElement Render(AdaptiveColumnSet columnSet, AdaptiveRende
#pragma warning disable CS0618 // Type or member is obsolete
width = column.Size?.ToLower();
#pragma warning restore CS0618 // Type or member is obsolete

ColumnDefinition columnDefinition = null;

if (width == null || width == AdaptiveColumnWidth.Stretch.ToLower())
{
ColumnDefinition columnDefinition = new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) };
tag.NotAutoWidthColumnDefinition = columnDefinition;
tag.ViewIndex = uiColumnSet.ColumnDefinitions.Count;
uiColumnSet.ColumnDefinitions.Add(columnDefinition);
columnDefinition = new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) };
}
else if (width == AdaptiveColumnWidth.Auto.ToLower())
uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
{
columnDefinition = new ColumnDefinition() { Width = GridLength.Auto };
}
else
{
if (double.TryParse(width, out double val) && val >= 0)
{
// Weighted proportion (number only)
ColumnDefinition columnDefinition = new ColumnDefinition() { Width = new GridLength(val, GridUnitType.Star) };
tag.NotAutoWidthColumnDefinition = columnDefinition;
tag.ViewIndex = uiColumnSet.ColumnDefinitions.Count;
uiColumnSet.ColumnDefinitions.Add(columnDefinition);
columnDefinition = new ColumnDefinition() { Width = new GridLength(val, GridUnitType.Star) };
}
else if (width.EndsWith("px") && double.TryParse(width.Substring(0, width.Length - 2), out double pxVal) && pxVal >= 0)
{
// Exact pixel (number followed by "px")
ColumnDefinition columnDefinition = new ColumnDefinition() { Width = new GridLength((int)pxVal, GridUnitType.Pixel) };
tag.NotAutoWidthColumnDefinition = columnDefinition;
tag.ViewIndex = uiColumnSet.ColumnDefinitions.Count;
uiColumnSet.ColumnDefinitions.Add(columnDefinition);
columnDefinition = new ColumnDefinition() { Width = new GridLength((int)pxVal, GridUnitType.Pixel) };
}
else
uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
{
columnDefinition = new ColumnDefinition() { Width = GridLength.Auto };
}
}

uiContainer.Tag = tag;
context.SetVisibility(uiContainer, column.IsVisible, tag);
// Store the column definition in the tag so we can toggle the visibility later
tag.ColumnDefinition = columnDefinition;
tag.ViewIndex = uiColumnSet.ColumnDefinitions.Count;

uiColumnSet.ColumnDefinitions.Add(columnDefinition);

uiContainer.Tag = tag;

Grid.SetColumn(uiContainer, uiColumnSet.ColumnDefinitions.Count - 1);
uiColumnSet.Children.Add(uiContainer);

context.SetVisibility(uiContainer, column.IsVisible, tag);
}

context.ResetSeparatorVisibilityInsideContainer(uiColumnSet);
Expand Down
Loading