Skip to content

Commit

Permalink
feat(perf): Improve performance of the ScrollViewer with managed Scro…
Browse files Browse the repository at this point in the history
…llBar by defering their load
  • Loading branch information
dr1rrb authored and Dr.Rx committed Oct 21, 2020
1 parent e5af774 commit 08eacc5
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 122 deletions.
237 changes: 127 additions & 110 deletions src/Uno.UI/UI/Xaml/Controls/ScrollBar/ScrollBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ void Initialize()
Unloaded += DetachEvents;
}

/// <summary>
/// Indicates if this scrollbar supports to change its orientation once its template has been applied (cf. remarks).
/// This is false by default (which means that the ScrollBar will support dynamic orientation changes).
/// </summary>
/// <remarks>
/// This flag is for performance consideration, it allows ScrollBar to load only half of its template.
/// It's used by core controls (e.g. ScrollViewer) where the ScrollBar's orientation will never change.
/// It's required as, unlike UWP, a control which is Visibility = Collapsed will get its template applied anyway.
/// </remarks>
internal bool IsFixedOrientation { get; set; } = false;

// Update the visual states when the Visibility property is changed.
protected override void OnVisibilityChanged(Visibility oldValue, Visibility newValue)
{
Expand Down Expand Up @@ -150,151 +161,157 @@ protected override void OnApplyTemplate()
base.OnApplyTemplate();

// Get the parts
spElementHorizontalTemplate = GetTemplateChildHelper<FrameworkElement>("HorizontalRoot");
m_tpElementHorizontalTemplate = spElementHorizontalTemplate;
spElementHorizontalLargeIncrease = GetTemplateChildHelper<RepeatButton>("HorizontalLargeIncrease");
m_tpElementHorizontalLargeIncrease = spElementHorizontalLargeIncrease;
if (m_tpElementHorizontalLargeIncrease != null)
{
strAutomationName = AutomationProperties.GetName(m_tpElementHorizontalLargeIncrease);

if (strAutomationName == null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_HORIZONTALLARGEINCREASE, strAutomationName));
AutomationProperties.SetName(m_tpElementHorizontalLargeIncrease as RepeatButton, strAutomationName);
}
}
spElementHorizontalSmallIncrease =GetTemplateChildHelper<RepeatButton>("HorizontalSmallIncrease");
m_tpElementHorizontalSmallIncrease = spElementHorizontalSmallIncrease;
if (m_tpElementHorizontalSmallIncrease != null)
if (!IsFixedOrientation || Orientation == Orientation.Horizontal)
{
strAutomationName = AutomationProperties.GetName(m_tpElementHorizontalSmallIncrease);

if (strAutomationName == null)
spElementHorizontalTemplate = GetTemplateChildHelper<FrameworkElement>("HorizontalRoot");
m_tpElementHorizontalTemplate = spElementHorizontalTemplate;
spElementHorizontalLargeIncrease = GetTemplateChildHelper<RepeatButton>("HorizontalLargeIncrease");
m_tpElementHorizontalLargeIncrease = spElementHorizontalLargeIncrease;
if (m_tpElementHorizontalLargeIncrease != null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_HORIZONTALSMALLINCREASE, strAutomationName));
AutomationProperties.SetName(m_tpElementHorizontalSmallIncrease, strAutomationName);
strAutomationName = AutomationProperties.GetName(m_tpElementHorizontalLargeIncrease);

if (strAutomationName == null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_HORIZONTALLARGEINCREASE, strAutomationName));
AutomationProperties.SetName(m_tpElementHorizontalLargeIncrease as RepeatButton, strAutomationName);
}
}
}
spElementHorizontalLargeDecrease = GetTemplateChildHelper<RepeatButton>("HorizontalLargeDecrease");
m_tpElementHorizontalLargeDecrease = spElementHorizontalLargeDecrease;
if (m_tpElementHorizontalLargeDecrease != null)
{
strAutomationName = AutomationProperties.GetName(m_tpElementHorizontalLargeDecrease);

if (strAutomationName == null)
spElementHorizontalSmallIncrease = GetTemplateChildHelper<RepeatButton>("HorizontalSmallIncrease");
m_tpElementHorizontalSmallIncrease = spElementHorizontalSmallIncrease;
if (m_tpElementHorizontalSmallIncrease != null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_HORIZONTALLARGEDECREASE, strAutomationName));
AutomationProperties.SetName(m_tpElementHorizontalLargeDecrease, strAutomationName);

}
}
spElementHorizontalSmallDecrease = GetTemplateChildHelper<RepeatButton>("HorizontalSmallDecrease");
m_tpElementHorizontalSmallDecrease = spElementHorizontalSmallDecrease;
if (m_tpElementHorizontalSmallDecrease != null)
{
strAutomationName = AutomationProperties.GetName(m_tpElementHorizontalSmallDecrease);
strAutomationName = AutomationProperties.GetName(m_tpElementHorizontalSmallIncrease);

if (strAutomationName == null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_HORIZONTALSMALLDECREASE, strAutomationName));
AutomationProperties.SetName(m_tpElementHorizontalSmallDecrease, strAutomationName);
if (strAutomationName == null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_HORIZONTALSMALLINCREASE, strAutomationName));
AutomationProperties.SetName(m_tpElementHorizontalSmallIncrease, strAutomationName);

}
}
}
spElementHorizontalThumb = GetTemplateChildHelper<Thumb>("HorizontalThumb");
m_tpElementHorizontalThumb = spElementHorizontalThumb;
if (m_tpElementHorizontalThumb != null)
{
strAutomationName = AutomationProperties.GetName(m_tpElementHorizontalThumb);

if (strAutomationName == null)
spElementHorizontalLargeDecrease = GetTemplateChildHelper<RepeatButton>("HorizontalLargeDecrease");
m_tpElementHorizontalLargeDecrease = spElementHorizontalLargeDecrease;
if (m_tpElementHorizontalLargeDecrease != null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_HORIZONTALTHUMB, strAutomationName));
AutomationProperties.SetName(m_tpElementHorizontalThumb, strAutomationName);
strAutomationName = AutomationProperties.GetName(m_tpElementHorizontalLargeDecrease);

}
}
if (strAutomationName == null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_HORIZONTALLARGEDECREASE, strAutomationName));
AutomationProperties.SetName(m_tpElementHorizontalLargeDecrease, strAutomationName);

