-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WindowSoftInputModeAdjust.Resize and Pan on iOS #10662
Comments
This currently doesn't work if there is a scrollable control on the page such as CollectionView or ScrollView, because items inside those are currently scrolled (or moved?), when the keyboard opens on iOS. I saw there are a bunch of issues regarding this and I think my solution would be a simpler approach that covers more cases and aligns the logic for Android and iOS (not sure about the other platforms). |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
@borrmann
Maybe I can get it working and create a nuget with it. |
@angelru pushing the Entry instead of changing the padding or translation of the parent control is an alternative approach which might be great in many scenarios. If you create a Nuget I recommend checking for the event that gets triggered when the keyboard height changes as well, which f.e. happens on some devices when the Emoji keyboard opens up. Maybe this would also be something interesting for the CommunityToolkit instead a separate nuget @jfversluis ? |
If you have code that works fine on Android/iOS and also with CollectionView/ScrollView etc... please share when you can :) |
@angelru Here is my code. At the moment I only use it in a chat window where the entry is below a collectionview.
|
@borrmann |
Since I´m using dependency injection and have registered some views as Singleton, I changed the code a little bit. |
Many thanks to @borrmann! I was (eventually!) able to come up with a workaround for my app. Here's the code I'm using: https://gist.github.com/greg84/0297569ef1052801a384aae9c75800cd Some comments:
|
Okay so from all this, What is the answer currently? or any updates from MAUI devs team? |
I keep thinking because this is not integrated in MAUI or at least in toolkit. |
#5478 (comment) |
No go on the iOS side. Will follow up if I go this route |
Is there a solution to mirror the behaviour of WindowSoftInputModeAdjust.Resize on iOS using .NET 8? The behaviour I am seeing in my iOS MAUI app is that when the software keyboard opens, the elements in my ContentPage get scrolled up off screen, which is not what I want. I need the window area to resize instead. |
@tomShoutTheSecond #if IOS e.g. when navigating to the page, and should be turned back on when leaving with #if IOS Then, instead of translating your page, you could modify the height of your desired contentview, e.g. by modifying padding/ margin.
|
The bug persists in .NET 8. When encountering an issue with multiple entries inside a ScrollView , consider implementing the following workaround: Firstly, create a new file under
custom ScrollView code:
Usage of the custom scrollView
Credit goes to this guy for putting it together |
@borrmann Where do you call KeyboardAutoManagerScroll.Disconnect();? |
In my project I am calling KeyboardAutoManagerScroll.Disconnect() in MauiProgram.CreateMauiApp() |
I call it in OnNavigatedTo:
and reconnect in OnNavigatedFrom as I only want this in a specific page. I use MAUI 8.0.7. Strange you still get the panning.. Where do you call it? |
I´m calling it at the same place. Maybe it´s because I´m using maui hybrid with blazor this time. |
I'm facing the same issue, that it gets panned up every now and then. The behaviour seems erratic but may be related to previous actions like tapping on a blank space (focus changes). My setup is a web view with an input field inside the web page. Have you already found a solution? |
I've been experimenting with a variety of keyboard workarounds and have noticed that
in its output. Is anybody else seeing this behavior? I tried to get at the value manually but |
var duration = (uint)(args.AnimationDuration * 1000); In OnKeyboardShow works for me (like in the full code I posted above). |
Well I've been tinkering with it, so this is what it's using now (the debugger shows that the path where it's parsing the string is what is getting hit): private double TryExtractAnimationDuration(UIKeyboardEventArgs e)
{
// this is a workaround because AnimationDuration is incorrectly returning 0 even when the logging shows
// it should be returning a value (.25 seconds in all cases I've seen, but that may not be guaranteed)
double duration = e.AnimationDuration;
if (duration == 0.0d)
{
const string extractMatch = "UIKeyboardAnimationDurationUserInfoKey = \"";
var rawStr = e.Notification.ToString();
int startIdx = rawStr.IndexOf(extractMatch);
if (startIdx > -1)
{
startIdx += rawStr.Length;
var len = rawStr.IndexOf('"', startIdx) - startIdx;
double.TryParse(rawStr.Substring(startIdx, len), out duration);
}
}
if (duration == 0.0d)
{
duration = .25; // fall-back to default observed in debugger
}
return duration;
} I've been running in the Simulator; would that have any impact on how this code behaves? Manifest version for my iOS workload is currently: 17.2.8053/8.0.100, though I'll probably try to find some time to update this week I'm a little concerned that half my workarounds will break when I do 😅. |
@TheXenocide Yeah I think I would first try it on a device instead. I think simulator keyboards potentially could behave differently because you can also type on the devices keyboard (as in the one connected to the Mac/ MacBook). |
Description
It would be really great to have Property of ContentPage that enables a similar behaviour to
WindowSoftInputModeAdjust.Resize
andWindowSoftInputModeAdjust.Pan
on Android for iOS.I think this would be possible by listening to the keyboard up event on iOS. There are a few tutorials showing this for Xamarin.Forms. This would be useful for any page with Entries or Editors.
Moreover, I can't really think of any scenario where anyone wants their content to be hidden by the keyboard on iOS.
When Pan is chosen, the ContentPage should move up entirely, when Resize is chosen the bottom Padding of the Page could be changed. I have created a example. The animation of the keyboard up event could probably be improved (and should be added for the Resize mode), but I could not find an exact function of the iOS keyboard animation and the animation for padding could probably imitated if first the page is translated up and then afterwards the Translation is removed and Padding set.
This code would probably create some issues, if the ResizeMode is set for the whole App on Android and it might not work correctly when the Resize property is updated on runtime. However, this could be a good starting point and works fine in the scenarios I have tested.
Here is my code:
on Android:
on iOS
Public API Changes
a new Property called 'Resize' on ContentPage. Maybe instead of a bool it would make sense to use an enum called 'ResizeMode', with 'Pan', 'Resize' and 'None' instead, where 'None' leaves the current behaviour (so the keyboard will hide elements on the bootom of the page on iOS).
Intended Use-Case
Move your content up like on Android on any page that uses Keyboards on iOS!
Just set your desired Mode in Xaml ContenPage like this:
<custom:KeyboardContentPage Resize="True" ..... >
The text was updated successfully, but these errors were encountered: