YousicianGit / UnityNativeEdit

Unity Native Input Plugin for both iOS and Android (Unity UI compatible)
44 stars 13 forks source link

Multi Line Support in Inputfield #39

Open ATHellboy opened 7 years ago

ATHellboy commented 7 years ago

Hey,

Is this modified inputField support multi line submit and multi line newline ?

I've checked these items and unfortunately just support single line ?

Any suggestion to fix this issue ?

I've had RTL languages problem in Unity and this package solve my problem. I've test many packages and codes but all of them have problem in some situation.

Many thanks, Alireza

Hemaolle commented 7 years ago

Hi ATHellboy!

The original plugin where we forked from had some support for multiline text fields but we haven't been using those ourselves so yeah it's likely that there are some bugs (and we might even have broken more things with those with our changes).

I think the multiline code is still in the project so you could try to fix issues yourself, that might be the quickest route.

We're not planning to use multiline fields ourselves, so we're likely not looking into that in the near future.

I might investigate it on my free time at some point, but I'm not making any promises :)

ATHellboy commented 7 years ago

Many thanks Hemalloe

ATHellboy commented 7 years ago

Hey,

The input field is controlled by sending Json file to the plugin ?

I've seen in NativeEditBox which multi line attribute of input field is sent to the plugin like other attributes.

I try to dig in codes and find differences between these codes and original ones and I've not found anything special just one thing that i guess maybe it is important part of multi line feature.

nativeeditbox7

The difference which is in my mind is if (c == '\n') { this.ForceSendKeydown_Android("enter"); } part of code.

Do you have any idea about that ?

Unfortunately I've not tested original code to determine that multi line works or doesn't.

Many thanks

Hemaolle commented 7 years ago

I think this should catch the enter presses the same way, we just thought it was cleaner to compare directly to the character.

Hemaolle commented 7 years ago

Could you describe what kind of problems you have with the multiline input fields?

ATHellboy commented 7 years ago

Multiline doesn't work in input fields.When i choose multiline from combo box in inspector of input field component, It doesn't change anything in android build. It works in editor but not android build. Actually in android build, multiline input fileds are like single ones.

ATHellboy commented 7 years ago

I've checked original code that you fork from it. I don't know why, but the native input field didn't work. Does this native android plugin support multiline ?

ATHellboy commented 7 years ago

Anyone ?

Hemaolle commented 7 years ago

Yeah, I don't know if the original developer then tested the multiline stuff either. I can see that there are some things done differently if a multiline flag is passed to the plugin, but I can't say where the issue lies then. One thing that I think we changed was adding an event for return pressed, but then again if the original version doesn't work either I'm not sure if that was the breaking change.

As said earlier I might investigate the multiline problems at some point in the future, but if you need it in your project and want to use this plugin I recommend trying to investigate the issue yourself. I'm more than happy to integrate a fix if you manage to find one.

ATHellboy commented 7 years ago

Thanks Hemaolle,

I try to investigate about multiline but I asked just because you and other contributes know the codes and plugin more than me.

I've checked the original one but I think i need to recheck it again and I'll let you know for the result.

Hemaolle commented 7 years ago

Yeah, no problem :) Let me know how it goes!

ATHellboy commented 7 years ago

Yup, I've had some mistakes for checking the original one, I've tested it and multiline works very well but until now I didn't find any solution for this version.

ATHellboy commented 7 years ago

How can I disable return key ? I want to comment lines that reference to return key but when I do that the input field doesn't work

I guess maybe it is because of return key, because when I've checked original plugin in the input field we have next line button but in this plugin we don't have it.

screenshot_2017-06-21-03-35-42 .

Hemaolle commented 7 years ago

Not having the return button sounds like a problem in either setting the texfield to multiline (maybe the setting gets reset after it's set by something else we do) or the IME (keyboard) options or similar. I think we maybe added the possibility to have a "Done" or "Next" button on the keyboard so maybe that affects the presence of the return button.

ATHellboy commented 7 years ago

Excuse me for latency.

Yup, I think it is reset by something so I guess maybe it is because of return keys because multiline textfiled need next line button but it doesn't exist.

Default return key returns what kind of return key ? just next and done ? Is there any way to add next line key to the return keys option ?

Many thanks

Hemaolle commented 7 years ago

Not sure if the return key is an option like the "Next" and "Done" keys or if it's just dependent on having a multiline input field.

ATHellboy commented 7 years ago

It's selectable in editor, I'm not sure it depends on type of inputfield, but in original code, it depends. if it is multiline, return key is next line, if it is single, return key is done.

Hemaolle commented 7 years ago

Yeah, I'm not that familiar with Android keyboards that I wold remember by heart how it works :)

ATHellboy commented 7 years ago

Is there any way to disable (comment) some of attributes of EditBoxConfig ? I try to do but the inputfield disables.

Chazzmundo commented 7 years ago

Multiline support is also something I'm very interested in. So far there seems to be 3 caveats which stop this plugin being perfect:

1) The lack of multiline support

