Skip to content

Commit

Permalink
Merge pull request #22 from muak/survey/HeaderView
Browse files Browse the repository at this point in the history
Fix iOS Header/FooterView disappear
  • Loading branch information
muak committed Jan 25, 2024
2 parents d48f041 + cd07e7b commit b1929de
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 20 deletions.
54 changes: 40 additions & 14 deletions Sample/Views/HeaderSurveyPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,66 @@
Title="HeaderSurveyPage"
x:DataType="vm:HeaderSurveyViewModel">

<sv:SettingsView>
<sv:SettingsView HasUnevenRows="True">

<sv:Section>
<sv:Section.HeaderView>
<CheckBox IsChecked="{Binding IsShow.Value}" />
<sv:Section.HeaderView>
<StackLayout Orientation="Horizontal" Spacing="0" Grid.Row="1">
<CheckBox IsChecked="{Binding IsShow.Value}"
VerticalOptions="Center" WidthRequest="36"/>
<Label Text="Agree"
TextColor="Black"
FontSize="16"
VerticalOptions="Center" />
</StackLayout>
</sv:Section.HeaderView>
</sv:Section>

<sv:Section IsVisible="{Binding IsShow.Value}">
<sv:Section IsVisible="{Binding IsShow.Value}">

<sv:Section.HeaderView>
<HorizontalStackLayout>
<BoxView WidthRequest="30" HeightRequest="30" Color="Bisque" />
<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="Hoge" ValueText="Abc" />
<sv:EntryCell Title="Input" />

<sv:PickerCell />

</sv:Section>


<sv:Section IsVisible="{Binding IsShow.Value}">

<sv:Section.HeaderView>
<HorizontalStackLayout>
<BoxView WidthRequest="30" HeightRequest="30" Color="Red" />
<BoxView WidthRequest="30" HeightRequest="30" Color="Bisque" />
<Label Text="Header" />
</HorizontalStackLayout>
</sv:Section.HeaderView>

<sv:Section.FooterView>
<Label Text="Footer" />
<ContentView>
<Button
Text="Submit"
Margin="32,32,32,8"
/>
</ContentView>
</sv:Section.FooterView>
<sv:LabelCell Title="Fuga" ValueText="Xyz" />
<sv:EntryCell Title="Input" />

<sv:CustomCell IsMeasureOnce="False" IsSelectable="False"
ShowArrowIndicator="False" UseFullSize="True"
>
<Grid Padding="16,8,24,8">
<Editor
AutoSize="TextChanges"
MinimumHeightRequest="80"
MaxLength="300"
Placeholder="Input your text"
/>
</Grid>
</sv:CustomCell>

</sv:Section>

</sv:SettingsView>
Expand Down
12 changes: 6 additions & 6 deletions SettingsView/Platforms/iOS/CustomHeaderFooterView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public virtual void UpdateCell(View newCell,UITableView tableView)

if(oldCell != null)
{
oldCell.Handler?.DisconnectHandler();
// Do not disconnect the Handler here as it may not redraw.
//oldCell.Handler?.DisconnectHandler();
oldCell.PropertyChanged -= CellPropertyChanged;
oldCell.MeasureInvalidated -= OnMeasureInvalidated;
// Delete previous child element
Expand All @@ -185,7 +186,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);
ArrangeSubView(handler);
}
else
{
Expand All @@ -200,13 +201,15 @@ public virtual void UpdateCell(View newCell,UITableView tableView)
if (handlerType == viewHandlerType)
{
handler.SetVirtualView(_virtualCell);
System.Diagnostics.Debug.WriteLine("SetVirtualCell");
}
else
{
//when cells are getting reused the element could be already set to another cell
//so we should dispose based on the renderer and not the renderer.Element
handler.DisposeHandlersAndChildren();
handler = GetNewHandler();
System.Diagnostics.Debug.WriteLine("Already set another cell");
}

_virtualCell.MeasureInvalidated += OnMeasureInvalidated;
Expand All @@ -230,10 +233,7 @@ public virtual void UpdateCell(View newCell,UITableView tableView)

_heightConstraint = handler.PlatformView.HeightAnchor.ConstraintEqualTo(finalH);
_heightConstraint.Priority = 999f;
_heightConstraint.Active = true;

// TODO: 不要になったかも。
// Layout.LayoutChildIntoBoundingRegion(_virtualCell, new Rectangle(0, 0, finalW, finalH));
_heightConstraint.Active = true;

handler.PlatformView.UpdateConstraintsIfNeeded();
}
Expand Down

0 comments on commit b1929de

Please sign in to comment.