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

Conversation

almedina-ms
Copy link
Contributor

@almedina-ms almedina-ms commented Apr 26, 2019

Fixes #2604
Also fixes #2890

The big problem is that toggle visibility doesn't interact correctly with elements that have spacing between them, so when the elements are hidden, their separators are not hidden (the same behaviour happens when the element is originally not visible).

How verified

Two test files were modified for testing the correct behavior and, for testing purposes, the separator color was changed so the change would be more visible

WPF

For WPF the spacings are margins at the top so that value must be modified when hiding and showing

Hide the separator for the first visible element on card creation
image

Hide the separator for the first visible element on toggle action

Initial state
image

State after the first element (Image) was hidden
image

State after the first column has been hidden
image

HTML

Hide the separator for the first visible element on card creation

image

Hide the separator for the first visible element on toggle action

Initial state
image

State after the first element (Image) was hidden
image

State after the first column has been hidden
image

ColumnDefinition columnDefinition = new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) };
tag.NotAutoWidthColumnDefinition = columnDefinition;
tag.ViewIndex = uiColumnSet.ColumnDefinitions.Count;
uiColumnSet.ColumnDefinitions.Add(columnDefinition);
Copy link
Member

@paulcam206 paulcam206 Apr 26, 2019

Choose a reason for hiding this comment

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

can't this more cleanly be written by generating the ColumnDefinition for each situation, and then adding it in one spot? #Closed


const parent = targetElement.parentNode;
var isFirstElement = true;
for(var k = 0; k < parent.childNodes.length; k++){{
Copy link
Member

@paulcam206 paulcam206 Apr 26, 2019

Choose a reason for hiding this comment

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

mix of tabs and spaces #Closed

@@ -279,17 +279,68 @@ static int Main(string[] args)
// The way to discern between checkbox elements and inline-actions is that inline-actions contain a textinput
var isCheckBoxElement = ((targetElementsInDocument.length > 1) && !(targetElement.className.includes('ac-textinput')));

const targetSeparatorId = targetElement.dataset.acSeparatorid;
Copy link
Member

@paulcam206 paulcam206 Apr 26, 2019

Choose a reason for hiding this comment

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

  				 [](start = 86, length = 6)

unnecessary trailing tabs here #Closed

Copy link
Member

@paulcam206 paulcam206 left a comment

Choose a reason for hiding this comment

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

🕐

@shalinijoshi19
Copy link
Member

shalinijoshi19 commented Apr 30, 2019

  	"wrap": true,

Can you make sure the new cards you added are referenced in the feature testing bug bash notes in our OneNote also? #Resolved


Refers to: samples/Tests/ToggleVisibility.AllElements.json:255 in cec3a75. [](commit_id = cec3a75, deletion_comment = False)


public AdaptiveSpacing Spacing { get; set; } = AdaptiveSpacing.None;

public Grid ElementContainer { get; set; }
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.

ElementContainer [](start = 20, length = 16)

rename to ParentElementContainer #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed to ParentContainerElement


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


public ColumnDefinition NotAutoWidthColumnDefinition { get; set; } = null;

public RowDefinition NotAutoHeightRowDefinition { get; set; } = 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.

rename to ColumnDefinition and RowDefinition and store auto by default #Resolved

@@ -83,9 +82,12 @@ public static void AddContainerElements(Grid uiContainer, IList<AdaptiveElement>
FrameworkElement uiElement = context.Render(cardElement);
if (uiElement != null)
{
TagContent tag = new TagContent(AdaptiveSpacing.None, uiContainer);
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.

add this as a last else #Resolved

}
else
{
RowDefinition rowDefinition = new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) };
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.

RowDefinition [](start = 24, length = 13)

add comment for clarification on what tag information is being stored here and why #Resolved

uiColumnSet.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
{
columnDefinition = new ColumnDefinition() { Width = GridLength.Auto };

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.

nit: extra line
#Resolved

{
columnDefinition = new ColumnDefinition() { Width = GridLength.Auto };
}

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.

nit: extra line #Resolved

@@ -286,24 +286,164 @@ public FontColorConfig GetForegroundColors(AdaptiveTextColor textColor)
}
}

private TagContent GetTagContent(FrameworkElement element)
{
if (element != 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.

consolidate this ifs as they are checked left to right #Resolved

return null;
}

public void SetVisibility(FrameworkElement element, bool isVisible, TagContent tagContent)
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.

isVisible [](start = 65, length = 9)

rename to desiredVisibility #Resolved

}

// Trying to set the same rowDefinition twice to the same element is not valid, so we have to make a check first
if (!(elementIsCurrentlyVisible && isVisible))
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.

isVisible [](start = 51, length = 9)

move this check so the column and row Definitions are not created
#Resolved

// if we read something with the format {"elementId": <id>", "isVisible": true} or we just read the id and the element is not visible
if ((targetElement.IsVisible.HasValue && targetElement.IsVisible.Value) || (!targetElement.IsVisible.HasValue && visibility != Visibility.Visible))
// otherwise if we read something with the format {"elementId": <id>", "isVisible": false} or we just read the id and the element is visible
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.

wrap lines to 120ish characters so they are not extra long #Resolved


SetVisibility(elementFrameworkElement, newVisibility, tagContent);

if (tagContent != 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.

check just with tagContent for null check #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

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

C# doesn't allow null checks with only the variable name as C or C++ do


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

// if we read something with the format {"elementId": <id>", "isVisible": true} or we just read the id and the element is not visible
if ((targetElement.IsVisible.HasValue && targetElement.IsVisible.Value) || (!targetElement.IsVisible.HasValue && visibility != Visibility.Visible))
// otherwise if we read something with the format {"elementId": <id>", "isVisible": false} or we just read the id and the element is visible
bool newVisibility = (targetElement.IsVisible.HasValue && targetElement.IsVisible.Value) || (!targetElement.IsVisible.HasValue && !isCurrentlyVisible);
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.

split conditional and comment #Resolved

}

/// <summary>
/// Elements are adde to the container in two ways: if the height is auto or the inserted element is a container, then the element
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.

add d #Resolved

}

