Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Dynamically changing editor height to accommodate multiple lines of text as needed

$
0
0

I want my editor to behave like the iOS messages app: at first it's just a single line, but as you type enough to add another line, the editor expands and its Y coordinate moves up (so that it doesn't fall offscreen). I read https://forums.xamarin.com/discussion/99124/how-to-show-multiple-lines-in-an-editor and it almost works. The biggest issue I have right now though is that the vertical centering gets screwed up. Here's what happens:
1. Initial startup, editor is sized correctly for a single line
2. Type enough to form a second line. The editor does correctly increase its height, however, now the vertical centering is screwed up. Text is top aligned.
3. Keep typing enough to add a 3rd line. As expected, height correctly changes, but now the text is correctly center aligned vertically
4. Keep typing enough to add a 4th line. Vertical centering screws up as in #2. The pattern keeps repeating: we keep alternating between correctly aligned (center) and top.

Attached are images for states 1, 2, 3 for a more illustrative example.
The code is very simple (as that link shows): the custom editor just simply does InvalidateMeasure when the text changes.

Once I get past that issue, my second issue is that I don't know how to make its Y coordinate adjust upward. In my test I made a grid with 2 rows 1 column (as that link suggested sticking your custom editor in an autosizing grid row). First/top row is a box view which I set a HeightRequest to 500. Second/bottom row is the editor which I didn't set any height values for. In reality the box view will be replaced with a different view, like a list or something, but box seemed easiest to test with. Anyway, the desired behavior is the same as the iOS message app: instead of the text box height expanding downward, the Y coordinate moves up and the height expands, so that the net effect is the box just grows taller (upward) and not downward. I would be OK with either the editor expanding upward and partially obscuring the contents above it, or with the layout adjusting both items so that the height of the upper row shrinks as the height of the lower (editor containing) one expands. Either works just as well.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>