Skip to content

Commit

Permalink
feat(textbox): start skia-based TextBox implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed Nov 7, 2023
1 parent 93f6b63 commit bc7d426
Show file tree
Hide file tree
Showing 6 changed files with 595 additions and 25 deletions.
6 changes: 6 additions & 0 deletions src/Uno.UI/FeatureConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,12 @@ public static class TextBox
/// <remarks>This feature is used to avoid screenshot comparisons false positives</remarks>
public static bool HideCaret { get; set; }

/// <summary>
/// Determines if a native (Gtk/Wpf) TextBox overlay should be used on the skia targets instead of the
/// Uno skia-based TextBox implementation.
/// </summary>
public static bool UseOverlayOnSkia { get; set; } = false;

#if __ANDROID__
/// <summary>
/// The legacy <see cref="Windows.UI.Xaml.Controls.TextBox.InputScope"/> prevents invalid input on hardware keyboard.
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ internal override void OnPropertyChanged2(DependencyPropertyChangedEventArgs arg
private Hyperlink? FindHyperlinkAt(Point point)
{
var padding = Padding;
var span = Inlines.GetRenderSegmentSpanAt(point - new Point(padding.Left, padding.Top), false);
var span = Inlines.GetRenderSegmentSpanAt(point - new Point(padding.Left, padding.Top), false)?.span;

if (span == null)
{
Expand Down
41 changes: 36 additions & 5 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Uno.UI.Helpers;
using Uno.UI.Xaml.Media;
using Windows.ApplicationModel.DataTransfer;
using Uno.UI;

#if HAS_UNO_WINUI
using Microsoft.UI.Input;
Expand Down Expand Up @@ -116,6 +117,10 @@ public TextBox()

DefaultStyleKey = typeof(TextBox);
SizeChanged += OnSizeChanged;

#if __SKIA__
_timer.Tick += TimerOnTick;
#endif
}

private protected override void OnLoaded()
Expand Down Expand Up @@ -150,10 +155,15 @@ private protected override void OnLoaded()
// 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
#if __SKIA__
if (FeatureConfiguration.TextBox.UseOverlayOnSkia)
#endif
{
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
}
}
Expand Down Expand Up @@ -896,6 +906,14 @@ private void OnFocusStateChanged(FocusState oldValue, FocusState newValue, bool
}

UpdateVisualState();
#if __SKIA__
if (!FeatureConfiguration.TextBox.UseOverlayOnSkia)
{
// this is needed so that we UpdateScrolling after the button appears.
UpdateLayout();
UpdateScrolling();
}
#endif
}

partial void OnFocusStateChangedPartial(FocusState focusState);
Expand Down Expand Up @@ -946,8 +964,12 @@ protected override void OnPointerPressed(PointerRoutedEventArgs args)
}

args.Handled = true;

OnPointerPressedNative(args);
}

partial void OnPointerPressedNative(PointerRoutedEventArgs e);

/// <inheritdoc />
protected override void OnPointerReleased(PointerRoutedEventArgs args)
{
Expand All @@ -971,7 +993,16 @@ protected override void OnTapped(TappedRoutedEventArgs e)
partial void OnTappedPartial();

/// <inheritdoc />
protected override void OnKeyDown(KeyRoutedEventArgs args)
protected override void OnKeyDown(KeyRoutedEventArgs args) => OnKeyDownPartial(args);

private partial void OnKeyDownPartial(KeyRoutedEventArgs args);

#if !__SKIA__
private partial void OnKeyDownPartial(KeyRoutedEventArgs args) => OnKeyDownInternal(args);

#endif

private void OnKeyDownInternal(KeyRoutedEventArgs args)
{
base.OnKeyDown(args);

Expand Down
Loading

0 comments on commit bc7d426

Please sign in to comment.