Skip to content

Commit

Permalink
Merge pull request #21 from muak/survey/HeaderView
Browse files Browse the repository at this point in the history
iOS Header/FooterView fix
  • Loading branch information
muak committed Jan 25, 2024
2 parents 61164a2 + 4c586c0 commit d48f041
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 8 deletions.
1 change: 1 addition & 0 deletions Sample/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static MauiApp CreateMauiApp()
containerRegistry.RegisterForNavigation<ListPage, ListViewModel>();
containerRegistry.RegisterForNavigation<CustomHeaderPage, CustomHeaderViewModel>();
containerRegistry.RegisterForNavigation<TapSurveyPage, TapSurveyViewModel>();
containerRegistry.RegisterForNavigation<HeaderSurveyPage, HeaderSurveyViewModel>();
})
.OnAppStart(async(container, navigation) =>
{
Expand Down
3 changes: 2 additions & 1 deletion Sample/Sample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
<ItemGroup>
<PackageReference Include="Prism.DryIoc.Maui" Version="9.0.271-pre" />
<PackageReference Include="ReactiveProperty" Version="9.3.4" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.3" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.6" />
</ItemGroup>
<ItemGroup>
<Folder Include="Views\" />
Expand Down
14 changes: 14 additions & 0 deletions Sample/ViewModels/HeaderSurveyViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using Reactive.Bindings;

namespace Sample.ViewModels;

public class HeaderSurveyViewModel: BindableBase
{
public ReactivePropertySlim<bool> IsShow { get; } = new();

public HeaderSurveyViewModel()
{
}
}

3 changes: 2 additions & 1 deletion Sample/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_ =>
Expand Down
49 changes: 49 additions & 0 deletions Sample/Views/HeaderSurveyPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:sv="clr-namespace:AiForms.Settings;assembly=SettingsView"
xmlns:vm="clr-namespace:Sample.ViewModels"
x:Class="Sample.Views.HeaderSurveyPage"
Title="HeaderSurveyPage"
x:DataType="vm:HeaderSurveyViewModel">

<sv:SettingsView>

<sv:Section>
<sv:Section.HeaderView>
<CheckBox IsChecked="{Binding IsShow.Value}" />
</sv:Section.HeaderView>
</sv:Section>

<sv:Section IsVisible="{Binding IsShow.Value}">
<sv:Section.HeaderView>
<HorizontalStackLayout>
<BoxView WidthRequest="30" HeightRequest="30" Color="Bisque" />
<Label Text="Header" />
</HorizontalStackLayout>
</sv:Section.HeaderView>
<sv:Section.FooterView>
<Label Text="Footer" />
</sv:Section.FooterView>
<sv:LabelCell Title="Hoge" ValueText="Abc" />
<sv:EntryCell Title="Input" />
</sv:Section>

<sv:Section IsVisible="{Binding IsShow.Value}">
<sv:Section.HeaderView>
<HorizontalStackLayout>
<BoxView WidthRequest="30" HeightRequest="30" Color="Red" />
<Label Text="Header" />
</HorizontalStackLayout>
</sv:Section.HeaderView>
<sv:Section.FooterView>
<Label Text="Footer" />
</sv:Section.FooterView>
<sv:LabelCell Title="Fuga" ValueText="Xyz" />
<sv:EntryCell Title="Input" />
</sv:Section>

</sv:SettingsView>

</ContentPage>
9 changes: 9 additions & 0 deletions Sample/Views/HeaderSurveyPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Sample.Views;

public partial class HeaderSurveyPage : ContentPage
{
public HeaderSurveyPage()
{
InitializeComponent();
}
}
1 change: 1 addition & 0 deletions SettingsView/Platforms/iOS/Cells/CustomCellContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 13 additions & 4 deletions SettingsView/Platforms/iOS/CustomHeaderFooterView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using AiForms.Settings.Extensions;
using CoreGraphics;
using Foundation;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
using ObjCRuntime;
using SpriteKit;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}
}
5 changes: 3 additions & 2 deletions SettingsView/SettingsView.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<Description>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)</Description>
<PackageReleaseNotes>
Fix TapGestureRecognizer issue
Fix iOS Header/FooterView issue
</PackageReleaseNotes>
<PackageTags>MAUI TableView Cell Setting Configuration Option ListView UITableView RecyclerView ReOrder DragDrop</PackageTags>
</PropertyGroup>
Expand Down Expand Up @@ -141,6 +141,7 @@ There are various cells such as (LabelCell,ButtonCell,CommandCell,SwitchCell,Che
<AndroidResource Include="Platforms\Android\Resources\values\attrs.xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.3" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.6" />
</ItemGroup>
</Project>

0 comments on commit d48f041

Please sign in to comment.