Using Xamarin Forms, consider the Xaml below.
<StackLayout VerticalOptions="FillAndExpand">
<Image x:Name="cameraImage" Source="camera.png" />
<Label Text="Describe the image" />
<Editor />
<Button Text="Save" />
</StackLayout>
This renders an image, an editor and a save button. The image is in 4x3 image ratio and covers about a third of the available screen height. The editor is rendered below.
The problem is that the keyboard covers the Editor in iOS. A standard iOS issue normally.
The question is: What is the Xamarin Forms way of handling this?
Thanks
// Johan
Expanding on the answer from @Falko, you can check the platform for iOS since Android handles this as expected natively.
I also added this to the page for quick and dirty orientation via this answer.
Anyway, I understand that Xamarin are adding some solutions for this soon. For now, though...
Using ScrollView as mentioned above fixes problem in iOS and partially fixes in Android. To fully fix problem in android, I found another simple and nice addition.
Only in android I replace Xamarin forms Editor with android specific TextEdit control. So in my Page constructor I have following code just for android.
You also need to add android specific namespaces as needed.
Sometimes you cannot put your main view in a scrollview, in those cases you can implement this by handling the keyboard events the iOS project and passing them to the Forms level. Android takes care of it's self.
Then at the Forms level:
If you are working in a Stacklayout and wish to raise the view above the keyboard you can put a spacer with a height 0 at the bottom of the stack. Then set it to the height of the keyboard when the keyboard changed event is raised.
If you are working with a Listview you can handle this by translating your view by the amount it would have been overlapped by.
Listviews have to be handled differently as there height is automatically adjusted by Forms and using a spacer results over correction.
Sample here: https://github.com/naturalistic/raisekeyboard
I just stumbled upon this question when writing a tiny chat application, which basically contains a scrollable message list, a text entry and a send button:
The problem with the previously posted solution is that you'd need to nest two scroll views, which is not recommended by the Xamarin.Forms documentation. To prevent the keyboard from hiding the entry, I found the following hack:
I'm adding a
placeholder
at the end of the main stack layout. Depending on whether the entry is focussed (i.e. the keyboard is visible or not) the height of the placeholder is set to 0 or the keyboard height.Of course, this is not perfect. Especially the hard-coded keyboard height should be implemented more elegantly. And probably you should apply it on iOS only, not on Android.
Be careful, the
raisekeyboard
was just implemented for one entry in the application, if you add a new Entry, theKeyboardHelper.KeyboardChanged
is going to shoot, when the focus is in any entry.To get auto scroll for Editors and Entries with Xamarin.Forms, you usually just have to pack your View, in this case the StackLayout, into a ScrollView:
That's how it's supposed to work, but as of today (June 2014) there's a bug preventing this to work fully with the Editor (it works well with Entries). The issue is known and is worked on.
[UPDATE 2014-11-20]The issue has been addressed, and will be available in the next -pre release of XF 1.3