Skip to content

Commit

Permalink
fix: Adjust TextBox ScrollViewer workaround for Material TextBox to w…
Browse files Browse the repository at this point in the history
…rap properly
  • Loading branch information
Youssef1313 committed Nov 6, 2023
1 parent 8186a16 commit 954b367
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
6 changes: 0 additions & 6 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ private protected override void OnUnloaded()
}
}

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

partial void InitializePropertiesPartial()
{
OnImeOptionsChanged(ImeOptions);
Expand Down
31 changes: 22 additions & 9 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,28 @@ protected override void OnApplyTemplate()
_contentElement = GetTemplateChild(TextBoxConstants.ContentElementPartName) as ContentControl;
_header = GetTemplateChild(TextBoxConstants.HeaderContentPartName) as ContentPresenter;

if (GetTemplateChild(TextBoxConstants.DeleteButtonPartName) is Button button)
{
_deleteButton = new WeakReference<Button>(button);
}

UpdateTextBoxView();
InitializeProperties();
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__
Expand All @@ -195,15 +217,6 @@ protected override void OnApplyTemplate()
scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; // The template sets this to Hidden
#endif
}

if (GetTemplateChild(TextBoxConstants.DeleteButtonPartName) is Button button)
{
_deleteButton = new WeakReference<Button>(button);
}

UpdateTextBoxView();
InitializeProperties();
UpdateVisualState();
}

partial void InitializePropertiesPartial();
Expand Down

0 comments on commit 954b367

Please sign in to comment.