Skip to content

Commit

Permalink
chore: Adjust for more clear git diff
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Nov 6, 2023
1 parent 398059c commit c2cd4e6
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,46 @@ public TextBox()
SizeChanged += OnSizeChanged;
}

private protected override void OnLoaded()
{
base.OnLoaded();

#if __ANDROID__
SetupTextBoxView();
#endif

// This workaround is added in OnLoaded rather than OnApplyTemplate.
// Apparently, sometimes (e.g, Material style), the TextBox style setters are executed after OnApplyTemplate
// So, the style setters would override what the workaround does.
// OnLoaded appears to be executed after both OnApplyTemplate and after the style setters, making sure the values set here are not modified after.
if (_contentElement is ScrollViewer scrollViewer)
{
#if __IOS__ || __MACOS__
// We disable scrolling because the inner ITextBoxView provides its own scrolling
scrollViewer.HorizontalScrollMode = ScrollMode.Disabled;
scrollViewer.VerticalScrollMode = ScrollMode.Disabled;
scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled;
#else
// The template of TextBox contains the following:
/*
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
*/
// Historically, TemplateBinding for attached DPs wasn't supported, and TextBox worked perfectly fine.
// When support for TemplateBinding for attached DPs was added, TextBox broke (test: TextBox_AutoGrow_Vertically_Wrapping_Test) because of
// change in the values of these properties. The following code serves as a workaround to set the values to what they used to be
// before the support for TemplateBinding for attached DPs.
scrollViewer.HorizontalScrollMode = ScrollMode.Enabled; // The template sets this to Auto
scrollViewer.VerticalScrollMode = ScrollMode.Enabled; // The template sets this to Auto
scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; // The template sets this to Hidden
scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; // The template sets this to Hidden
#endif
}
}

internal bool IsUserModifying => _isInputModifyingText || _isInputClearingText;

private void OnSizeChanged(object sender, SizeChangedEventArgs args)
Expand Down Expand Up @@ -179,46 +219,6 @@ protected override void OnApplyTemplate()
UpdateVisualState();
}

private protected override void OnLoaded()
{
base.OnLoaded();

#if __ANDROID__
SetupTextBoxView();
#endif

// This workaround is added in OnLoaded rather than OnApplyTemplate.
// Apparently, sometimes (e.g, Material style), the TextBox style setters are executed after OnApplyTemplate
// So, the style setters would override what the workaround does.
// OnLoaded appears to be executed after both OnApplyTemplate and after the style setters, making sure the values set here are not modified after.
if (_contentElement is ScrollViewer scrollViewer)
{
#if __IOS__ || __MACOS__
// We disable scrolling because the inner ITextBoxView provides its own scrolling
scrollViewer.HorizontalScrollMode = ScrollMode.Disabled;
scrollViewer.VerticalScrollMode = ScrollMode.Disabled;
scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled;
#else
// The template of TextBox contains the following:
/*
HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
*/
// Historically, TemplateBinding for attached DPs wasn't supported, and TextBox worked perfectly fine.
// When support for TemplateBinding for attached DPs was added, TextBox broke (test: TextBox_AutoGrow_Vertically_Wrapping_Test) because of
// change in the values of these properties. The following code serves as a workaround to set the values to what they used to be
// before the support for TemplateBinding for attached DPs.
scrollViewer.HorizontalScrollMode = ScrollMode.Enabled; // The template sets this to Auto
scrollViewer.VerticalScrollMode = ScrollMode.Enabled; // The template sets this to Auto
scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; // The template sets this to Hidden
scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; // The template sets this to Hidden
#endif
}
}

partial void InitializePropertiesPartial();

#region Text DependencyProperty
Expand Down

0 comments on commit c2cd4e6

Please sign in to comment.