Skip to content

Commit

Permalink
[UWP] Cherry-pick visibility fixes to release (#4120)
Browse files Browse the repository at this point in the history
Fixes #4035
Original commit: a4a1f1b
Original PR: #3264

Co-authored-by: almedina-ms <35784165+almedina-ms@users.noreply.github.com>
  • Loading branch information
paulcam206 and almedina-ms authored Jun 8, 2020
1 parent c59fb8a commit 5aad855
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 17 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19 changes: 18 additions & 1 deletion source/uwp/Renderer/lib/ElementTagContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ namespace AdaptiveNamespace
_In_ IPanel* parentPanel,
_In_ IUIElement* separator,
_In_ IColumnDefinition* columnDefinition,
boolean isStretchable)
_In_ boolean expectedVisibility,
_In_ boolean isStretchable)

{
if (parentPanel != nullptr)
{
Expand All @@ -28,6 +30,7 @@ namespace AdaptiveNamespace
m_columnDefinition = columnDefinition;
m_separator = separator;
m_cardElement = cardElement;
m_expectedVisibility = expectedVisibility;
m_isStretchable = isStretchable;
return S_OK;
}
Expand All @@ -51,14 +54,28 @@ namespace AdaptiveNamespace
{
return m_parentPanel.CopyTo(parentPanel);
}

HRESULT ElementTagContent::get_IsStretchable(boolean* isStretchable)
{
*isStretchable = m_isStretchable;
return S_OK;
}

HRESULT ElementTagContent::put_IsStretchable(boolean isStretchable)
{
m_isStretchable = isStretchable;
return S_OK;
}

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;
}
}
11 changes: 10 additions & 1 deletion source/uwp/Renderer/lib/ElementTagContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ 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;
virtual HRESULT get_IsStretchable(_Outptr_ boolean * isStretchable) = 0;
virtual HRESULT put_IsStretchable(boolean isStretchable) = 0;
};
Expand All @@ -28,12 +33,15 @@ namespace AdaptiveNamespace
_In_ ABI::Windows::UI::Xaml::Controls::IPanel* parentPanel,
_In_ ABI::Windows::UI::Xaml::IUIElement* separator,
_In_ ABI::Windows::UI::Xaml::Controls::IColumnDefinition* columnDefinition,
boolean isStretchable);
_In_ boolean expectedVisibility,
_In_ boolean isStretchable);

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;
virtual HRESULT get_IsStretchable(_Outptr_ boolean* isStretchable) override;
virtual HRESULT put_IsStretchable(boolean isStretchable) override;

Expand All @@ -42,6 +50,7 @@ namespace AdaptiveNamespace
Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::Controls::IColumnDefinition> m_columnDefinition;
Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::IUIElement> m_separator;
Microsoft::WRL::WeakRef m_parentPanel;
boolean m_expectedVisibility;
boolean m_isStretchable;
};
}
35 changes: 20 additions & 15 deletions source/uwp/Renderer/lib/XamlBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ namespace AdaptiveNamespace
RETURN_IF_FAILED(element->get_Height(&heightType));

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

XamlHelpers::AppendXamlElementToPanel(newControl, parentPanel, heightType);
Expand Down Expand Up @@ -983,11 +983,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 @@ -1464,7 +1468,16 @@ namespace AdaptiveNamespace
ComPtr<IUIElement> toggleElementAsUIElement;
RETURN_IF_FAILED(toggleElement.As(&toggleElementAsUIElement));

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

Visibility visibilityToSet = Visibility_Visible;
if (toggle == ABI::AdaptiveNamespace::IsVisible_IsVisibleTrue)
{
visibilityToSet = Visibility_Visible;
Expand All @@ -1475,21 +1488,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 5aad855

Please sign in to comment.