mopsicus / umi

Unity mobile input (UMI) plugin for Android and iOS, allows to use features of mobile native input fields
MIT License
399 stars 92 forks source link

InputField init's with a weird empty character. #57

Closed Jared-Gross closed 3 years ago

Jared-Gross commented 3 years ago

This a complicated issue to explain. Here are images. https://imgur.com/a/YjlMA5G

So what happens is this: I start the app, and I try and search for something, but it tells me that I must type at least 2 letters. They way my searching is setup starts with at least 2 letters, if it only shows one letter, that message shows. (That back button should also not be there on the first image) Removing the MobileInputField removes the weird character from startup.

How do I reset it? Selecting the InputField and pressing backspace once, then everything works as expected perfectly! But this issue is for ever single InputField in my project.

Not sure if I explained this well, but that's sorta all there is.

Here is what I've tried. I tried looping over each InputField and clearing the text:

foreach (GameObject go in inputFieldsWithMobileScript) {
  go.SetActive (true);
  go.GetComponent<TMP_InputField> ().text = "";
  go.GetComponent<MobileInputField> ().Text = "";
}

This looked like it would work, but, this did not work, the weird character is still there.

I was wondering if I would change this line to equal an empty string instead of value

I'm stumped with this issue, please help.

mopsicus commented 3 years ago

I guess it could be cuz you setup align for your TMP input field. Try to refactor InitProcess method like that: https://pastebin.com/aU3dsxcv

Jared-Gross commented 3 years ago

I get an error when I add that to InitializeOnNextFrame() Assets\Scripts\UnityMobileInput\MobileInputField.cs(298,33): error CS0103: The name 'UnicodeCategory' does not exist in the current context

It's set up as an IEnumerator Yours is setup as a void.

EDIT

Here is how the function looks on my end.

/// <summary>
/// Initialization coroutine
/// </summary>
private IEnumerator InitialzieOnNextFrame () {
    // yield return null;
    //             this.PrepareNativeEdit ();
    // #if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
    //             this.CreateNativeEdit ();
    //             this.SetTextNative (this._inputObjectText.text);
    //             _inputObject.placeholder.gameObject.SetActive (false);
    //             _inputObject.enabled = false;
    //             _inputObjectText.enabled = false;
    // #endif
    yield return null;
    this.PrepareNativeEdit ();
#if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
    this.CreateNativeEdit ();
    string data = this._inputObjectText.text.Trim ();
    if (data.Length == 1) {
        UnicodeCategory category = Char.GetUnicodeCategory (data[0]);
        if (category != UnicodeCategory.Format) {
            this.SetTextNative (this._inputObjectText.text);
        }
    }
    _inputObject.placeholder.gameObject.SetActive (false);
    _inputObject.enabled = false;
    _inputObjectText.enabled = false;
#endif
}
mopsicus commented 3 years ago

Did you add namespaces System.Globalization and System?

Jared-Gross commented 3 years ago

Works fantastic!

For future viewers summary.

Change the InitialzieOnNextFrame () in MobileInputField.cs from:

/// <summary>
/// Initialization coroutine
/// </summary>
private IEnumerator InitialzieOnNextFrame () {
    yield return null;
    this.PrepareNativeEdit ();
#if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
    this.CreateNativeEdit ();
    this.SetTextNative (this._inputObjectText.text);
    _inputObject.placeholder.gameObject.SetActive (false);
    _inputObject.enabled = false;
    _inputObjectText.enabled = false;
#endif
}

To:

/// <summary>
/// Initialization coroutine
/// </summary>
private IEnumerator InitialzieOnNextFrame () {
      yield return null;
      this.PrepareNativeEdit ();
#if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR
      this.CreateNativeEdit ();
      string data = this._inputObjectText.text.Trim ();
      if (data.Length == 1) {
          UnicodeCategory category = Char.GetUnicodeCategory (data[0]);
          if (category != UnicodeCategory.Format) {
              this.SetTextNative (this._inputObjectText.text);
          }
      }
      _inputObject.placeholder.gameObject.SetActive (false);
      _inputObject.enabled = false;
      _inputObjectText.enabled = false;
#endif
}

Don't forget to add using System.Globalization; and using System; at the top of the script.