Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ namespace CommunityToolkit.Maui.Core.Views;
/// </summary>
public class MauiMediaElement : CoordinatorLayout
{
static Android.Views.Window window => Platform.CurrentActivity?.Window ?? throw new InvalidOperationException("Current activity is null");
static Android.Views.View decorView => window.DecorView ?? throw new InvalidOperationException("DecorView is null");
static AndroidX.Core.View.WindowInsetsControllerCompat insetsController => WindowCompat.GetInsetsController(window, decorView) ?? throw new InvalidOperationException("InsetsController is null");
readonly RelativeLayout relativeLayout;
readonly PlayerView playerView;

int defaultSystemUiVisibility;
bool isSystemBarVisible;
bool isFullScreen;

#pragma warning disable CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable.
Expand Down Expand Up @@ -78,7 +79,7 @@ protected override void OnVisibilityChanged(Android.Views.View changedView, [Gen
base.OnVisibilityChanged(changedView, visibility);
if (isFullScreen && visibility is ViewStates.Visible)
{
SetSystemBarsVisibility();
SetStatusBarsHidden(isFullScreen);
}
}

Expand Down Expand Up @@ -131,77 +132,31 @@ void OnFullscreenButtonClick(object? sender, PlayerView.FullscreenButtonClickEve
isFullScreen = false;
layout?.RemoveView(relativeLayout);
AddView(relativeLayout);
relativeLayout.Invalidate();
}
// Hide/Show the SystemBars and Status bar
SetSystemBarsVisibility();
SetStatusBarsHidden(isFullScreen);
}

Copy link

Copilot AI Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new SetStatusBarsHidden method lacks XML documentation comments. According to the coding guidelines, public methods should have XML documentation. Since this method is currently public (though it should likely be private/internal), add documentation explaining:

  • The purpose of the method
  • The hidden parameter
  • Any exceptions that may be thrown

Example:

/// <summary>
/// Sets the visibility of system bars (status bar and navigation bar).
/// </summary>
/// <param name="hidden">If <see langword="true"/>, hides the system bars; otherwise, shows them.</param>
/// <exception cref="InvalidOperationException">Thrown when the current activity, DecorView, or InsetsController is null.</exception>
Suggested change
/// <summary>
/// Sets the visibility of system bars (status bar and navigation bar).
/// </summary>
/// <param name="hidden">If <see langword="true"/>, hides the system bars; otherwise, shows them.</param>
/// <exception cref="InvalidOperationException">Thrown when the current activity, DecorView, or InsetsController is null.</exception>

Copilot uses AI. Check for mistakes.
void SetSystemBarsVisibility()
public static void SetStatusBarsHidden(bool hidden)
Copy link

Copilot AI Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method SetStatusBarsHidden is marked as public static, but it should be private or internal since it's an implementation detail of system bar visibility management. Making it public exposes internal Android-specific behavior that shouldn't be part of the public API surface. Consider changing the visibility to private or internal.

Suggested change
public static void SetStatusBarsHidden(bool hidden)
static void SetStatusBarsHidden(bool hidden)

Copilot uses AI. Check for mistakes.
{
var currentWindow = CurrentPlatformContext.CurrentWindow;
var windowInsetsControllerCompat = WindowCompat.GetInsetsController(currentWindow, currentWindow.DecorView);

var barTypes = WindowInsetsCompat.Type.StatusBars()
| WindowInsetsCompat.Type.SystemBars()
| WindowInsetsCompat.Type.NavigationBars();

if (isFullScreen)
{
WindowCompat.SetDecorFitsSystemWindows(currentWindow, false);
if (OperatingSystem.IsAndroidVersionAtLeast(30))
{
var windowInsets = currentWindow.DecorView.RootWindowInsets;
if (windowInsets is not null)
{
isSystemBarVisible = windowInsets.IsVisible(WindowInsetsCompat.Type.NavigationBars()) || windowInsets.IsVisible(WindowInsetsCompat.Type.StatusBars());

if (isSystemBarVisible)
{
currentWindow.InsetsController?.Hide(WindowInsets.Type.SystemBars());
}
}
}
else
{
defaultSystemUiVisibility = (int)currentWindow.DecorView.SystemUiFlags;

currentWindow.DecorView.SystemUiFlags = currentWindow.DecorView.SystemUiFlags
| SystemUiFlags.LayoutStable
| SystemUiFlags.LayoutHideNavigation
| SystemUiFlags.LayoutFullscreen
| SystemUiFlags.HideNavigation
| SystemUiFlags.Fullscreen
| SystemUiFlags.Immersive;
}

if (windowInsetsControllerCompat is not null)
{
windowInsetsControllerCompat.Hide(barTypes);
windowInsetsControllerCompat.SystemBarsBehavior = WindowInsetsControllerCompat.BehaviorShowTransientBarsBySwipe;
}

}
else
if (OperatingSystem.IsAndroidVersionAtLeast(26))
{
if (OperatingSystem.IsAndroidVersionAtLeast(30))
if (hidden)
{
if (isSystemBarVisible)
{
currentWindow.InsetsController?.Show(WindowInsets.Type.SystemBars());
}
window.ClearFlags(WindowManagerFlags.LayoutNoLimits);
window.AddFlags(WindowManagerFlags.Fullscreen);
window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
insetsController.SystemBarsBehavior = WindowInsetsControllerCompat.BehaviorShowTransientBarsBySwipe;
insetsController.Hide(WindowInsetsCompat.Type.SystemBars());
}
else
{
currentWindow.DecorView.SystemUiFlags = (SystemUiFlags)defaultSystemUiVisibility;
}

if (windowInsetsControllerCompat is not null)
{
windowInsetsControllerCompat.Show(barTypes);
windowInsetsControllerCompat.SystemBarsBehavior = WindowInsetsControllerCompat.BehaviorDefault;
window.ClearFlags(WindowManagerFlags.Fullscreen);
window.SetFlags(WindowManagerFlags.DrawsSystemBarBackgrounds, WindowManagerFlags.DrawsSystemBarBackgrounds);
insetsController.SystemBarsBehavior = WindowInsetsControllerCompat.BehaviorDefault;
insetsController.Show(WindowInsetsCompat.Type.SystemBars());
}

WindowCompat.SetDecorFitsSystemWindows(currentWindow, true);
}
}

Expand Down
Loading