spElementVerticalTemplate = GetTemplateChildHelper<FrameworkElement>("VerticalRoot");
m_tpElementVerticalTemplate = spElementVerticalTemplate;
}
}
spElementHorizontalSmallDecrease = GetTemplateChildHelper<RepeatButton>("HorizontalSmallDecrease");
m_tpElementHorizontalSmallDecrease = spElementHorizontalSmallDecrease;
if (m_tpElementHorizontalSmallDecrease != null)
{
strAutomationName = AutomationProperties.GetName(m_tpElementHorizontalSmallDecrease);

spElementVerticalLargeIncrease = GetTemplateChildHelper<RepeatButton>("VerticalLargeIncrease");
m_tpElementVerticalLargeIncrease = spElementVerticalLargeIncrease;
if (m_tpElementVerticalLargeIncrease != null)
{
strAutomationName = AutomationProperties.GetName(m_tpElementVerticalLargeIncrease);
if (strAutomationName == null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_HORIZONTALSMALLDECREASE, strAutomationName));
AutomationProperties.SetName(m_tpElementHorizontalSmallDecrease, strAutomationName);

if (strAutomationName == null)
}
}
spElementHorizontalThumb = GetTemplateChildHelper<Thumb>("HorizontalThumb");
m_tpElementHorizontalThumb = spElementHorizontalThumb;
if (m_tpElementHorizontalThumb != null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_VERTICALALLARGEINCREASE, strAutomationName));
AutomationProperties.SetName(m_tpElementVerticalLargeIncrease, strAutomationName);
strAutomationName = AutomationProperties.GetName(m_tpElementHorizontalThumb);

if (strAutomationName == null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_HORIZONTALTHUMB, strAutomationName));
AutomationProperties.SetName(m_tpElementHorizontalThumb, strAutomationName);

}
}
}

spElementVerticalSmallIncrease = GetTemplateChildHelper<RepeatButton>("VerticalSmallIncrease");
m_tpElementVerticalSmallIncrease = spElementVerticalSmallIncrease;
if (m_tpElementVerticalSmallIncrease != null)
if (!IsFixedOrientation || Orientation == Orientation.Vertical)
{
strAutomationName = AutomationProperties.GetName(m_tpElementVerticalSmallIncrease);
spElementVerticalTemplate = GetTemplateChildHelper<FrameworkElement>("VerticalRoot");
m_tpElementVerticalTemplate = spElementVerticalTemplate;

if (strAutomationName == null)
spElementVerticalLargeIncrease = GetTemplateChildHelper<RepeatButton>("VerticalLargeIncrease");
m_tpElementVerticalLargeIncrease = spElementVerticalLargeIncrease;
if (m_tpElementVerticalLargeIncrease != null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_VERTICALSMALLINCREASE, strAutomationName));
AutomationProperties.SetName(m_tpElementVerticalSmallIncrease, strAutomationName);
strAutomationName = AutomationProperties.GetName(m_tpElementVerticalLargeIncrease);

