Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Android CustomCell Measure #17

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sample/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static MauiApp CreateMauiApp()
containerRegistry.RegisterForNavigation<MainPage, MainViewModel>();
containerRegistry.RegisterForNavigation<ContentPage>();
containerRegistry.RegisterForNavigation<ListPage, ListViewModel>();
containerRegistry.RegisterForNavigation<CustomHeaderPage, CustomHeaderViewModel>();
})
.OnAppStart(navigationService =>
{
Expand Down
17 changes: 17 additions & 0 deletions Sample/ViewModels/CustomHeaderViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using Reactive.Bindings;

namespace Sample.ViewModels;

public class CustomHeaderViewModel:BindableBase
{
public ReactivePropertySlim<string> Description { get; } = new ReactivePropertySlim<string>();
public ReactivePropertySlim<bool> IsAgree { get; } = new ReactivePropertySlim<bool>();

public CustomHeaderViewModel()
{
//Description.Value = "退会すると、診察券登録はすべて解除され、利用規約に従いデータは適切に処理されます。";
Description.Value = "Upon withdrawal, all medical ticket registrations will be cancelled and data will be properly processed in accordance with the Terms of Use.";
}
}

5 changes: 3 additions & 2 deletions Sample/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ public MainViewModel(INavigationService navigationService)
});

ToProfileCommand.Subscribe(async _ => {

//Description.Value += "01234567890";
await navigationService.NavigateAsync("ListPage");
//await navigationService.NavigateAsync("ListPage");
await navigationService.NavigateAsync("CustomHeaderPage");
});

AddContentCommand.Subscribe(_ =>
Expand Down
60 changes: 60 additions & 0 deletions Sample/Views/CustomHeaderPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?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"
x:Class="Sample.Views.CustomHeaderPage"
Title="CustomHeaderPage">

<sv:SettingsView HeaderBackgroundColor="LightGray">
<sv:Section>
<sv:Section.HeaderView>
<StackLayout>
<Border Grid.Row="0"
Stroke="Red"
StrokeThickness="{OnPlatform iOS=3,Android=1}"
Padding="8" BackgroundColor="#FFDDDD"
Margin="16,8,16,8" StrokeShape="RoundRectangle 16">

<Grid ColumnDefinitions="30,*,12" RowDefinitions="Auto">

<Image Grid.Column="0"
Source="dotnet_bot"
WidthRequest="30" HeightRequest="30"
VerticalOptions="Center" />
<Label Grid.Column="1" Text="Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text End"
TextColor="Black"
FontSize="16"
LineBreakMode="CharacterWrap"
/>
<Image Grid.Column="2" Source="ic_close"
WidthRequest="12" HeightRequest="12"
VerticalOptions="Center" />
</Grid>
</Border>
<StackLayout Orientation="Horizontal" Spacing="0" Grid.Row="1"
Margin="16,8,16,8">

<CheckBox IsChecked="{Binding IsAgree.Value}" Color="Orange"
VerticalOptions="Center" WidthRequest="36" x:Name="agreeCheckbox" />
<Label Text="I Agree"
TextColor="Black"
FontSize="16"
VerticalOptions="Center" />
</StackLayout>
</StackLayout>

</sv:Section.HeaderView>
</sv:Section>

<sv:Section Title="TitleA">
<sv:LabelCell Title="Label" />
</sv:Section>

<sv:Section Title="TitleB">
<sv:LabelCell Title="Label" />
</sv:Section>

</sv:SettingsView>

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

public partial class CustomHeaderPage : ContentPage
{
public CustomHeaderPage()
{
InitializeComponent();
}
}
1 change: 0 additions & 1 deletion Sample/Views/ListPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<sv:Section>
<sv:Section.HeaderView>
<Grid>
<!--TODO:Image修正-->
<ImageButton Source="ic_close"
WidthRequest="30" HeightRequest="30"
VerticalOptions="Center" HorizontalOptions="End"
Expand Down
13 changes: 7 additions & 6 deletions SettingsView/Platforms/Android/FormsViewContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,22 @@ protected override void OnLayout(bool changed, int l, int t, int r, int b)

protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
int width = MeasureSpec.GetSize(widthMeasureSpec);
int pxWidth = MeasureSpec.GetSize(widthMeasureSpec);

if (IsMeasureOnce && _heightCache > 0)
{
SetMeasuredDimension(width, _heightCache);
SetMeasuredDimension(pxWidth, _heightCache);
return;
}

var size = _viewHandler.VirtualView.Measure(width, double.PositiveInfinity);
var dpWidth = Context.FromPixels(pxWidth);
var size = _viewHandler.VirtualView.Measure(dpWidth, double.PositiveInfinity);
// This way can't measure correctly.
//var measure = _viewHandler.MeasureVirtualView(width, heightMeasureSpec);
int height = (int)Context.ToPixels(size.Height);
int pxHeight = (int)Context.ToPixels(size.Height);

SetMeasuredDimension(width, height);
_heightCache = height;
SetMeasuredDimension(pxWidth, pxHeight);
_heightCache = pxHeight;
}

public virtual void CellPropertyChanged(object sender, PropertyChangedEventArgs e)
Expand Down
13 changes: 7 additions & 6 deletions SettingsView/Platforms/Android/HeaderFooterContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,23 @@ protected override void OnLayout(bool changed, int l, int t, int r, int b)

protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
int width = MeasureSpec.GetSize(widthMeasureSpec);
int pxWidth = MeasureSpec.GetSize(widthMeasureSpec);
if (_viewHandler == null)
{
SetMeasuredDimension(width, 0);
SetMeasuredDimension(pxWidth, 0);
return;
}
if(ViewHolder.RowInfo.ViewType == ViewType.CustomFooter && !ViewHolder.RowInfo.Section.FooterVisible)
{
SetMeasuredDimension(width, 0);
SetMeasuredDimension(pxWidth, 0);
return;
}

var size = _viewHandler.VirtualView.Measure(width, double.PositiveInfinity);
int height = (int)Context.ToPixels(size.Height);
var dpWidth = Context.FromPixels(pxWidth);
var size = _viewHandler.VirtualView.Measure(dpWidth, double.PositiveInfinity);
int pxHeight = (int)Context.ToPixels(size.Height);

SetMeasuredDimension(width, height);
SetMeasuredDimension(pxWidth, pxHeight);
}

public virtual void CellPropertyChanged(object sender, PropertyChangedEventArgs e)
Expand Down
6 changes: 3 additions & 3 deletions SettingsView/Platforms/iOS/CustomHeaderFooterView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ public virtual void UpdateCell(View newCell,UITableView tableView)
_virtualCell.MeasureInvalidated += OnMeasureInvalidated;

var height = double.PositiveInfinity;
var result = handler.VirtualView.Measure(tableView.Frame.Width, height);
var finalW = result.Width;
var result = _virtualCell.Measure(tableView.Frame.Width, height,MeasureFlags.IncludeMargins);
var finalW = result.Request.Width;
if(_virtualCell.HorizontalOptions.Alignment == LayoutAlignment.Fill)
{
finalW = tableView.Frame.Width;
}
var finalH = (float)result.Height;
var finalH = (float)result.Request.Height;

UpdateNativeCell();

Expand Down
1 change: 1 addition & 0 deletions nuget/AzurePipelines.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ There are various cells such as (LabelCell,ButtonCell,CommandCell,SwitchCell,Che
</description>
<summary></summary>
<releaseNotes>
- Fix Android CustomCell Size
- Update .NET 7.0
- Fix PickerCell SingleSelectMode not working.
</releaseNotes>
Expand Down