From c2cd4e649ae7f37dfda6b13ab839bb621a2342f4 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Mon, 6 Nov 2023 12:30:05 +0200 Subject: [PATCH] chore: Adjust for more clear git diff --- .../UI/Xaml/Controls/TextBox/TextBox.cs | 80 +++++++++---------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs b/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs index d5f84e0f9bda..8b0c7bc464bd 100644 --- a/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs +++ b/src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs @@ -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) @@ -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