Skip to content

Commit

Permalink
[UWP] Add ExpectedVisibility flag to tag to avoid hiding separator (#…
Browse files Browse the repository at this point in the history
…3264)

* Add expected visibility flag to avoid auto size images issue

* Update tests results

* Fix comments
  • Loading branch information
almedina-ms authored Jul 29, 2019
1 parent 1605822 commit a4a1f1b
Show file tree
Hide file tree
Showing 54 changed files with 43 additions and 16 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 15 additions & 1 deletion source/uwp/Renderer/lib/ElementTagContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ namespace AdaptiveNamespace
HRESULT ElementTagContent::RuntimeClassInitialize(_In_ IAdaptiveCardElement* cardElement,
_In_ IPanel* parentPanel,
_In_ IUIElement* separator,
_In_ IColumnDefinition* columnDefinition)
_In_ IColumnDefinition* columnDefinition,
_In_ boolean expectedVisibility)
{
m_columnDefinition = columnDefinition;
m_parentPanel = parentPanel;
m_separator = separator;
m_cardElement = cardElement;
m_expectedVisibility = expectedVisibility;
return S_OK;
}

Expand All @@ -41,4 +43,16 @@ namespace AdaptiveNamespace
{
return m_parentPanel.CopyTo(parentPanel);
}

HRESULT ElementTagContent::get_ExpectedVisibility(_Outptr_ boolean* expectedVisibility)
{
*expectedVisibility = m_expectedVisibility;
return S_OK;
}

HRESULT ElementTagContent::set_ExpectedVisibility(boolean expectedVisibility)
{
m_expectedVisibility = expectedVisibility;
return S_OK;
}
}
10 changes: 9 additions & 1 deletion source/uwp/Renderer/lib/ElementTagContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ namespace AdaptiveNamespace
virtual HRESULT get_AdaptiveCardElement(_COM_Outptr_ ABI::AdaptiveNamespace::IAdaptiveCardElement * *cardElement) = 0;
virtual HRESULT get_Separator(_COM_Outptr_ ABI::Windows::UI::Xaml::IUIElement * *separator) = 0;
virtual HRESULT get_ParentPanel(_COM_Outptr_ ABI::Windows::UI::Xaml::Controls::IPanel * *parentPanel) = 0;
// Auto size images hide themselves while they haven't finished loading even when they are expected to be visible so the best way
// to track the intended visibility of the element and its separator is keeping this flag to avoid comparing against the rendered visibility
virtual HRESULT get_ExpectedVisibility(_Outptr_ boolean* expectedVisibility) = 0;
virtual HRESULT set_ExpectedVisibility(_In_ boolean expectedVisibility) = 0;
};

class ElementTagContent
Expand All @@ -21,17 +25,21 @@ namespace AdaptiveNamespace
HRESULT RuntimeClassInitialize(_In_ ABI::AdaptiveNamespace::IAdaptiveCardElement* cardElement,
_In_ ABI::Windows::UI::Xaml::Controls::IPanel* parentPanel,
_In_ ABI::Windows::UI::Xaml::IUIElement* separator,
_In_ ABI::Windows::UI::Xaml::Controls::IColumnDefinition* columnDefinition);
_In_ ABI::Windows::UI::Xaml::Controls::IColumnDefinition* columnDefinition,
_In_ boolean expectedVisibility);

virtual HRESULT get_ColumnDefinition(_COM_Outptr_ ABI::Windows::UI::Xaml::Controls::IColumnDefinition** columnDefinition) override;
virtual HRESULT get_AdaptiveCardElement(_COM_Outptr_ ABI::AdaptiveNamespace::IAdaptiveCardElement** cardElement) override;
virtual HRESULT get_Separator(_COM_Outptr_ ABI::Windows::UI::Xaml::IUIElement** separator) override;
virtual HRESULT get_ParentPanel(_COM_Outptr_ ABI::Windows::UI::Xaml::Controls::IPanel** parentPanel) override;
virtual HRESULT get_ExpectedVisibility(_Outptr_ boolean* expectedVisibility) override;
virtual HRESULT set_ExpectedVisibility(_In_ boolean expectedVisibility) override;

