maui
maui copied to clipboard
[Android] Window currently doesn't apply AdjustPan so the view doesn't pan up (scroll) when the keyboard opens
Description
Original issue here
In XF Window.SetSoftInputMode(Android.Views.SoftInput.AdjustPan);
would get called after the OnCreate
call whereas in MAUI it's called before OnCreate
. It seems like this causes the property to have no effect
If you call this method after OnCreate
than everything starts to work like XF.
Reproduction
If you take the XAML
below and test a few different permutations, you'll notice that the behavior isn't currently consistent when you open a keyboard
- Shell: Nothing happens
- Shell/ScrollView: entry scrolls into view but ScrollView doesn't reset
- NavigationPage/ScrollView: entry scrolls into view but ScrollView doesn't reset
If you test this scenario on XF all permutations work the same
- the window pans up (scrolls up) when you open the keyboard
- you close the keyboard and it pans back down
<StackLayout Padding="10">
<Entry Text="Top"></Entry>
<Entry></Entry>
<Entry></Entry>
<Entry></Entry>
<Entry></Entry>
<Entry></Entry>
<Entry></Entry>
<Entry></Entry>
<Entry></Entry>
<Entry></Entry>
<Entry></Entry>
<Entry Text="Middle"></Entry>
<Entry></Entry>
<Entry></Entry>
<Entry></Entry>
<Entry></Entry>
<Entry></Entry>
<Entry></Entry>
<Entry></Entry>
<Entry></Entry>
<Entry></Entry>
<Entry></Entry>
<Entry Text="Bottom"></Entry>
</StackLayout>
Workaround
Basically, open the MainActivity
class and add the following override
public class MainActivity : MauiAppCompatActivity
{
// add this override
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Window.SetSoftInputMode(Android.Views.SoftInput.AdjustPan);
}
// end of override
}
@PureWeen thanks a lot !!! Really appreciate your hard work.
@PureWeen Good This has solved the problem that has plagued me for a month. I even want to give up maui
Is there a workaround if you want certain behaviour on certain pages? I call this method sometimes in OnAppearing or OnNavigatedTo, but the behaviour doesn't update.
@borrmann once this releases you should be able to change the platform specific for this on Application
and it will update.
https://learn.microsoft.com/en-us/dotnet/maui/android/platform-specifics/soft-keyboard-input-mode?view=net-maui-7.0
AdjustPan doesn't solve the problem completely, if the input doesn't need to be panned to input text it works, but if it pans it still causes the same issue
@cerkzil this should be fixed in a future release by https://github.com/dotnet/maui/pull/12661
I have a workaround in a nuget here https://github.com/PureWeen/ShanedlerSamples
If you want to try that nuget and see if it fixes it for you. If it doesn't let me know and I can attach a repro.