I need to implement dynamic height of textarea that expects a user to type comment. I have seen the interaction of textArea like this on WhatsApp. The text area will be initially of 1 line height later on as the user enters the text it should increase. But the text area should not be increased more than 3 line height.
Asked
Active
Viewed 698 times
2 Answers
2
As of now, I used a workaround to achieve that.
var _lines = textFieldValue.split(/\r\n|\r|\n/).length;
if(_lines > 3 || textFieldValue.length > 90) {
$.textAreaDescriptionId.height = "80dp";
} else {
$.textAreaDescriptionId.height = Titanium.UI.SIZE;
}

mukesh.kumar
- 1,100
- 16
- 30
0
I would use something like this:
$.textArea.height = $.textArea.font.fontSize * 3 // plus some padding
Add a padding because otherwise it will be too small. The fontSize * 3 is the minimum you should have for 3 lines.
Edit
As mentioned in the comments. There is currently no way to set maxLines for a TextField in Titanium. So it won't work dynamically.
Ticket and PR to include this feature:

miga
- 3,997
- 13
- 45
-
I think he's asking to set a dynamic height like the field should look like a single-line field initially, and as the user continues to type in, it should expand to 3 lines tall automatically. Not sure any easy way to do this without having **maxLines** property for TextArea – Prashant Saini Mar 11 '18 at 10:19
-
Ah, I see. You are right, there is currently no option for a TextField to set maxLines. I'll set up a PR! – miga Mar 11 '18 at 12:21
-
The only way at present is if we wrap a **TextArea** with **width=SIZE** & **top/bottom=0** inside a View of fixed height of 3 lines tall. It will certainly create a resizable TextArea with just a limitation that other UI elements will have to consider the height of this TextArea's parent View. – Prashant Saini Mar 11 '18 at 18:37
-
Thanks, @PrashantSaini for your suggestions. I do not want to limit the number of characters in the text field. I just want to limit the height, the user should still be able to enter text. – mukesh.kumar Mar 12 '18 at 09:53