diff --git a/samples/MauiPdfViewerSample/AppShell.xaml b/samples/MauiPdfViewerSample/AppShell.xaml
index f029871..d88b7c9 100644
--- a/samples/MauiPdfViewerSample/AppShell.xaml
+++ b/samples/MauiPdfViewerSample/AppShell.xaml
@@ -4,9 +4,17 @@
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiPdfViewerSample"
+ FlyoutBehavior="Flyout"
Title="MauiPdfViewerSample">
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/MauiPdfViewerSample/LayoutReproPage.xaml.cs b/samples/MauiPdfViewerSample/LayoutReproPage.xaml.cs
new file mode 100644
index 0000000..8d91972
--- /dev/null
+++ b/samples/MauiPdfViewerSample/LayoutReproPage.xaml.cs
@@ -0,0 +1,144 @@
+using MauiNativePdfView;
+using MauiNativePdfView.Abstractions;
+
+namespace MauiPdfViewerSample;
+
+///
+/// Dedicated repro harness for layering / composition issues.
+///
+/// Primary target: GitHub issue #8 — content placed in the same Grid region as a
+/// PdfView ("row 0") is invisible unless BackgroundColor is set, and
+/// overlapping content flickers while the PDF scrolls.
+///
+/// This page is intentionally self-contained and toggle-driven so new layering
+/// scenarios can be added over time without disturbing the main viewer page.
+///
+public partial class LayoutReproPage : ContentPage
+{
+ private enum BackgroundMode { Unset, Transparent, Opaque }
+
+ private BackgroundMode _backgroundMode = BackgroundMode.Unset;
+ private bool _overlayLayout = true; // true = Overlay (faithful #8 repro), false = Stacked (control case)
+ private bool _headerOnTop; // true = header ZIndex bumped (flicker workaround)
+
+ public LayoutReproPage()
+ {
+ InitializeComponent();
+
+ // Open in the exact failing state from issue #8: overlay layout, background unset.
+ ApplyLayout();
+ ApplyBackground();
+ ApplyZIndex();
+
+ PdfViewer.Source = PdfSource.FromAsset("sample.pdf");
+ }
+
+ // ── Layout: Overlay vs Stacked ────────────────────────────────────────────
+ private void OnToggleLayout(object? sender, EventArgs e)
+ {
+ _overlayLayout = !_overlayLayout;
+ ApplyLayout();
+ }
+
+ private void ApplyLayout()
+ {
+ if (_overlayLayout)
+ {
+ // Header and PdfView share a single cell — the faithful issue #8 repro.
+ ReproHost.RowDefinitions = new RowDefinitionCollection(
+ new RowDefinition { Height = GridLength.Star });
+
+ Grid.SetRow(PdfViewer, 0);
+ Grid.SetRow(HeaderBand, 0);
+ HeaderBand.VerticalOptions = LayoutOptions.Start;
+ LayoutButton.Text = "Layout: Overlay";
+ }
+ else
+ {
+ // Header in its own row above the PdfView — the control case that
+ // should always render correctly regardless of background.
+ ReproHost.RowDefinitions = new RowDefinitionCollection(
+ new RowDefinition { Height = GridLength.Auto },
+ new RowDefinition { Height = GridLength.Star });
+
+ Grid.SetRow(HeaderBand, 0);
+ HeaderBand.VerticalOptions = LayoutOptions.Fill;
+ Grid.SetRow(PdfViewer, 1);
+ LayoutButton.Text = "Layout: Stacked";
+ }
+
+ UpdateStateLabel();
+ }
+
+ // ── Background: (unset) → Transparent → Opaque ─────────────────────────────
+ private void OnCycleBackground(object? sender, EventArgs e)
+ {
+ _backgroundMode = _backgroundMode switch
+ {
+ BackgroundMode.Unset => BackgroundMode.Transparent,
+ BackgroundMode.Transparent => BackgroundMode.Opaque,
+ _ => BackgroundMode.Unset,
+ };
+ ApplyBackground();
+ }
+
+ private void ApplyBackground()
+ {
+ switch (_backgroundMode)
+ {
+ case BackgroundMode.Unset:
+ // Closest thing to "never set in XAML": reset to the property default (null).
+ PdfViewer.ClearValue(VisualElement.BackgroundColorProperty);
+ BgButton.Text = "BG: (unset)";
+ break;
+ case BackgroundMode.Transparent:
+ PdfViewer.BackgroundColor = Colors.Transparent;
+ BgButton.Text = "BG: Transparent";
+ break;
+ case BackgroundMode.Opaque:
+ PdfViewer.BackgroundColor = Colors.White;
+ BgButton.Text = "BG: White";
+ break;
+ }
+
+ UpdateStateLabel();
+ }
+
+ // ── Header ZIndex (flicker workaround toggle) ──────────────────────────────
+ private void OnToggleZIndex(object? sender, EventArgs e)
+ {
+ _headerOnTop = !_headerOnTop;
+ ApplyZIndex();
+ }
+
+ private void ApplyZIndex()
+ {
+ HeaderBand.ZIndex = _headerOnTop ? 10 : 0;
+ ZIndexButton.Text = _headerOnTop ? "Header Z: 10" : "Header Z: 0";
+ UpdateStateLabel();
+ }
+
+ // ── Status readout ─────────────────────────────────────────────────────────
+ private void UpdateStateLabel()
+ {
+ var layout = _overlayLayout ? "Overlay" : "Stacked";
+ var bg = _backgroundMode switch
+ {
+ BackgroundMode.Unset => "unset",
+ BackgroundMode.Transparent => "Transparent",
+ _ => "White (opaque)",
+ };
+ StateLabel.Text = $"Layout={layout} • Background={bg} • Header ZIndex={HeaderBand.ZIndex}";
+ }
+
+ // ── PdfView events ─────────────────────────────────────────────────────────
+ private void OnDocumentLoaded(object? sender, DocumentLoadedEventArgs e)
+ {
+ HeaderSubLabel.Text = $"{e.PageCount} pages loaded — scroll to test flicker.";
+ }
+
+ private async void OnError(object? sender, PdfErrorEventArgs e)
+ {
+ await DisplayAlert("PDF Error", e.Message, "OK");
+ }
+}
diff --git a/src/MauiNativePdfView/Platforms/Android/PdfViewAndroid.cs b/src/MauiNativePdfView/Platforms/Android/PdfViewAndroid.cs
index 6ad40c3..622e763 100644
--- a/src/MauiNativePdfView/Platforms/Android/PdfViewAndroid.cs
+++ b/src/MauiNativePdfView/Platforms/Android/PdfViewAndroid.cs
@@ -43,6 +43,7 @@ public class PdfViewAndroid : IPdfView, IDisposable
public PdfViewAndroid(Context context)
{
_pdfView = new PDFView(context, null);
+ _pdfView.SetBackgroundColor(global::Android.Graphics.Color.Transparent);
}
///
@@ -227,16 +228,15 @@ public Color? BackgroundColor
set
{
_backgroundColor = value;
- if (value != null)
- {
- var androidColor = global::Android.Graphics.Color.Argb(
+ var androidColor = value != null
+ ? global::Android.Graphics.Color.Argb(
(int)(value.Alpha * 255),
(int)(value.Red * 255),
(int)(value.Green * 255),
- (int)(value.Blue * 255));
- _pdfView.SetBackgroundColor(androidColor);
- _pdfView.Invalidate();
- }
+ (int)(value.Blue * 255))
+ : global::Android.Graphics.Color.Transparent;
+ _pdfView.SetBackgroundColor(androidColor);
+ _pdfView.Invalidate();
}
}