I am having a problem regarding the keyboard on iOS. I am developing a chat page on Xamarin, cross platform, and this page has a scrollView which make possible to the user to scroll along the messages.
There is a commom problem regarding the keyboard on iOS, where it covers the entry. iOS doesn't scroll up the page automatically. To solve this problem, a simple solution is to put a tag "Scrollview" covering the whole code of the page. This usually works fine. However, my page already has a scrollview inside it. Therefore, when I put a scrollview inside another scrollview, the behaviour is a little crazy, even on Android. Sometimes it scrolls the "messages view", sometimes it scrolls the whole page.
There is a solution to avoid the keyboard problem on iOS not using the scrollview tag? Or there is a solution to use a scrollview inside another scrollview?
Any suggestions?
Thank you in advance!
One way you can deal with this is a custom page renderer that scrolls the whole page up when the keyboard appears.
Here is some sample code to do this. I assume you would only want to do this on pages that have that need it, so first in the Forms PCL (Portable Class Library) project create an empty subclass of
ContentPage
e.g. calledKeyboardInputContentPage
(or whatever you like):Then you inherit from the
KeyboardInputContentPage
for the actual page(s) that you need this functionality, in my test I called itTestKeyboardInputContentPage
:And the custom page renderer code. This goes in the iOS app project:
Since this renderer actually scrolls the entire native page up and back down when the keyboard shows and hides, it should not matter how you layout the page in the Forms Xaml. All that matters is that your Forms page inherits from
KeyboardInputContentPage
.I hope this helps!
I encountered the same problem while trying to implement a chat feature in our app. A solution is to use a custom renderer for the
Entry
, and adjust its margin when the keyboard event is triggered. I followed the pattern set in this post.In this case, I embed my
Entry
into aContentView
, so I inherit from aViewRenderer
to adjust theContentView
. Depending on the situation, the Renderer you inherit from may vary. However, in most cases you should be able to reset the margin to the Keyboard's height.For iOS you can use this Plugin (add to your iOS project): https://github.com/paulpatarinski/Xamarin.Forms.Plugins/tree/master/KeyboardOverlap
For Android add following string in MainActivity after LoadApplication(new App());