private:
Microsoft::WRL::ComPtr<ABI::AdaptiveNamespace::IAdaptiveCardElement> m_cardElement;
Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::Controls::IColumnDefinition> m_columnDefinition;
Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::IUIElement> m_separator;
Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::Controls::IPanel> m_parentPanel;
boolean m_expectedVisibility;
};
}
33 changes: 19 additions & 14 deletions source/uwp/Renderer/lib/XamlBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ namespace AdaptiveNamespace
}

ComPtr<ElementTagContent> tagContent;
RETURN_IF_FAILED(MakeAndInitialize<ElementTagContent>(&tagContent, element, parentPanel, separator, columnDefinition));
RETURN_IF_FAILED(MakeAndInitialize<ElementTagContent>(&tagContent, element, parentPanel, separator, columnDefinition, isVisible));
RETURN_IF_FAILED(newControlAsFrameworkElement->put_Tag(tagContent.Get()));

ABI::AdaptiveNamespace::HeightType heightType{};
Expand Down Expand Up @@ -973,11 +973,15 @@ namespace AdaptiveNamespace
Visibility visibility;
RETURN_IF_FAILED(child->get_Visibility(&visibility));

boolean expectedVisibility{};
RETURN_IF_FAILED(elementTagContent->get_ExpectedVisibility(&expectedVisibility));

if (separator)
{
if (visibility == Visibility_Collapsed || !foundPreviousVisibleElement)
if (!expectedVisibility || !foundPreviousVisibleElement)
{
// If the element is collapsed, or if it's the first visible element, collapse the separator
// Images are hidden while they are retrieved, we shouldn't hide the separator
RETURN_IF_FAILED(separator->put_Visibility(Visibility_Collapsed));
}
else
Expand Down Expand Up @@ -1448,6 +1452,15 @@ namespace AdaptiveNamespace
ComPtr<IUIElement> toggleElementAsUIElement;
RETURN_IF_FAILED(toggleElement.As(&toggleElementAsUIElement));

ComPtr<IFrameworkElement> toggleElementAsFrameworkElement;
RETURN_IF_FAILED(toggleElement.As(&toggleElementAsFrameworkElement));

ComPtr<IInspectable> tag;
RETURN_IF_FAILED(toggleElementAsFrameworkElement->get_Tag(&tag));

ComPtr<IElementTagContent> elementTagContent;
RETURN_IF_FAILED(tag.As(&elementTagContent));

Visibility visibilityToSet = Visibility_Visible;
if (toggle == ABI::AdaptiveNamespace::IsVisible_IsVisibleTrue)
{
Expand All @@ -1459,21 +1472,13 @@ namespace AdaptiveNamespace
}
else if (toggle == ABI::AdaptiveNamespace::IsVisible_IsVisibleToggle)
{
Visibility currentVisibility;
RETURN_IF_FAILED(toggleElementAsUIElement->get_Visibility(&currentVisibility));
visibilityToSet = (currentVisibility == Visibility_Collapsed) ? Visibility_Visible : Visibility_Collapsed;
boolean currentVisibility{};
RETURN_IF_FAILED(elementTagContent->get_ExpectedVisibility(&currentVisibility));
visibilityToSet = (currentVisibility) ? Visibility_Collapsed : Visibility_Visible;
}

RETURN_IF_FAILED(toggleElementAsUIElement->put_Visibility(visibilityToSet));

ComPtr<IFrameworkElement> toggleElementAsFrameworkElement;
RETURN_IF_FAILED(toggleElement.As(&toggleElementAsFrameworkElement));

ComPtr<IInspectable> tag;
RETURN_IF_FAILED(toggleElementAsFrameworkElement->get_Tag(&tag));

ComPtr<IElementTagContent> elementTagContent;
RETURN_IF_FAILED(tag.As(&elementTagContent));
RETURN_IF_FAILED(elementTagContent->set_ExpectedVisibility(visibilityToSet == Visibility_Visible));

ComPtr<IPanel> parentPanel;
RETURN_IF_FAILED(elementTagContent->get_ParentPanel(&parentPanel));
Expand Down

0 comments on commit a4a1f1b

Please sign in to comment.