dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.98k stars 1.71k forks source link

[Android] Modal shown TabbedPage has problems with SetSoftInputMode AdjustResize #20358

Open siem300 opened 7 months ago

siem300 commented 7 months ago

Description

During our migration of Maui from Xamarin Forms we ran into a problem where the TabbedPage renders its Toolbar across the content of the shown page. This only happens when the TabbedPage is opened as a Modal and SetSoftInputMode is set to AdjustResize in the MainActivity.

We need the AdjustResize to prevent the keyboard from blocking the input control when the user is typing.

I have attached a reproduction project and screenshots containing the error.

Modal TabbedPage Non modal TabbedPage
Screenshot_20240205-113440 Screenshot_20240205-113447

Steps to Reproduce

  1. Start the attached repro scenario
  2. Select the entry field, the resize happens and is shown correctly
  3. Select the 'Click me' button
  4. Select the entry field, the resize happens and the tabbedpage is now shown above the content

Link to public reproduction project repository

https://github.com/siem300/Maui-Modal-TabbedPage-issue

Version with bug

8.0.3

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

https://github.com/dotnet/maui/issues/20358#issuecomment-1995929663

Relevant log output

No response

ghost commented 7 months ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

konradzuse commented 6 months ago

I have a similar issue, my tabbed page is using a BottomNavBar, and the bar is stretched to fill half the screen when the keyboard opens

siem300 commented 6 months ago

The moment you give the tabbar a background color the problem gets worse cause you can't see the underlying content anymore.

Uridel commented 6 months ago

Is there any workaround for this issue. It is currently halting our product from being taken into production.

PureWeen commented 5 months ago

alright so here's a workaround

#if ANDROID
            this.Children[0].Loaded += (_,_) =>
            {
                var platformView = (this.Handler as IPlatformViewHandler).PlatformView;                

                var bottomNavigationView = (platformView.Parent.Parent as Android.Views.View)
                    .FindViewById<Android.Views.ViewGroup>(Resource.Id.navigationlayout_bottomtabs)
                    .GetChildAt(0);

                bottomNavigationView.SetPadding(0,0,0,0);
                AndroidX.Core.View.ViewCompat.SetOnApplyWindowInsetsListener(bottomNavigationView, null);

            };
#endif

Add this to the ctor of your tabbedpage that's being pushed modally.

This seems to be a weird quirk with BottomNavigationView

If you search around for BottomNavigationView and software keyboard you'll get a bunch of SO posts that tell you to use "AdjustPan" instead of "AdjustResize" to fix :-)

BottomNavigationView has this window inset watcher that bumps the navigationview up. I haven't tested all scenarios to see if this breaks other things yet.

For NET9 I'm hoping that moving to DialogFragment just magically fixes this

image

XamlTest commented 5 months ago

Verified this on VS 17.10.0 Preview 2.0(8.0.7). Repro on Android 14.0-API34. Maui-Modal-TabbedPage.zip

siem300 commented 5 months ago

@PureWeen The workaround works! Thanks for figuring out a temporary solution.