Did you verify this is a real problem by searching [Stack Overflow]
Yes.
Tell us about the problem
In my nativescript-angular project, I have a TextField control as follows:
<TextField
hint="Password"
[secure]="!isPasswordVisible">
</TextField>
Now, when we change isPasswordVisible value programmatically, it works great on iOS. But on android it always resets the cursor position to the first character.
I tried to find the root cause of the issue and found that whenever setInputType is called, android will reset the cursor position to the first character.
I checked the code of text-field.android.js and the issue is we are calling setInputType but we are not setting the cursor to its original position. This results in cursor resets to first character. So just getting the cursor position before calling setInputType and setting that cursor position after calling setInputType will solve this issue as shown below.
text-field.android.js
function onSecurePropertyChanged(data) {
var textField = data.object;
...
var cursor = textField.android.getSelectionStart();
...
textField.android.setInputType(newInputType);
textField.android.setSelection(cursor);
}
Edit
I also noted that currently when secure is set to false, the input type is being set to TYPE_TEXT_VARIATION_NORMAL. This opens a different soft keyboard than that is visible when secure is true. So it will be great if we can have some provision so that when password is visible (secure is false), the inputType is set to TYPE_TEXT_VARIATION_VISIBLE_PASSWORD instead of TYPE_TEXT_VARIATION_NORMAL. This will keep the soft keyboard same irrespective of whether password is visible or not.
Which platform(s) does your issue occur on?
Android
Please provide the following version numbers that your issue occurs with:
- CLI: 2.4.0
- Cross-platform modules: 2.4.0
- Runtime(s): 2.4.1
Let me know if you want me to create a PR for this.
Did you verify this is a real problem by searching [Stack Overflow]
Yes.
Tell us about the problem
In my nativescript-angular project, I have a
TextFieldcontrol as follows:Now, when we change
isPasswordVisiblevalue programmatically, it works great on iOS. But on android it always resets the cursor position to the first character.I tried to find the root cause of the issue and found that whenever
setInputTypeis called, android will reset the cursor position to the first character.I checked the code of
text-field.android.jsand the issue is we are callingsetInputTypebut we are not setting the cursor to its original position. This results in cursor resets to first character. So just getting the cursor position before callingsetInputTypeand setting that cursor position after callingsetInputTypewill solve this issue as shown below.text-field.android.jsEdit
I also noted that currently when
secureis set to false, the input type is being set toTYPE_TEXT_VARIATION_NORMAL. This opens a different soft keyboard than that is visible whensecureis true. So it will be great if we can have some provision so that when password is visible (secureis false), the inputType is set toTYPE_TEXT_VARIATION_VISIBLE_PASSWORDinstead ofTYPE_TEXT_VARIATION_NORMAL. This will keep the soft keyboard same irrespective of whether password is visible or not.Which platform(s) does your issue occur on?
Android
Please provide the following version numbers that your issue occurs with:
Let me know if you want me to create a PR for this.