A game framework written with osu! in mind.
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2// See the LICENCE file in the repository root for full licence text.
3
4using System;
5using Foundation;
6using osu.Framework.Input;
7
8namespace osu.Framework.iOS.Input
9{
10 public class IOSTextInput : ITextInputSource
11 {
12 private readonly IOSGameView view;
13
14 private string pending = string.Empty;
15
16 public IOSTextInput(IOSGameView view)
17 {
18 this.view = view;
19 }
20
21 public bool ImeActive => false;
22
23 public string GetPendingText()
24 {
25 try
26 {
27 return pending;
28 }
29 finally
30 {
31 pending = string.Empty;
32 }
33 }
34
35 private void handleShouldChangeCharacters(NSRange range, string text)
36 {
37 if (text == " " || text.Trim().Length > 0)
38 pending += text;
39 }
40
41 public void Deactivate()
42 {
43 view.KeyboardTextField.HandleShouldChangeCharacters -= handleShouldChangeCharacters;
44 view.KeyboardTextField.UpdateFirstResponder(false);
45 }
46
47 public void Activate()
48 {
49 view.KeyboardTextField.HandleShouldChangeCharacters += handleShouldChangeCharacters;
50 view.KeyboardTextField.UpdateFirstResponder(true);
51 }
52
53 public void EnsureActivated()
54 {
55 /// If the user has manually closed the keyboard, it will not be shown until another <see cref="Framework.Graphics.UserInterface.TextBox"/>
56 /// is focused. Calling <see cref="IOSGameView.HiddenTextField.UpdateFirstResponder"/> over and over again won't work, due to how
57 /// `responderSemaphore` currently works.
58
59 // TODO: add iOS implementation
60 }
61
62 public event Action<string> OnNewImeComposition
63 {
64 add { }
65 remove { }
66 }
67
68 public event Action<string> OnNewImeResult
69 {
70 add { }
71 remove { }
72 }
73 }
74}