AndroidX icon indicating copy to clipboard operation
AndroidX copied to clipboard

VS 2019 16.11.0 Preview 1.0 - WindowInsetsControllerCompat

Open gmck opened this issue 4 years ago • 1 comments

@jpobst As you predicted Xamarin.AndroidX.Core 1.5.0 has now been released, so I tested against the changes I made re the now closed issue xamarin/xamarin-android#5970.

In the AndroidR only version, the HideSystemUi was

Activity.Window.SetDecorFitsSystemWindows(false);
IWindowInsetsController windowInsetsController = Activity.Window.InsetsController;
windowInsetsController.Hide(WindowInsets.Type.StatusBars() | WindowInsets.Type.NavigationBars());                            
windowInsetsController.SystemBarsBehavior = (int)WindowInsetsControllerBehavior.ShowTransientBarsBySwipe;

For the WindowsCompat version, my initial attempt was

WindowCompat.SetDecorFitsSystemWindows(Activity.Window, false);
WindowInsetsControllerCompat windowInsetsControllerCompat = ViewCompat.GetWindowInsetsController(Activity.Window.DecorView);
windowInsetsControllerCompat.Hide(WindowInsetsCompat.Type.SystemBars() | WindowInsets.Type.NavigationBars());    
windowInsetsControllerCompat.SystemBarsBehavior = WindowInsetsControllerCompat.BehaviorShowTransientBarsBySwipe;

That works on AndroidR, but fails at runtime on anything lower than AndroidR because windowInsetsControllerCompat is always null.

Is that to be expected? The Android docs state Retrieves a WindowInsetsControllerCompat of the window this view is attached to, so I assumed it would work for all BuildVersionsCodes.

To get around it I create a WindowInsetsControllerCompat in the OnResume of the Fragment.

windowInsetsControllerCompat = new WindowInsetsControllerCompat(Activity.Window, Activity.Window.DecorView);

and then just use.

WindowCompat.SetDecorFitsSystemWindows(Activity.Window, false);
windowInsetsControllerCompat.Hide(WindowInsetsCompat.Type.SystemBars() | WindowInsets.Type.NavigationBars());    
windowInsetsControllerCompat.SystemBarsBehavior = WindowInsetsControllerCompat.BehaviorShowTransientBarsBySwipe;

WindowInsetsControllerCompat windowInsetsControllerCompat = ViewCompat.GetWindowInsetsController(Activity.Window.DecorView);

Appreciate your comments.

gmck avatar Jun 06 '21 03:06 gmck

Another method I wanted to consider trying was

public static WindowInsetsControllerCompat toWindowInsetsControllerCompat(WindowInsetsController insetsController)

but it appears to be missing from Xamarin.AndroidX.Core 1.5.0

gmck avatar Jun 06 '21 04:06 gmck

public static WindowInsetsControllerCompat toWindowInsetsControllerCompat(WindowInsetsController insetsController)
but it appears to be missing from Xamarin.AndroidX.Core 1.5.0 

This seems to be available now, so it must have gotten fixed at some point since this was filed.

image

jpobst avatar Mar 14 '24 20:03 jpobst