From 4c586c0dc2e60f9ad98f06cc49318ca2d8dd2a90 Mon Sep 17 00:00:00 2001 From: Satoshi Nakamura Date: Thu, 25 Jan 2024 12:01:37 +0900 Subject: [PATCH] iOS Header/FooterView fix --- Sample/MauiProgram.cs | 1 + Sample/Sample.csproj | 3 +- Sample/ViewModels/HeaderSurveyViewModel.cs | 14 ++++++ Sample/ViewModels/MainViewModel.cs | 3 +- Sample/Views/HeaderSurveyPage.xaml | 49 +++++++++++++++++++ Sample/Views/HeaderSurveyPage.xaml.cs | 9 ++++ .../Platforms/iOS/Cells/CustomCellContent.cs | 1 + .../Platforms/iOS/CustomHeaderFooterView.cs | 17 +++++-- SettingsView/SettingsView.csproj | 5 +- 9 files changed, 94 insertions(+), 8 deletions(-) create mode 100644 Sample/ViewModels/HeaderSurveyViewModel.cs create mode 100644 Sample/Views/HeaderSurveyPage.xaml create mode 100644 Sample/Views/HeaderSurveyPage.xaml.cs diff --git a/Sample/MauiProgram.cs b/Sample/MauiProgram.cs index aa11cc9..2c29e76 100644 --- a/Sample/MauiProgram.cs +++ b/Sample/MauiProgram.cs @@ -26,6 +26,7 @@ public static MauiApp CreateMauiApp() containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterForNavigation(); }) .OnAppStart(async(container, navigation) => { diff --git a/Sample/Sample.csproj b/Sample/Sample.csproj index 82ec997..c98866f 100644 --- a/Sample/Sample.csproj +++ b/Sample/Sample.csproj @@ -78,7 +78,8 @@ - + + diff --git a/Sample/ViewModels/HeaderSurveyViewModel.cs b/Sample/ViewModels/HeaderSurveyViewModel.cs new file mode 100644 index 0000000..9927559 --- /dev/null +++ b/Sample/ViewModels/HeaderSurveyViewModel.cs @@ -0,0 +1,14 @@ +using System; +using Reactive.Bindings; + +namespace Sample.ViewModels; + +public class HeaderSurveyViewModel: BindableBase +{ + public ReactivePropertySlim IsShow { get; } = new(); + + public HeaderSurveyViewModel() + { + } +} + diff --git a/Sample/ViewModels/MainViewModel.cs b/Sample/ViewModels/MainViewModel.cs index f4f59cb..a0eb06a 100644 --- a/Sample/ViewModels/MainViewModel.cs +++ b/Sample/ViewModels/MainViewModel.cs @@ -48,7 +48,8 @@ public MainViewModel(INavigationService navigationService) //Description.Value += "01234567890"; //await navigationService.NavigateAsync("ListPage"); - await navigationService.NavigateAsync("TapSurveyPage"); + //await navigationService.NavigateAsync("TapSurveyPage"); + await navigationService.NavigateAsync("HeaderSurveyPage"); }); AddContentCommand.Subscribe(_ => diff --git a/Sample/Views/HeaderSurveyPage.xaml b/Sample/Views/HeaderSurveyPage.xaml new file mode 100644 index 0000000..3164140 --- /dev/null +++ b/Sample/Views/HeaderSurveyPage.xaml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sample/Views/HeaderSurveyPage.xaml.cs b/Sample/Views/HeaderSurveyPage.xaml.cs new file mode 100644 index 0000000..11eb620 --- /dev/null +++ b/Sample/Views/HeaderSurveyPage.xaml.cs @@ -0,0 +1,9 @@ +namespace Sample.Views; + +public partial class HeaderSurveyPage : ContentPage +{ + public HeaderSurveyPage() + { + InitializeComponent(); + } +} diff --git a/SettingsView/Platforms/iOS/Cells/CustomCellContent.cs b/SettingsView/Platforms/iOS/Cells/CustomCellContent.cs index 1dde962..cbcd796 100644 --- a/SettingsView/Platforms/iOS/Cells/CustomCellContent.cs +++ b/SettingsView/Platforms/iOS/Cells/CustomCellContent.cs @@ -157,6 +157,7 @@ public virtual void UpdateCell(View newCell, UITableView tableView) // Workaround GestureRecognizer bug // TODO: if fix this issue, remove the following code. // https://github.com/dotnet/maui/issues/17948 + // https://github.com/dotnet/maui/issues/1718 newCell.Parent = Application.Current.MainPage; // If Handler is not generated, generate it. diff --git a/SettingsView/Platforms/iOS/CustomHeaderFooterView.cs b/SettingsView/Platforms/iOS/CustomHeaderFooterView.cs index 278f44a..9a8e7de 100644 --- a/SettingsView/Platforms/iOS/CustomHeaderFooterView.cs +++ b/SettingsView/Platforms/iOS/CustomHeaderFooterView.cs @@ -3,6 +3,7 @@ using AiForms.Settings.Extensions; using CoreGraphics; using Foundation; +using Microsoft.Maui.Handlers; using Microsoft.Maui.Platform; using ObjCRuntime; using SpriteKit; @@ -145,6 +146,7 @@ public virtual void UpdateCell(View newCell,UITableView tableView) // Workaround GestureRecognizer bug // TODO: if fix this issue, remove the following code. // https://github.com/dotnet/maui/issues/17948 + // https://github.com/dotnet/maui/issues/1718 newCell.Parent = Application.Current.MainPage; if (_virtualCell == newCell) @@ -183,6 +185,7 @@ public virtual void UpdateCell(View newCell,UITableView tableView) handler = newCell.Handler as IPlatformViewHandler; // If the incoming Cell belongs to another parent, peel it off. handler.PlatformView?.RemoveFromSuperview(); + ArrangeSubView(handler); } else { @@ -248,16 +251,22 @@ protected virtual IPlatformViewHandler GetNewHandler() } var newHandler = _virtualCell.ToHandler(_virtualCell.FindMauiContext()); - ContentView.AddSubview(newHandler.PlatformView); - var native = newHandler.PlatformView; + ArrangeSubView(newHandler); + + return newHandler; + } + + protected virtual void ArrangeSubView(IPlatformViewHandler handler) + { + ContentView.AddSubview(handler.PlatformView); + + var native = handler.PlatformView; native.TranslatesAutoresizingMaskIntoConstraints = false; native.TopAnchor.ConstraintEqualTo(ContentView.TopAnchor).Active = true; native.LeftAnchor.ConstraintEqualTo(ContentView.LeftAnchor).Active = true; native.BottomAnchor.ConstraintEqualTo(ContentView.BottomAnchor).Active = true; native.RightAnchor.ConstraintEqualTo(ContentView.RightAnchor).Active = true; - - return newHandler; } } diff --git a/SettingsView/SettingsView.csproj b/SettingsView/SettingsView.csproj index 9d99eba..8e7aaa9 100644 --- a/SettingsView/SettingsView.csproj +++ b/SettingsView/SettingsView.csproj @@ -20,7 +20,7 @@ This is a flexible TableView specialized in settings for Android / iOS. There are various cells such as (LabelCell,ButtonCell,CommandCell,SwitchCell,CheckboxCell,RadioCell,PickerCell,EntryCell,NumberPickerCell,TimePickerCell,DatePickerCell,CustomCell) - Fix TapGestureRecognizer issue + Fix iOS Header/FooterView issue MAUI TableView Cell Setting Configuration Option ListView UITableView RecyclerView ReOrder DragDrop @@ -141,6 +141,7 @@ There are various cells such as (LabelCell,ButtonCell,CommandCell,SwitchCell,Che - + +