2) It no longer detects the user clicking somewhere on screen that is not part of the input field (which should act as a submit action like it normally does)

3) The text renders on top of all other elements

I think I can solve 2) by putting an invisible panel somewhere on screen which detects being pressed and auto sets the focus off of the InputText. Annoying to have to do but a workaround

As for 3, I'm thinking every time the native text isn't in focus, I will swap it out for a standard input field with the same value.

Issue 1) however, would benefit much more from an in-code fix than the other two. I'm going to have a look at this at some point in the next few days but if anyone else solves it, I'd love to see their solution :)

ATHellboy commented 7 years ago

Oh it's so good Chazzmundo.

today I've tried to find difference between native plugin codes of original one and this one.

Now I want to learn how to modify native android codes.

Chazzmundo commented 7 years ago

Hey, so it turns out another user also had the same problem regarding the multiline issue but managed to solve it. I've verified it locally and it works nicely.

Simply go to your InputField script, change the Content Type to "Custom" and ensure the Line Type is "Multi Line Newline". If I get some time in the future, I'll look into why this doesn't work as standard without having to set it to a Custom Content type as well as try and fix the other 2 issues I raised properly.

Source of fix (in the closed issues list ^_^): https://github.com/YousicianGit/UnityNativeEdit/issues/31

ATHellboy commented 7 years ago

Hey guys,

I want to add auto alignment to input field. First I've tried to use this piece of code that I've wrote :

char[] inputFieldString = myText.text.ToCharArray();

        if (string.IsNullOrEmpty(myText.text))
        {
            checkAutoAlignment = true;
        }

        if (checkAutoAlignment)
        {
            if (inputFieldString.Length == 1)
            {
                if (Regex.IsMatch(inputFieldString[0].ToString(), @"^[\u0600-\u06FF\uFB8A\u067E\u0686\u06AF]+$"))
                {
                    myText.alignment = TextAnchor.UpperLeft;
                }
                else
                {
                    myText.alignment = TextAnchor.UpperLeft;
                }
                checkAutoAlignment = false;
            }
        }

It works in editor very well, but doesn't work on android device. I guess it because of plugin that controls all stuffs in inputField.

So I try this code and nothing work yet :

char[] inputFieldString = objUnityText.text.ToCharArray();

        if (string.IsNullOrEmpty(objUnityText.text))
        {
            checkAutoAlignment = true;
        }

        if (checkAutoAlignment)
        {
            if (inputFieldString.Length == 1)
            {
                if (Regex.IsMatch(inputFieldString[0].ToString(), @"^[\u0600-\u06FF\uFB8A\u067E\u0686\u06AF]+$"))
                {
                    mConfig.align = TextAnchor.UpperRight.ToString();
                }
                else
                {
                    mConfig.align = TextAnchor.UpperLeft.ToString();
                }

                JsonObject jsonMsg = new JsonObject();

                Debug.Log(mConfig.align);

                jsonMsg["align"] = mConfig.align;

                this.SendPluginMsg(jsonMsg);

                checkAutoAlignment = false;
            }
        }

Determining text anchor works very well, but I think it doesn't send to the plugin, because nothing changed in inputField.

Is there any problem for sending ?

Do you have any idea how to create auto alignment according to RTL or LTR language ?

ATHellboy commented 7 years ago

I've fixed auto align and multiline for all kind of content type.

Now my problem is cursor (caret), It doesn't appear on input field.

Any idea ?

Fix for multiline:

          //Move from inside "Custom" content type to  here
            if (multiline) editInputType  |=  InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;

Fix for auto align:

int gravity = 0;

        switch (alignment) {
            case "UpperLeft":
            case "UpperCenter":
            case "UpperRight":
                gravity = Gravity.TOP;
                break;
            case "MiddleLeft":
            case "MiddleCenter":
            case "MiddleRight":
                gravity = Gravity.CENTER_VERTICAL;
                break;
            case "LowerLeft":
            case "LowerCenter":
            case "LowerRight":
                gravity = Gravity.BOTTOM;
                break;
        }

        edit.setGravity(gravity);
Hemaolle commented 7 years ago

Looks great! Perhaps you could make a fork of the repository and then you could make a pull request for the multiline fix to incorporate it in our version?

Not sure what could be the problem with the caret :/ Is it broken always or only with multiline?

ATHellboy commented 7 years ago

Yes, of course.

It is broken always. I've not found problem yet.