Skip to content

Commit

Permalink
dont try to activate recycle pool which is not public. (#526)
Browse files Browse the repository at this point in the history
* dont try to activate recycle pool which is not public.

* empty commit to kick the pipeline

* Ensure properties before they are used.
  • Loading branch information
ranjeshj authored and jevansaks committed Apr 5, 2019
1 parent 7c9a8bd commit d5abae6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 38 deletions.
8 changes: 4 additions & 4 deletions dev/Repeater/ItemTemplateWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void ItemTemplateWrapper::TemplateSelector(winrt::DataTemplateSelector const& va
winrt::UIElement ItemTemplateWrapper::GetElement(winrt::ElementFactoryGetArgs const& args)
{
auto selectedTemplate = m_dataTemplate ? m_dataTemplate : m_dataTemplateSelector.SelectTemplate(args.Data());
auto recyclePool = winrt::RecyclePool::GetPoolInstance(selectedTemplate);
auto recyclePool = RecyclePool::GetPoolInstance(selectedTemplate);
winrt::UIElement element = nullptr;

if (recyclePool)
Expand All @@ -68,15 +68,15 @@ void ItemTemplateWrapper::RecycleElement(winrt::ElementFactoryRecycleArgs const&
winrt::DataTemplate selectedTemplate = m_dataTemplate?
m_dataTemplate:
element.GetValue(RecyclePool::GetOriginTemplateProperty()).as<winrt::DataTemplate>();
auto recyclePool = CachedVisualTreeHelpers::GetPoolInstance(selectedTemplate);
auto recyclePool = RecyclePool::GetPoolInstance(selectedTemplate);
if (!recyclePool)
{
// No Recycle pool in the template, create one.
recyclePool = winrt::make<RecyclePool>();
CachedVisualTreeHelpers::SetPoolInstance(selectedTemplate, recyclePool);
RecyclePool::SetPoolInstance(selectedTemplate, recyclePool);
}

recyclePool.PutElement(args.Element(), L"" /* key */, args.Parent());
}

#pragma endregion
#pragma endregion
29 changes: 0 additions & 29 deletions dev/Repeater/ItemsRepeater.common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,6 @@ winrt::DependencyObject CachedVisualTreeHelpers::GetParent(winrt::DependencyObje
return instance->m_visualTreeHelper.GetParent(child);
}

/* static */
void CachedVisualTreeHelpers::SetPoolInstance(winrt::DataTemplate const& dataTemplate, winrt::RecyclePool const& recyclePool)
{
auto instance = LifetimeHandler::GetCachedVisualTreeHelpersInstance();
MUX_ASSERT(instance);

if (!instance->m_recyclePoolStatics)
{
instance->m_recyclePoolStatics = winrt::get_activation_factory<winrt::RecyclePool, winrt::IRecyclePoolStatics>();
}

instance->m_recyclePoolStatics.SetPoolInstance(dataTemplate, recyclePool);
}

/* static */
winrt::RecyclePool CachedVisualTreeHelpers::GetPoolInstance(winrt::DataTemplate const& dataTemplate)
{
auto instance = LifetimeHandler::GetCachedVisualTreeHelpersInstance();
MUX_ASSERT(instance);

if (!instance->m_recyclePoolStatics)
{
instance->m_recyclePoolStatics = winrt::get_activation_factory<winrt::RecyclePool, winrt::IRecyclePoolStatics>();
}

return instance->m_recyclePoolStatics.GetPoolInstance(dataTemplate);
}

/* static */
winrt::IDataTemplateComponent CachedVisualTreeHelpers::GetDataTemplateComponent(winrt::UIElement const& element)
{
auto instance = LifetimeHandler::GetCachedVisualTreeHelpersInstance();
Expand Down
4 changes: 0 additions & 4 deletions dev/Repeater/ItemsRepeater.common.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@ class CachedVisualTreeHelpers :
static winrt::Rect GetLayoutSlot(winrt::FrameworkElement const& element);
static winrt::DependencyObject GetParent(winrt::DependencyObject const& child);

static void SetPoolInstance(winrt::DataTemplate const& dataTemplate, winrt::RecyclePool const& recyclePool);
static winrt::RecyclePool GetPoolInstance(winrt::DataTemplate const& dataTemplate);

static winrt::IDataTemplateComponent GetDataTemplateComponent(winrt::UIElement const& element);
CachedVisualTreeHelpers() {}

private:
winrt::ILayoutInformationStatics m_layoutInfo;
winrt::IVisualTreeHelperStatics m_visualTreeHelper;
winrt::IRecyclePoolStatics m_recyclePoolStatics;
winrt::IXamlBindingHelperStatics m_xamlBindingHelperStatics;
};
12 changes: 11 additions & 1 deletion dev/Repeater/RecyclePoolFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@ void RecyclePool::SetReuseKey(winrt::UIElement const& element, winrt::hstring co

winrt::RecyclePool RecyclePool::GetPoolInstance(winrt::DataTemplate const& dataTemplate)
{
if (!s_poolInstanceProperty)
{
EnsureProperties();
}

return dataTemplate.GetValue(s_poolInstanceProperty).try_as<winrt::RecyclePool>();
}

void RecyclePool::SetPoolInstance(winrt::DataTemplate const& dataTemplate, winrt::RecyclePool const& value)
{
if (!s_poolInstanceProperty)
{
EnsureProperties();
}

dataTemplate.SetValue(s_poolInstanceProperty, value);
}

Expand Down Expand Up @@ -82,4 +92,4 @@ void RecyclePool::ClearProperties()
s_reuseKeyProperty = nullptr;
s_poolInstanceProperty = nullptr;
s_originTemplateProperty = nullptr;
}
}

0 comments on commit d5abae6

Please sign in to comment.