question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Second ExpanderView PrimaryView height issue when First Status changes to Expanded iOS - CollectionView

See original GitHub issue
<CollectionView
    ItemsSource="{Binding Items}"
    VerticalOptions="StartAndExpand"
    ItemSizingStrategy="MeasureAllItems">
    <CollectionView.ItemsLayout>
        <LinearItemsLayout
            Orientation="Vertical"
            ItemSpacing="0" />
    </CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<expander:ExpandableView StateChanged="ExpandableViewStatusChanged">
    <expander:ExpandableView.PrimaryView>
        <Grid
            RowSpacing="0">
            <Grid.RowDefinitions>
                <RowDefinition
                    Height="Auto" />
                <RowDefinition
                    Height="40" />
                <RowDefinition
                    Height="Auto" />
            </Grid.RowDefinitions>
            <BoxView
                HeightRequest="1"
                BackgroundColor="Gray"
                Grid.Row="0" />
            <StackLayout
                x:Name="sl"
                Spacing="0"
                Orientation="Horizontal"
                Grid.Row="1">
                <Label
                    Margin="20,0,0,0"
                    x:Name="plusMinus"
                    Text="+"
                    VerticalTextAlignment="Center" />
                <Label
                    Text="{Binding Title}"
                    Margin="10,0,0,0"
                    TextColor="Green"
                    VerticalOptions="Center"
                    VerticalTextAlignment="Center"
                    HorizontalOptions="Start" />
            </StackLayout>
            <BoxView
                HeightRequest="1"
                BackgroundColor="Gray"
                Grid.Row="2" />
        </Grid>
    </expander:ExpandableView.PrimaryView>
    <expander:ExpandableView.SecondaryViewTemplate>
        <DataTemplate>
            <Label
                Padding="30,10"
                Text="{Binding Detail}"
                VerticalOptions="Start"
                VerticalTextAlignment="Center" />
        </DataTemplate>
    </expander:ExpandableView.SecondaryViewTemplate>
</expander:ExpandableView>

</DataTemplate>
private void ExpandableViewStatusChanged(object sender, StatusChangedEventArgs args)
{
    if (sender is ExpandableView expander)
    {
        if (expander.PrimaryView is Grid grid)
        {
            if (grid.FindByName("sl") is StackLayout titleStackLayout)
            {
                if (titleStackLayout.Children[0] is Label icon && titleStackLayout.Children[1] is Label titleText)
                {
                    if (args.Status == ExpandStatus.Expanding)
                    {
                        Device.BeginInvokeOnMainThread(() => {
                            titleStackLayout.BackgroundColor = Color.Green;
                            icon.Text = "-";

                            icon.TextColor = Color.White;
                            titleText.TextColor = Color.White;
                        });

                    }
                    else if (args.Status == ExpandStatus.Collapsing)
                    {
                        Device.BeginInvokeOnMainThread(() => {
                            titleStackLayout.BackgroundColor = Color.White;
                            icon.Text = "+";

                            icon.TextColor = Color.Green;
                            titleText.TextColor = Color.Green;
                        });


                    }

                }
            }
        }


    }

}

iOS ScreenShot

Only 1st item selected(look at Item2 height) - this is wrong

image

Other selections which look fine

None expanded

image

all 3 expanded

image

middle only expanded

image

last 2 expanded

image

last only expanded

image

Tried calling expander.ForceUpdateSize() and (expander.PrimaryView as Grid).ForceLayout() but dint work as expected.

Android

image

On android it is fine.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
AndreiMisiukevichcommented, Apr 8, 2020

Update

As mentioned in other posts using BindableLayout with StackLayout fixed this issue Only drawback was ItemTemplateSelctor BindableObject container doesn’t expose ItemsSource to do manipulation.

Why?

var stack = new StackLayout();
var source = BindableLayout.GetItemsSource(stack);
0reactions
pmahend1commented, Apr 9, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting cell height of CollectionView, doesn't really expand ...
The size is actually queried before the cell is created. You need a way to calculate the cell's height before the collectionView asks...
Read more >
issue with collection view sizing | Apple Developer Forums
Noticed a bunch of my collection views in beta 3 are showing up too tall, but immediately shrink to size when I scroll....
Read more >
iOS
Customize iOS View Preview Container view. The second view is View. Set Leading and Top to Participant Collection View Cell and change the...
Read more >
Expanding Collection View Cells
So by setting the height to an estimated value of 50 points, I am allowing it to grow or shrink as defined by...
Read more >
Digging deep into UICollectionView | by Kuang Lin - Medium
Set the data empty. Expand the collectionView with height > 0. This is causing crash because when you reloadData() under 0 height or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found