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

Backport CommandBarFlyout shadow fix #281

Merged
merged 5 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
31 changes: 4 additions & 27 deletions dev/CommandBarFlyout/CommandBarFlyout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,6 @@ CommandBarFlyout::CommandBarFlyout()
{
if (auto commandBar = winrt::get_self<CommandBarFlyoutCommandBar>(m_commandBar.get()))
{
if (SharedHelpers::IsThemeShadowAvailable())
{
#if defined(BUILD_WINDOWS)
if (Feature_CommandBarFlyoutShadow::IsEnabled())
{
// Apply a shadow (only if we have a CommandBar worth shadowing)
winrt::Windows::UI::Xaml::Media::ThemeShadow shadow;
commandBar->Shadow(shadow);
bool havePrimaryCommands = PrimaryCommands().Size() > 0;
auto translation = havePrimaryCommands ? winrt::float3{ 0.0f, 0.0f, 32.0f } : winrt::float3{ 0.0f, 0.0f, 0.0f };
commandBar->Translation(translation);
}
#endif
}

if (commandBar->HasOpenAnimation())
{
commandBar->PlayOpenAnimation();
Expand All @@ -175,6 +160,10 @@ CommandBarFlyout::CommandBarFlyout()
});
commandBar->IsOpen(false);
}
//CommandBarFlyoutCommandBar.Closed will be called when
//clicking the more (...) button, we clear the translations
//here
commandBar->ClearShadow();
}
}
});
Expand All @@ -186,18 +175,6 @@ CommandBarFlyout::CommandBarFlyout()
{
if (auto commandBar = m_commandBar.get())
{
if (SharedHelpers::IsThemeShadowAvailable())
{
#if defined(BUILD_WINDOWS)
if (Feature_CommandBarFlyoutShadow::IsEnabled())
{
// Clear the shadow
auto translation = winrt::float3{ 0.0f, 0.0f, 0.0f };
commandBar.Translation(translation);
}
#endif
}

if (commandBar.IsOpen())
{
commandBar.IsOpen(false);
Expand Down
65 changes: 64 additions & 1 deletion dev/CommandBarFlyout/CommandBarFlyoutCommandBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ CommandBarFlyoutCommandBar::CommandBarFlyoutCommandBar()
});

SizeChanged({ [this](auto const&, auto const&) { UpdateUI(); } });
Closed({ [this](auto const&, auto const&) { m_secondaryItemsRootSized = false; } });
Closed({ [this](auto const&, auto const&)
{
m_secondaryItemsRootSized = false;
} });

RegisterPropertyChangedCallback(
winrt::AppBar::IsOpenProperty(),
Expand Down Expand Up @@ -267,6 +270,7 @@ void CommandBarFlyoutCommandBar::UpdateUI(bool useTransitions)
{
UpdateTemplateSettings();
UpdateVisualState(useTransitions);
UpdateShadow();
}

void CommandBarFlyoutCommandBar::UpdateVisualState(bool useTransitions)
Expand Down Expand Up @@ -468,3 +472,62 @@ void CommandBarFlyoutCommandBar::UpdateTemplateSettings()
}
}
}

void CommandBarFlyoutCommandBar::UpdateShadow()
{
if (PrimaryCommands().Size() > 0)
{
AddShadow();
}
else if (PrimaryCommands().Size() == 0)
{
ClearShadow();
}
}

void CommandBarFlyoutCommandBar::AddShadow()
{
if (SharedHelpers::IsThemeShadowAvailable())
{
#ifdef USE_INSIDER_SDK
//Apply Shadow on the Grid named "ContentRoot", this is the first element below
//the clip animation of the commandBar. This guarantees that shadow respects the
//animation
winrt::IControlProtected thisAsControlProtected = *this;
auto grid = GetTemplateChildT<winrt::Grid>(L"ContentRoot", thisAsControlProtected);
if (winrt::IUIElement10 grid_uiElement10 = grid)
{
if (grid_uiElement10.Shadow() == nullptr)
{
winrt::Windows::UI::Xaml::Media::ThemeShadow shadow;
grid_uiElement10.Shadow(shadow);

auto translation = winrt::float3{ grid.Translation().x, grid.Translation().y, 32.0f };
grid.Translation(translation);
}
}
#endif
}
}

void CommandBarFlyoutCommandBar::ClearShadow()
{
if (SharedHelpers::IsThemeShadowAvailable())
{
#ifdef USE_INSIDER_SDK
winrt::IControlProtected thisAsControlProtected = *this;
auto grid = GetTemplateChildT<winrt::Grid>(L"ContentRoot", thisAsControlProtected);
if (winrt::IUIElement10 grid_uiElement10 = grid)
{
if (grid_uiElement10.Shadow() != nullptr)
{
grid_uiElement10.Shadow(nullptr);

//Undo the elevation
auto translation = winrt::float3{ grid.Translation().x, grid.Translation().y, 0.0f };
grid.Translation(translation);
}
}
#endif
}
}
4 changes: 4 additions & 0 deletions dev/CommandBarFlyout/CommandBarFlyoutCommandBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ class CommandBarFlyoutCommandBar :
void PlayOpenAnimation();
bool HasCloseAnimation();
void PlayCloseAnimation(std::function<void()> onCompleteFunc);
void ClearShadow();

private:
void AttachEventHandlers();
void DetachEventHandlers(bool useSafeGet = false);

void AddShadow();

void UpdateFlowsFromAndFlowsTo();
void UpdateUI(bool useTransitions = true);
void UpdateVisualState(bool useTransitions);
void UpdateTemplateSettings();
void UpdateShadow();

tracker_ref<winrt::FrameworkElement> m_primaryItemsRoot{ this };
tracker_ref<winrt::FrameworkElement> m_secondaryItemsRoot{ this };
Expand Down