Android InputEvent

If I do this :

var tf = _ve.Q<TextField>();
tf.RegisterCallback<InputEvent>(OnType);

 private void OnType(InputEvent evt)
 {
    var tf = (TextField) evt.target;
    tf.value = tf.value+"-";
 }

It works as expected on PC (adds a hyphen whenever I type something)
But on android it behaves weirdly. If I type a letter, the letter doesn’t appear. Then the field is slowly filled with hyphens.
Is there a way on android to use the textfield value inside the OnType function? All my attempts failed.

Hi @vejab , thank you for bringing this up! Upon reviewing the code, there is currently no workaround with the existing soft keyboard implementation. We will be addressing this and releasing a solution along with our other soft keyboard improvements.

For this scenario, have you looked into using ChangeEvent along with SetValueWithoutNotify()? Looking at the code snippet, the OnType method will always keep firing as the InputEvent is being continuously emitted since the value is being updated (and it sees that it’s different than the previous OnType call) within the OnType callback. With ChangeEvent, when you paired it with SetValueWithoutNotify(), it will only emit the specific value change once. FYI, if you are using ChangeEvent with SetValueWithoutNotify() at this moment, there is a bug where the value in the TextField is not synced with the OS’s soft keyboard input field. You will find that you have to close and re-open it in order for the values to sync. This bug will be fixed and delivered with our soft keyboard improvements.

Thanks. I made it work by having a different OnType method for android and PC since they behave differently. In my case, for android, I had to simulate the player typing all the characters one by one like this

var s = "";
foreach (var newchar in evt.newData) {
    s = ApplyFunction(s + newchar);
}

I’m looking forward the soft keyboard improvements :slight_smile:

1 Like