Browse Source

use seperate responder class

pull/8963/head
Dan Walmsley 4 years ago
parent
commit
133a95973a
  1. 130
      src/iOS/Avalonia.iOS/AvaloniaView.Text.cs
  2. 135
      src/iOS/Avalonia.iOS/AvaloniaView.cs

130
src/iOS/Avalonia.iOS/AvaloniaView.Text.cs

@ -15,7 +15,7 @@ namespace Avalonia.iOS;
[Adopts("UITextInput")]
[Adopts("UITextInputTraits")]
[Adopts("UIKeyInput")]
public partial class AvaloniaView : ITextInputMethodImpl, IUITextInput
public class AvaloniaResponder : UIResponder, IUITextInput
{
private class AvaloniaTextRange : UITextRange
{
@ -46,6 +46,23 @@ public partial class AvaloniaView : ITextInputMethodImpl, IUITextInput
//[Export("inputDelegate")]
//public UITextInputDelegate InputDelegate { get; set; }
[Export("foo")]
public void Foo()
{
}
}
public AvaloniaResponder()
{
_tokenizer = new UITextInputStringTokenizer(this);
}
public override bool CanPerform(Selector action, NSObject? withSender)
{
return base.CanPerform(action, withSender);
}
private string _markedText = "";
@ -62,27 +79,13 @@ public partial class AvaloniaView : ITextInputMethodImpl, IUITextInput
public override bool CanBecomeFirstResponder => true;
void ITextInputMethodImpl.SetClient(ITextInputMethodClient? client)
{
if (_client != null)
{
_client.CursorRectangleChanged -= ClientOnCursorRectangleChanged;
}
_client = client;
public override UIEditingInteractionConfiguration EditingInteractionConfiguration =>
UIEditingInteractionConfiguration.Default;
public override NSString TextInputContextIdentifier => new NSString("Test");
public override UITextInputMode TextInputMode => UITextInputMode.CurrentInputMode;
if (_client is { })
{
_client.CursorRectangleChanged += ClientOnCursorRectangleChanged;
_client.SurroundingTextChanged += ClientOnSurroundingTextChanged;
BecomeFirstResponder();
}
else
{
ResignFirstResponder();
}
}
[DllImport("/usr/lib/libobjc.dylib")]
extern static void objc_msgSend(IntPtr receiver, IntPtr selector, IntPtr arg);
@ -103,79 +106,6 @@ public partial class AvaloniaView : ITextInputMethodImpl, IUITextInput
objc_msgSend(WeakInputDelegate.Handle.Handle, TextDidChange, Handle.Handle);
}
void ITextInputMethodImpl.SetCursorRect(Rect rect)
{
// maybe this will be cursor / selection rect?
}
void ITextInputMethodImpl.SetOptions(TextInputOptions options)
{
IsSecureEntry = false;
switch (options.ContentType)
{
case TextInputContentType.Normal:
KeyboardType = UIKeyboardType.Default;
break;
case TextInputContentType.Alpha:
KeyboardType = UIKeyboardType.AsciiCapable;
break;
case TextInputContentType.Digits:
KeyboardType = UIKeyboardType.PhonePad;
break;
case TextInputContentType.Pin:
KeyboardType = UIKeyboardType.NumberPad;
IsSecureEntry = true;
break;
case TextInputContentType.Number:
KeyboardType = UIKeyboardType.PhonePad;
break;
case TextInputContentType.Email:
KeyboardType = UIKeyboardType.EmailAddress;
break;
case TextInputContentType.Url:
KeyboardType = UIKeyboardType.Url;
break;
case TextInputContentType.Name:
KeyboardType = UIKeyboardType.NamePhonePad;
break;
case TextInputContentType.Password:
KeyboardType = UIKeyboardType.Default;
IsSecureEntry = true;
break;
case TextInputContentType.Social:
KeyboardType = UIKeyboardType.Twitter;
break;
case TextInputContentType.Search:
KeyboardType = UIKeyboardType.WebSearch;
break;
}
if (options.IsSensitive)
{
IsSecureEntry = true;
}
ReturnKeyType = (UIReturnKeyType)options.ReturnKeyType;
AutocorrectionType = UITextAutocorrectionType.Yes;
}
void ITextInputMethodImpl.Reset()
{
ResignFirstResponder();
}
// Traits (Optional)
[Export("autocapitalizationType")] public UITextAutocapitalizationType AutocapitalizationType { get; private set; }
@ -233,8 +163,8 @@ public partial class AvaloniaView : ITextInputMethodImpl, IUITextInput
// TODO replace this with _client.SetCommitText?
if (KeyboardDevice.Instance is { })
{
_topLevelImpl.Input?.Invoke(new RawTextInputEventArgs(KeyboardDevice.Instance,
0, InputRoot, text));
/*_topLevelImpl.Input?.Invoke(new RawTextInputEventArgs(KeyboardDevice.Instance,
0, InputRoot, text));*/
}
}
@ -243,11 +173,11 @@ public partial class AvaloniaView : ITextInputMethodImpl, IUITextInput
if (KeyboardDevice.Instance is { })
{
// TODO: pass this through IME infrastructure instead of emulating a backspace press
_topLevelImpl.Input?.Invoke(new RawKeyEventArgs(KeyboardDevice.Instance,
/*_topLevelImpl.Input?.Invoke(new RawKeyEventArgs(KeyboardDevice.Instance,
0, InputRoot, RawKeyEventType.KeyDown, Key.Back, RawInputModifiers.None));
_topLevelImpl.Input?.Invoke(new RawKeyEventArgs(KeyboardDevice.Instance,
0, InputRoot, RawKeyEventType.KeyUp, Key.Back, RawInputModifiers.None));
0, InputRoot, RawKeyEventType.KeyUp, Key.Back, RawInputModifiers.None));*/
}
}
@ -279,8 +209,8 @@ public partial class AvaloniaView : ITextInputMethodImpl, IUITextInput
// todo _client.SetCommitText(text);
if (KeyboardDevice.Instance is { })
{
_topLevelImpl.Input?.Invoke(new RawTextInputEventArgs(KeyboardDevice.Instance,
0, InputRoot, text));
/*_topLevelImpl.Input?.Invoke(new RawTextInputEventArgs(KeyboardDevice.Instance,
0, InputRoot, text));*/
}
}

