Fixes for pages

This commit is contained in:
2026-01-24 02:37:37 +00:00
parent 7830356f24
commit ed89b6494d
5 changed files with 40 additions and 21 deletions

View File

@@ -49,6 +49,10 @@ public partial class PageHandler : ViewHandler<Page, SkiaPage>
protected override void ConnectHandler(SkiaPage platformView)
{
base.ConnectHandler(platformView);
// Set MauiPage reference for theme refresh support
platformView.MauiPage = VirtualView;
platformView.Appearing += OnAppearing;
platformView.Disappearing += OnDisappearing;
}
@@ -57,6 +61,7 @@ public partial class PageHandler : ViewHandler<Page, SkiaPage>
{
platformView.Appearing -= OnAppearing;
platformView.Disappearing -= OnDisappearing;
platformView.MauiPage = null;
base.DisconnectHandler(platformView);
}

View File

@@ -90,29 +90,19 @@ public class LinuxViewRenderer
try
{
// Render the page content
SkiaView? pageContent = null;
if (page is ContentPage contentPage && contentPage.Content != null)
{
pageContent = CurrentRenderer.RenderView(contentPage.Content);
}
// Render the page through the proper handler system
// This ensures all properties (including BackgroundColor via AppThemeBinding) are mapped
var skiaPage = CurrentRenderer.RenderPage(page);
if (pageContent == null)
if (skiaPage == null)
{
Console.WriteLine($"[PushPage] Failed to render page content");
Console.WriteLine($"[PushPage] Failed to render page through handler");
return false;
}
// Wrap in ScrollView if needed
if (pageContent is not SkiaScrollView)
{
var scrollView = new SkiaScrollView { Content = pageContent };
pageContent = scrollView;
}
// Push onto SkiaShell's navigation stack
CurrentSkiaShell.PushAsync(pageContent, page.Title ?? "Detail");
Console.WriteLine($"[PushPage] Successfully pushed page");
CurrentSkiaShell.PushAsync(skiaPage, page.Title ?? "Detail");
Console.WriteLine($"[PushPage] Successfully pushed page via handler system");
return true;
}
catch (Exception ex)

View File

@@ -764,9 +764,25 @@ public class LinuxApplication : IDisposable
navPage.Invalidate(); // Force redraw of navigation page
}
// Special handling for ContentPage - it stores content in Content property
// Special handling for SkiaPage - refresh via MauiPage handler and process Content
if (view is SkiaPage page)
{
// Refresh page properties via handler if MauiPage is set
var pageHandler = page.MauiPage?.Handler;
if (pageHandler != null)
{
try
{
Console.WriteLine($"[LinuxApplication] Refreshing page theme: {page.MauiPage?.GetType().Name}");
pageHandler.UpdateValue(nameof(IView.Background));
pageHandler.UpdateValue("BackgroundColor");
}
catch (Exception ex)
{
Console.WriteLine($"[LinuxApplication] Error refreshing page theme: {ex.Message}");
}
}
page.Invalidate(); // Force redraw to pick up theme-aware background
if (page.Content != null)
{

View File

@@ -26,6 +26,11 @@ public class SkiaPage : SkiaView
private float _paddingRight;
private float _paddingBottom;
/// <summary>
/// Reference to the MAUI Page for handler access during theme refresh.
/// </summary>
public Microsoft.Maui.Controls.Page? MauiPage { get; set; }
public SkiaView? Content
{
get => _content;
@@ -141,7 +146,8 @@ public class SkiaPage : SkiaView
protected override void OnDraw(SKCanvas canvas, SKRect bounds)
{
// Draw background color - use theme-aware default if not set
// Use BackgroundColor if explicitly set (including via AppThemeBinding),
// otherwise fall back to theme-aware default
SKColor bgColor;
if (BackgroundColor != null && BackgroundColor != Colors.Transparent)
{
@@ -149,7 +155,7 @@ public class SkiaPage : SkiaView
}
else
{
// Use theme-aware page background when no explicit color is set
// No explicit background - use theme-aware default
bgColor = SkiaTheme.CurrentPageBackgroundSK;
}

View File

@@ -500,7 +500,9 @@ public class SkiaShell : SkiaLayoutView
}
}
}
if (_selectedSectionIndex >= 0 && _selectedSectionIndex < _sections.Count)
// Only update current content if there are no pushed pages on the navigation stack
// Pushed pages are handled separately by LinuxApplication.RefreshViewTheme
if (_navigationStack.Count == 0 && _selectedSectionIndex >= 0 && _selectedSectionIndex < _sections.Count)
{
var section = _sections[_selectedSectionIndex];
if (_selectedItemIndex >= 0 && _selectedItemIndex < section.Items.Count)