if (strAutomationName == null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_VERTICALALLARGEINCREASE, strAutomationName));
AutomationProperties.SetName(m_tpElementVerticalLargeIncrease, strAutomationName);

}
}
}
spElementVerticalLargeDecrease = GetTemplateChildHelper<RepeatButton>("VerticalLargeDecrease");
m_tpElementVerticalLargeDecrease = spElementVerticalLargeDecrease;
if (m_tpElementVerticalLargeDecrease != null)
{
strAutomationName = AutomationProperties.GetName(m_tpElementVerticalLargeDecrease);

if (strAutomationName == null)
spElementVerticalSmallIncrease = GetTemplateChildHelper<RepeatButton>("VerticalSmallIncrease");
m_tpElementVerticalSmallIncrease = spElementVerticalSmallIncrease;
if (m_tpElementVerticalSmallIncrease != null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_VERTICALLARGEDECREASE, strAutomationName));
AutomationProperties.SetName(m_tpElementVerticalLargeDecrease, strAutomationName);
strAutomationName = AutomationProperties.GetName(m_tpElementVerticalSmallIncrease);

}
}
spElementVerticalSmallDecrease = GetTemplateChildHelper<RepeatButton>("VerticalSmallDecrease");
m_tpElementVerticalSmallDecrease = spElementVerticalSmallDecrease;
if (m_tpElementVerticalSmallDecrease != null)
{
strAutomationName = AutomationProperties.GetName(m_tpElementVerticalSmallDecrease);
if (strAutomationName == null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_VERTICALSMALLINCREASE, strAutomationName));
AutomationProperties.SetName(m_tpElementVerticalSmallIncrease, strAutomationName);

if (strAutomationName == null)
}
}
spElementVerticalLargeDecrease = GetTemplateChildHelper<RepeatButton>("VerticalLargeDecrease");
m_tpElementVerticalLargeDecrease = spElementVerticalLargeDecrease;
if (m_tpElementVerticalLargeDecrease != null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_VERTICALSMALLDECREASE, strAutomationName));
AutomationProperties.SetName(m_tpElementVerticalSmallDecrease, strAutomationName);
strAutomationName = AutomationProperties.GetName(m_tpElementVerticalLargeDecrease);

if (strAutomationName == null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_VERTICALLARGEDECREASE, strAutomationName));
AutomationProperties.SetName(m_tpElementVerticalLargeDecrease, strAutomationName);

}
}
}
spElementVerticalThumb = GetTemplateChildHelper<Thumb>("VerticalThumb");
m_tpElementVerticalThumb = spElementVerticalThumb;
if (m_tpElementVerticalThumb != null)
{
strAutomationName = AutomationProperties.GetName(m_tpElementVerticalThumb);
spElementVerticalSmallDecrease = GetTemplateChildHelper<RepeatButton>("VerticalSmallDecrease");
m_tpElementVerticalSmallDecrease = spElementVerticalSmallDecrease;
if (m_tpElementVerticalSmallDecrease != null)
{
strAutomationName = AutomationProperties.GetName(m_tpElementVerticalSmallDecrease);

if (strAutomationName == null)
if (strAutomationName == null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_VERTICALSMALLDECREASE, strAutomationName));
AutomationProperties.SetName(m_tpElementVerticalSmallDecrease, strAutomationName);

}
}
spElementVerticalThumb = GetTemplateChildHelper<Thumb>("VerticalThumb");
m_tpElementVerticalThumb = spElementVerticalThumb;
if (m_tpElementVerticalThumb != null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_VERTICALTHUMB, strAutomationName));
AutomationProperties.SetName(m_tpElementVerticalThumb as Thumb, strAutomationName);
strAutomationName = AutomationProperties.GetName(m_tpElementVerticalThumb);

if (strAutomationName == null)
{
// (DXamlCore.GetCurrentNoCreate().GetLocalizedResourceString(UIA_SCROLLBAR_VERTICALTHUMB, strAutomationName));
AutomationProperties.SetName(m_tpElementVerticalThumb as Thumb, strAutomationName);

}
}
}

spElementHorizontalPanningRoot = GetTemplateChildHelper<FrameworkElement>("HorizontalPanningRoot");
m_tpElementHorizontalPanningRoot = spElementHorizontalPanningRoot;
spElementHorizontalPanningThumb = GetTemplateChildHelper<FrameworkElement>("HorizontalPanningThumb");
m_tpElementHorizontalPanningThumb = spElementHorizontalPanningThumb;
spElementVerticalPanningRoot = GetTemplateChildHelper<FrameworkElement>("VerticalPanningRoot");
m_tpElementVerticalPanningRoot = spElementVerticalPanningRoot;
spElementVerticalPanningThumb = GetTemplateChildHelper<FrameworkElement>("VerticalPanningThumb");
m_tpElementVerticalPanningThumb = spElementVerticalPanningThumb;
spElementHorizontalPanningRoot = GetTemplateChildHelper<FrameworkElement>("HorizontalPanningRoot");
m_tpElementHorizontalPanningRoot = spElementHorizontalPanningRoot;
spElementHorizontalPanningThumb = GetTemplateChildHelper<FrameworkElement>("HorizontalPanningThumb");
m_tpElementHorizontalPanningThumb = spElementHorizontalPanningThumb;
spElementVerticalPanningRoot = GetTemplateChildHelper<FrameworkElement>("VerticalPanningRoot");
m_tpElementVerticalPanningRoot = spElementVerticalPanningRoot;
spElementVerticalPanningThumb = GetTemplateChildHelper<FrameworkElement>("VerticalPanningThumb");
m_tpElementVerticalPanningThumb = spElementVerticalPanningThumb;
}

// Attach the event handlers
AttachEvents();
Expand Down
Loading

0 comments on commit 08eacc5

Please sign in to comment.