135
src/iOS/Avalonia.iOS/AvaloniaView.cs

@ -19,38 +19,47 @@ using UIKit;
namespace Avalonia.iOS
{
public partial class AvaloniaView : UIView
public partial class AvaloniaView : UIView, ITextInputMethodImpl
{
internal IInputRoot InputRoot { get; private set; }
private TopLevelImpl _topLevelImpl;
private EmbeddableControlRoot _topLevel;
private TouchHandler _touches;
private ITextInputMethodClient _client;
private bool _isActive;
private AvaloniaResponder _textResponder;
public AvaloniaView()
{
_textResponder = new AvaloniaResponder();
_topLevelImpl = new TopLevelImpl(this);
_touches = new TouchHandler(this, _topLevelImpl);
_topLevel = new EmbeddableControlRoot(_topLevelImpl);
_tokenizer = new UITextInputStringTokenizer(this);
_topLevel.Prepare();
_topLevel.Renderer.Start();
var l = (CAEAGLLayer) Layer;
var l = (CAEAGLLayer)Layer;
l.ContentsScale = UIScreen.MainScreen.Scale;
l.Opaque = true;
l.DrawableProperties = new NSDictionary(
EAGLDrawableProperty.RetainedBacking, false,
EAGLDrawableProperty.ColorFormat, EAGLColorFormat.RGBA8
);
_topLevelImpl.Surfaces = new[] {new EaglLayerSurface(l)};
_topLevelImpl.Surfaces = new[] { new EaglLayerSurface(l) };
MultipleTouchEnabled = true;
AddSubviews(new UIView[] { new UIKit.UIButton(UIButtonType.InfoDark) });
}
internal class TopLevelImpl : ITopLevelImplWithTextInputMethod, ITopLevelImplWithNativeControlHost, ITopLevelImplWithStorageProvider
public override bool CanBecomeFirstResponder => true;
public override bool CanResignFirstResponder => true;
public override UIResponder NextResponder => _textResponder;
internal class TopLevelImpl : ITopLevelImplWithTextInputMethod, ITopLevelImplWithNativeControlHost,
ITopLevelImplWithStorageProvider
{
private readonly AvaloniaView _view;
public AvaloniaView View => _view;
@ -68,7 +77,7 @@ namespace Avalonia.iOS
}
public IRenderer CreateRenderer(IRenderRoot root) => new CompositingRenderer(root, Platform.Compositor);
public void Invalidate(Rect rect)
{
@ -82,7 +91,7 @@ namespace Avalonia.iOS
public Point PointToClient(PixelPoint point) => new Point(point.X, point.Y);
public PixelPoint PointToScreen(Point point) => new PixelPoint((int) point.X, (int) point.Y);
public PixelPoint PointToScreen(Point point) => new PixelPoint((int)point.X, (int)point.Y);
public void SetCursor(ICursorImpl _)
{
@ -121,7 +130,7 @@ namespace Avalonia.iOS
new AcrylicPlatformCompensationLevels();
public ITextInputMethodImpl? TextInputMethod => _view;
public INativeControlHostImpl NativeControlHost { get; }
public INativeControlHostImpl NativeControlHost { get; }
public IStorageProvider StorageProvider { get; }
}
@ -150,5 +159,107 @@ namespace Avalonia.iOS
get => (Control)_topLevel.Content;
set => _topLevel.Content = value;
}
ITextInputMethodClient ITextInputMethodImpl.Client => _client;
bool ITextInputMethodImpl.IsActive => _isActive;
void ITextInputMethodImpl.SetClient(ITextInputMethodClient client)
{
if (_client != null)
{
//_client.CursorRectangleChanged -= ClientOnCursorRectangleChanged;
}
_client = client;
if (_client is { })
{
//_client.CursorRectangleChanged += ClientOnCursorRectangleChanged;
//_client.SurroundingTextChanged += ClientOnSurroundingTextChanged;
_textResponder.BecomeFirstResponder();
var x = _textResponder.IsFirstResponder;
}
else
{
_textResponder.ResignFirstResponder();
}
}
void ITextInputMethodImpl.SetCursorRect(Rect rect)
{
// maybe this will be cursor / selection rect?
}
void ITextInputMethodImpl.SetOptions(TextInputOptions options)
{
/*IsSecureEntry = false;
switch (options.ContentType)
{
case TextInputContentType.Normal:
KeyboardType = UIKeyboardType.Default;
break;
case TextInputContentType.Alpha:
KeyboardType = UIKeyboardType.AsciiCapable;
break;
case TextInputContentType.Digits:
KeyboardType = UIKeyboardType.PhonePad;
break;
case TextInputContentType.Pin:
KeyboardType = UIKeyboardType.NumberPad;
IsSecureEntry = true;
break;
case TextInputContentType.Number:
KeyboardType = UIKeyboardType.PhonePad;
break;
case TextInputContentType.Email:
KeyboardType = UIKeyboardType.EmailAddress;
break;
case TextInputContentType.Url:
KeyboardType = UIKeyboardType.Url;
break;
case TextInputContentType.Name:
KeyboardType = UIKeyboardType.NamePhonePad;
break;
case TextInputContentType.Password:
KeyboardType = UIKeyboardType.Default;
IsSecureEntry = true;
break;
case TextInputContentType.Social:
KeyboardType = UIKeyboardType.Twitter;
break;
case TextInputContentType.Search:
KeyboardType = UIKeyboardType.WebSearch;
break;
}
if (options.IsSensitive)
{
IsSecureEntry = true;
}
ReturnKeyType = (UIReturnKeyType)options.ReturnKeyType;
AutocorrectionType = UITextAutocorrectionType.Yes;
SpellCheckingType = UITextSpellCheckingType.Yes;
KeyboardAppearance = UIKeyboardAppearance.Alert;*/
}
void ITextInputMethodImpl.Reset()
{
_textResponder?.ResignFirstResponder();
}
}
}

Loading…
Cancel
Save