Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SplitDrawable from Shell code #9896

Merged
merged 2 commits into from
Sep 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -85,7 +85,6 @@ IShellBottomNavViewAppearanceTracker IShellContext.CreateBottomNavViewAppearance

void IAppearanceObserver.OnAppearanceChanged(ShellAppearance appearance)
{
UpdateStatusBarColor(appearance);
}

#endregion IAppearanceObserver
Expand Down Expand Up @@ -269,37 +268,6 @@ int MakeMeasureSpec(int size, MeasureSpecMode mode)
return size + (int)mode;
}

void UpdateStatusBarColor(ShellAppearance appearance)
{
var activity = AndroidContext.GetActivity();
var window = activity?.Window;
var decorView = window?.DecorView;

int statusBarHeight = AndroidContext.GetStatusBarHeight();
int navigationBarHeight = AndroidContext.GetNavigationBarHeight();

// we are using the split drawable here to avoid GPU overdraw.
// All it really is is a drawable that only draws under the statusbar/bottom bar to make sure
// we dont draw over areas we dont need to. This has very limited benefits considering its
// only saving us a flat color fill BUT it helps people not freak out about overdraw.
AColor color;
if (appearance != null)
{
color = appearance.BackgroundColor.ToPlatform(Color.FromArgb("#03A9F4"));
}
else
{
color = Color.FromArgb("#03A9F4").ToPlatform();
}

if (!(decorView.Background is SplitDrawable splitDrawable) ||
splitDrawable.Color != color || splitDrawable.TopSize != statusBarHeight || splitDrawable.BottomSize != navigationBarHeight)
{
var split = new SplitDrawable(color, statusBarHeight, navigationBarHeight);
decorView.SetBackground(split);
}
}

bool IViewHandler.HasContainer { get => false; set { } }

object IViewHandler.ContainerView => null;
Expand Down Expand Up @@ -371,48 +339,5 @@ void IElementHandler.DisconnectHandler()

_disposed = true;
}

class SplitDrawable : Drawable
{
public int BottomSize { get; }
public AColor Color { get; }
public int TopSize { get; }

public SplitDrawable(AColor color, int topSize, int bottomSize)
{
Color = color;
BottomSize = bottomSize;
TopSize = topSize;
}

public override int Opacity => (int)Format.Opaque;

public override void Draw(Canvas canvas)
{
var bounds = Bounds;

using (var paint = new Paint())
{
#pragma warning disable CA1416 // https://github.com/xamarin/xamarin-android/issues/6962
paint.Color = Color;
#pragma warning restore CA1416

canvas.DrawRect(new ARect(0, 0, bounds.Right, TopSize), paint);

canvas.DrawRect(new ARect(0, bounds.Bottom - BottomSize, bounds.Right, bounds.Bottom), paint);

paint.Dispose();
}
}

public override void SetAlpha(int alpha)
{
}

public override void SetColorFilter(ColorFilter colorFilter)
{
}
}

}
}
6 changes: 0 additions & 6 deletions src/Controls/tests/DeviceTests/HandlerTestBase.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,13 @@ public AView GetSemanticPlatformElement(IViewHandler viewHandler)
return (AView)viewHandler.PlatformView;
}

static Drawable _decorDrawable;
Task SetupWindowForTests<THandler>(IWindow window, Func<Task> runTests, IMauiContext mauiContext = null)
where THandler : class, IElementHandler
{
mauiContext ??= MauiContext;
return InvokeOnMainThreadAsync(async () =>
{
AViewGroup rootView = MauiContext.Context.GetActivity().Window.DecorView as AViewGroup;
_decorDrawable ??= rootView.Background;
var linearLayoutCompat = new LinearLayoutCompat(MauiContext.Context);
var fragmentManager = MauiContext.GetFragmentManager();
var viewFragment = new WindowTestFragment(MauiContext, window);
Expand Down Expand Up @@ -84,10 +82,6 @@ Task SetupWindowForTests<THandler>(IWindow window, Func<Task> runTests, IMauiCon

await viewFragment.FinishedDestroying;

// This is mainly to remove changes to the decor view that shell imposes
if (_decorDrawable != rootView.Background)
rootView.Background = _decorDrawable;

// Unset the Support Action bar if the calling code has set the support action bar
if (MauiContext.Context.GetActivity() is AppCompatActivity aca)
{
Expand Down