maui icon indicating copy to clipboard operation
maui copied to clipboard

[Android] Window currently doesn't apply AdjustPan so the view doesn't pan up (scroll) when the keyboard opens

Open PureWeen opened this issue 2 years ago • 2 comments

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
}

image

PureWeen avatar Nov 10 '22 23:11 PureWeen

@PureWeen thanks a lot !!! Really appreciate your hard work.

Syed-RI avatar Nov 10 '22 23:11 Syed-RI

@PureWeen Good This has solved the problem that has plagued me for a month. I even want to give up maui

solayuta avatar Nov 12 '22 11:11 solayuta

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 avatar Nov 15 '22 12:11 borrmann

@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

PureWeen avatar Nov 29 '22 15:11 PureWeen

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 image

cerkzil avatar Dec 03 '22 14:12 cerkzil

@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.

PureWeen avatar Mar 07 '23 19:03 PureWeen