From ed89b6494d357ebe42dd0ab93df02c70f376d73f Mon Sep 17 00:00:00 2001 From: logikonline Date: Sat, 24 Jan 2026 02:37:37 +0000 Subject: [PATCH] Fixes for pages --- Handlers/PageHandler.cs | 5 +++++ Hosting/LinuxViewRenderer.cs | 24 +++++++----------------- LinuxApplication.cs | 18 +++++++++++++++++- Views/SkiaPage.cs | 10 ++++++++-- Views/SkiaShell.cs | 4 +++- 5 files changed, 40 insertions(+), 21 deletions(-) diff --git a/Handlers/PageHandler.cs b/Handlers/PageHandler.cs index c7faee7..e8f7447 100644 --- a/Handlers/PageHandler.cs +++ b/Handlers/PageHandler.cs @@ -49,6 +49,10 @@ public partial class PageHandler : ViewHandler 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 { platformView.Appearing -= OnAppearing; platformView.Disappearing -= OnDisappearing; + platformView.MauiPage = null; base.DisconnectHandler(platformView); } diff --git a/Hosting/LinuxViewRenderer.cs b/Hosting/LinuxViewRenderer.cs index f230186..b206fba 100644 --- a/Hosting/LinuxViewRenderer.cs +++ b/Hosting/LinuxViewRenderer.cs @@ -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) diff --git a/LinuxApplication.cs b/LinuxApplication.cs index a0867a9..ef0c50e 100644 --- a/LinuxApplication.cs +++ b/LinuxApplication.cs @@ -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) { diff --git a/Views/SkiaPage.cs b/Views/SkiaPage.cs index 989bb74..ea49bd6 100644 --- a/Views/SkiaPage.cs +++ b/Views/SkiaPage.cs @@ -26,6 +26,11 @@ public class SkiaPage : SkiaView private float _paddingRight; private float _paddingBottom; + /// + /// Reference to the MAUI Page for handler access during theme refresh. + /// + 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; } diff --git a/Views/SkiaShell.cs b/Views/SkiaShell.cs index 2d46371..9f2729a 100644 --- a/Views/SkiaShell.cs +++ b/Views/SkiaShell.cs @@ -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)