Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
[Shell,Android] Allow transparent background on Shell Header (#13322) f…
Browse files Browse the repository at this point in the history
…ixes #13305  fixes #12309

* Fix layout of FlyoutContent

* - fix ui tests

* [Controls] Add repo for issue #13305

* [Controls] Add more content to FlyoutBackground test

* [Android]  Make Shell header transparent

* - fix header container to set elevation

Co-authored-by: shane <shneuvil@microsoft.com>
  • Loading branch information
rmarinho and PureWeen committed Jan 15, 2021
1 parent a6c79e8 commit 2fa7165
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ public ShellFlyoutBackground()

protected override void Init()
{
AddFlyoutItem(CreateContentPage(), "Item 1");
AddFlyoutItem(CreateContentPage(), "Item 2");
for (int i = 0; i < 20; i++)
{
AddFlyoutItem(CreateContentPage(), $"Item {i}");
}

FlyoutBackgroundImage = "photo.jpg";
FlyoutBackgroundImageAspect = Aspect.AspectFill;
FlyoutVerticalScrollMode = ScrollMode.Enabled;
}

ContentPage CreateContentPage()
Expand Down Expand Up @@ -148,6 +151,52 @@ ContentPage CreateContentPage()
}
}),
AutomationId = "ToggleHeaderFooter"
},
new Button()
{
Text = "Toggle Header/Footer Transparent",
Command = new Command(() =>
{
if (FlyoutHeader == null)
{
FlyoutFooter =
new Label()
{
Text = "The FOOTER",
TextColor = Color.Blue,
HeightRequest = 50
};
FlyoutHeader =
new StackLayout
{
Orientation = StackOrientation.Horizontal,
HeightRequest = 100,
Children = {
new Label()
{
Text = "The HEADER",
FontSize = 25,
FontAttributes = FontAttributes.Bold,
VerticalTextAlignment = TextAlignment.Center,
TextColor = Color.Blue,
},
new Button()
{
Text = "OK",
FontSize = 25,
TextColor = Color.Green,
Command = new Command(() => DisplayAlert("Button", "ThisButtonWorks", "OK"))
}
}
};
}
else
{
FlyoutHeader = FlyoutFooter = null;
}
}),
AutomationId = "ToggleHeaderFooterTransparent"
}
}
};
Expand Down
5 changes: 2 additions & 3 deletions Xamarin.Forms.Platform.Android/Renderers/ContainerView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,12 @@ protected override void OnLayout(bool changed, int l, int t, int r, int b)

var width = Context.FromPixels(r - l);
var height = Context.FromPixels(b - t);

_shellViewRenderer.LayoutView(width, height);
LayoutView(0, 0, width, height);
}

protected virtual void LayoutView(double x, double y, double width, double height)
{
View?.Layout(new Rectangle(x, y, width, height));
_shellViewRenderer.LayoutView(width, height);
}

protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,19 +549,8 @@ void UpdateElevation()

protected override void LayoutView(double x, double y, double width, double height)
{
var context = Context;
var paddingLeft = context.FromPixels(PaddingLeft);
var paddingTop = context.FromPixels(PaddingTop);
var paddingRight = context.FromPixels(PaddingRight);
var paddingBottom = context.FromPixels(PaddingBottom);

width -= paddingLeft + paddingRight;
height -= paddingTop + paddingBottom;

UpdateElevation();

if (View != null)
View.Layout(new Rectangle(paddingLeft, paddingTop, width, height));
base.LayoutView(x, y, width, height);
}

protected override void Dispose(bool disposing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
android:id="@+id/flyoutcontent_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
app:elevation="0dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

</xamarin.forms.platform.android.ShellFlyoutLayout>

0 comments on commit 2fa7165

Please sign in to comment.