/// <summary>
/// Elements are adde to the container in two ways: if the height is auto or the inserted element is a container, then the element
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.

Regenerate and make the summary clearer #Resolved

}

Thickness renderedMargin = renderedElement.Margin;
renderedElement.Margin = new Thickness(renderedMargin.Left,
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 the spacing form being a margin to being a grid

Do this here or add a note on Bug #2816 for bleed #Resolved

"height": "stretch",
"version": "1.0",
"body": [
{
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.

run the UWP test app #Resolved

@@ -0,0 +1,42 @@
using System;
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.

add copyright banner #Resolved

foreach (var targetElement in toggleVisibilityAction.TargetElements)
{
// If the string is not empty, append a comma in preparation to add the new target element
if (!String.IsNullOrWhiteSpace(targetElements))
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 this to targetElements.IsNullOrWhiteSpace #Resolved

// 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)

}
}

if (!String.IsNullOrEmpty(cardElement.Id))
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.

use IsNullOrWhiteSpace rather than IsNullOrEmpty #Resolved

Copy link
Member

Choose a reason for hiding this comment

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

btw wrt our offline discussion, you can't call isNullOrWhitespace on the instance/object directly unless there is an extension method defined (probably would be neat) so incorrect on that front also; btw prefer using the string alias instead of the String class name generally but for now consistency with rest of the code base is fine!


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

}

// if explicit image size is not used, use Adaptive Image size
// if explicit image size is not used, use Adpative Image size
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.

Adpative [](start = 55, length = 8)

introduced typo here #Resolved

@RebeccaAnne
Copy link
Contributor

RebeccaAnne commented May 1, 2019

  	"id": "input6",

add test card where an element inside a container is made visible but the container is made hidden #Resolved


Refers to: samples/Tests/ToggleVisibility.AllElements.json:197 in 76533f4. [](commit_id = 76533f4, deletion_comment = False)

@shalinijoshi19
Copy link
Member

@almedina-ms anything blocking this review?

@almedina-ms
Copy link
Contributor Author

just missing approval


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

Copy link
Member

@paulcam206 paulcam206 left a comment

Choose a reason for hiding this comment

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

:shipit:

@paulcam206
Copy link
Member

PR also fixes #2890

@almedina-ms almedina-ms merged commit ee55bc3 into master May 15, 2019
@almedina-ms almedina-ms deleted the user/almedina-ms/WPFFixToggleVisibilitySpacing branch May 15, 2019 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants