jamesmontemagno / app-monkeychat

Monkey Chat application feature Twilio IP Messaging
110 stars 52 forks source link

How to enter text if the entry doesn't scroll up? #1

Open FrancoisM opened 8 years ago

FrancoisM commented 8 years ago

The entry doesn't scroll up when the keyboard appears (at least on ios simulator). I guess the view should be within a sroll view.

amalsher commented 7 years ago

@FrancoisM just use this plugin, it will solve the issue: https://www.nuget.org/packages/Xam.Plugins.Forms.KeyboardOverlap/

FrancoisM commented 7 years ago

Tks but as you can imagine after 8 months I already implemented a solution ;-)

amalsher commented 7 years ago

It might help others

mjrichards91 commented 7 years ago

@FrancoisM What was the solution you implemented? I've tried the plugin but has some mixed results.

FrancoisM commented 7 years ago

@mjrichards91 Add the Entry at the End of a vertical StackLayout which itself goes into a ScrollView.

mjrichards91 commented 7 years ago

@FrancoisM So you put the ListView and the StackLayout/Entry within the ScrollView?

FrancoisM commented 7 years ago

Here is some pseudo code. I forgot the details of why I had to do so but I use an absolutelayout whose height varies. Don't forget to put your send button somewhere lol. I actually also use an editor rather than an entry which I invalidate on TextChanged so it can grow in size when entering more text.

var scroll= new ScrollView 
{
    Content = new StackLayout 
    {
        Children = {
            new BoxView { VerticalOptions = Start, HeightRequest = listHeight}, //some fake space
            new Entry { VerticalOptions = End }
       }
    }
}

var abs = new AbsoluteLayout();
var list = new Listiew();
abs.Chidren.Add(scroll);
abs.Children.Add(list, new Rectangle(0, 0, someWidth, listHeight));

scrollView.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName != ScrollView.ScrollYProperty.PropertyName) return;
                var initialHeight = listHeight;
                var scrollHeight = scrollView.ScrollY;
                var newHeight = initialHeight - scrollHeight;{newHeight}");
                AbsoluteLayout.SetLayoutBounds(list, new Rectangle(messagesList.X, messagesList.Y, messagesList.Width, newHeight));
                list.ScrollToBottom(false);
            };

Content =abs;