Skip to content

Commit

Permalink
feat: Support for TextBox.Paste and PasswordBox.Paste on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Oct 18, 2023
1 parent 3fc9331 commit aab94da
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/Uno.UI.Runtime.Skia.Gtk/UI/Controls/GtkTextBoxView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ protected GtkTextBoxView()
InputWidget.StyleContext.AddClass(TextBoxViewCssClass);
}

public event TextControlPasteEventHandler? Paste;

/// <summary>
/// Represents the root widget of the input layout.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public bool CanPasteClipboardContent
}
#endif
// Skipping already declared event Windows.UI.Xaml.Controls.PasswordBox.PasswordChanged
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || false || __NETSTD_REFERENCE__ || __MACOS__
#if false || __IOS__ || IS_UNIT_TESTS || __WASM__ || false || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public event global::Windows.UI.Xaml.Controls.TextControlPasteEventHandler Paste
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public void ClearUndoRedoHistory()
#endif
// Skipping already declared event Windows.UI.Xaml.Controls.TextBox.SelectionChanged
// Skipping already declared event Windows.UI.Xaml.Controls.TextBox.TextChanged
#if __ANDROID__ || __IOS__ || IS_UNIT_TESTS || __WASM__ || false || __NETSTD_REFERENCE__ || __MACOS__
#if false || __IOS__ || IS_UNIT_TESTS || __WASM__ || false || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public event global::Windows.UI.Xaml.Controls.TextControlPasteEventHandler Paste
{
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Controls/TextBox/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public partial class TextBox : Control, IFrameworkTemplatePoolAware
public event TypedEventHandler<TextBox, TextBoxTextChangingEventArgs> TextChanging;
public event TypedEventHandler<TextBox, TextBoxBeforeTextChangingEventArgs> BeforeTextChanging;
public event RoutedEventHandler SelectionChanged;
#if __SKIA__
#if __SKIA__ || __ANDROID__
public event TextControlPasteEventHandler Paste;
#endif

Expand Down
28 changes: 15 additions & 13 deletions src/Uno.UI/UI/Xaml/Controls/TextBox/TextBoxView.Android.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
#nullable enable

using System;
using System.Collections.Generic;
using System.Text;
using Android.Widget;
using Uno.UI;
using Uno.UI.Helpers;
using Java.Lang.Reflect;
using Android.Content;
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.OS;
using Android.Runtime;
using Android.Text;
using Android.Views;
using Android.Views.InputMethods;
using Android.Widget;
using AndroidX.Core.Content;
using AndroidX.Core.Graphics;
using Java.Lang.Reflect;
using Uno.Disposables;
using Uno.Extensions;
using Uno.Foundation.Logging;
using Uno.UI;
using Uno.UI.DataBinding;
using Uno.UI.Extensions;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Uno.UI.Xaml.Media;

namespace Windows.UI.Xaml.Controls
{
Expand Down Expand Up @@ -104,6 +91,21 @@ internal void SetTextNative(string text)
}
}

public override bool OnTextContextMenuItem(int id)
{
if (id == Android.Resource.Id.Paste)
{
var args = new TextControlPasteEventArgs();
Owner?.RaisePaste(args);
if (args.Handled)
{
return true;
}
}

return base.OnTextContextMenuItem(id);
}

protected override void OnTextChanged(Java.Lang.ICharSequence? text, int start, int lengthBefore, int lengthAfter)
{
if (!_isRunningTextChanged && _isInitialized)
Expand Down

0 comments on commit aab94da

Please sign in to comment.