Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] [iOS] CollectionView does not display items if IsVisible modified via a binding/trigger #13551

Closed
dmariogatto opened this issue Jan 26, 2021 · 12 comments · Fixed by #13640
Assignees
Labels
a/collectionview blocker Issue blocks next stable release. Prioritize fixing and reviewing this issue. i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often in-progress This issue has an associated pull request that may resolve it! p/iOS 🍎 t/bug 🐛

Comments

@dmariogatto
Copy link
Contributor

dmariogatto commented Jan 26, 2021

Description

Bind CollectionView to an item source, also bind IsVisible to an initially false value. When the binding for IsVisible changes to true the CollectionView does not display its items. (similar to #13203)

Steps to Reproduce

    <Grid RowDefinitions="*,*,*">
        <!--  Works 👍 (EDIT: doesn't work when IsVisible="false"  -->
        <CollectionView
            x:Name="ItemsView1"
            IsVisible="True" <!-- EDIT: this should be 'false' -->
            ItemsSource="{Binding Items}">
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <Frame>
                        <Label Text="{Binding}" />
                    </Frame>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>

        <!--  Does not work 👎  -->
        <CollectionView
            x:Name="ItemsView2"
            Grid.Row="1"
            IsVisible="{Binding Items.Count, Converter={StaticResource IntToBoolConverter}}"
            ItemsSource="{Binding Items}">
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <Frame>
                        <Label Text="{Binding}" />
                    </Frame>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>

        <!--  Does not work 👎  -->
        <CollectionView
            x:Name="ItemsView3"
            Grid.Row="2"
            ItemsSource="{Binding Items}">
            <View.Triggers>
                <DataTrigger
                    Binding="{Binding Items.Count}"
                    TargetType="View"
                    Value="0">
                    <Setter Property="IsVisible" Value="False" />
                </DataTrigger>
            </View.Triggers>
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <Frame>
                        <Label Text="{Binding}" />
                    </Frame>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>
    </Grid>

Expected Behavior

Should display items after visibility is changed to true.

Actual Behavior

No items displayed.

Basic Information

  • Version with issue: 4.8.0.1821
  • Last known good version: 4.8.0.1687
  • Platform Target Frameworks:
    • iOS: 14.2

Workaround

N/A (probably can toggle via code behind)

Repro link

Repeo: Issue13203v2.zip

@dmariogatto dmariogatto added s/unverified New report that has yet to be verified t/bug 🐛 labels Jan 26, 2021
@rmarinho rmarinho added the i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often label Jan 27, 2021
@rmarinho rmarinho added blocker Issue blocks next stable release. Prioritize fixing and reviewing this issue. and removed s/unverified New report that has yet to be verified labels Jan 27, 2021
@AlleSchonWeg
Copy link
Contributor

AlleSchonWeg commented Jan 27, 2021

@dmariogatto
Is the CollectionView displaying items, if you insert a space somewhere in xaml and save it while the app is running?

@dmariogatto
Copy link
Contributor Author

I made a mistake in the repro project, that first CollectionView should have IsVisible="False" , which means it no longer works as expected (IsVisible="True" is set in the code behind after binding items, so pretty much the same as #13203).

@AlleSchonWeg
If I trigger a hot reload, the bottom two collections display correctly.

@AlleSchonWeg
Copy link
Contributor

If I trigger a hot reload, the bottom two collections display correctly.

I had the same problem. A litte delay helps me to workaround this issue: #13203 (comment)

@Deepfreezed
Copy link

Deepfreezed commented Jan 28, 2021

I am having the same issue on iOS. Using version 5.0.0.1931.

Here are the other scenarios where CollectionView fails to update or disappears:

  • CollectionView disappears if I change visibility state of another element that is in the same container.

  • In the viewmodel if I initially set the databinding to empty, then subsequently populate the databinding, CollectionView remains empty

@developer9969
Copy link

Hi everyone, just managed to upgrade to XF5 and went through quite an excercise to find out that we have this visibility issue on the collectionView when we use the "IsVisible" flag to us is a showstopper and I might have to revert to 4.8 unless there is a workaround. Does anyone know if this is been looked at and planned for next service release?

@Tommigun1980
Copy link

Hi everyone, just managed to upgrade to XF5 and went through quite an excercise to find out that we have this visibility issue on the collectionView when we use the "IsVisible" flag to us is a showstopper and I might have to revert to 4.8 unless there is a workaround. Does anyone know if this is been looked at and planned for next service release?

@developer9969 I found one workaround to the IsVisible bug (#13548), but it can be cumbersome to implement in certain places. But maybe it can help even a tiny bit?

@hartez hartez added the in-progress This issue has an associated pull request that may resolve it! label Feb 1, 2021
@developer9969
Copy link

@Tommigun1980 hi there thanks for your reply and suggestion
If I can avoid reverting to 4.8 and have a temporary workround that woud be great,currently my ItemSource is set in xaml with binding in View Model.

So somewhow I have to do below in my View CodeBehind, right?

var items = this.myCollectionView.ItemsSource;
this.myCollectionView.ItemsSource = null;
this.myCollectionView.ItemsSource = items;

Just hope they do a service release very soon as this breaks at least 10 pages in my app.

@Tommigun1980
Copy link

Tommigun1980 commented Feb 2, 2021

@Tommigun1980 hi there thanks for your reply and suggestion
If I can avoid reverting to 4.8 and have a temporary workround that woud be great,currently my ItemSource is set in xaml with binding in View Model.

So somewhow I have to do below in my View CodeBehind, right?

var items = this.myCollectionView.ItemsSource;
this.myCollectionView.ItemsSource = null;
this.myCollectionView.ItemsSource = items;

Just hope they do a service release very soon as this breaks at least 10 pages in my app.

Hi. I’m also hoping for a fix and Hartez seems to just have committed one so that’s good.

But in the interim yeah, you could try setting the ItemsSource to null and back to the value after toggling IsVisible. I am not 100% sure if the hack applies to this case as well, but I suspect these issues may be related as they all are very similar and started to happen in XF5 so it’s probably worth a try.
In my case force re-setting the ItemsSource in the code-behind circumvents the problem, it’s not elegant or performant but at least it works.

And I hope Hartez’s fix solves #13548 as well.

@Eltee-Taiwo
Copy link

@Tommigun1980 hi there thanks for your reply and suggestion
If I can avoid reverting to 4.8 and have a temporary workround that woud be great,currently my ItemSource is set in xaml with binding in View Model.
So somewhow I have to do below in my View CodeBehind, right?

var items = this.myCollectionView.ItemsSource;
this.myCollectionView.ItemsSource = null;
this.myCollectionView.ItemsSource = items;

Just hope they do a service release very soon as this breaks at least 10 pages in my app.

Hi. I’m also hoping for a fix and Hartez seems to just have committed one so that’s good.

But in the interim yeah, you could try setting the ItemsSource to null and back to the value after toggling IsVisible. I am not 100% sure if the hack applies to this case as well, but I suspect these issues may be related as they all are very similar and started to happen in XF5 so it’s probably worth a try.
In my case force re-setting the ItemsSource in the code-behind circumvents the problem, it’s not elegant or performant but at least it works.

And I hope Hartez’s fix solves #13548 as well.

One more note on this, in my case I had to add delays between setting it to null and adding the new values for the UI to catch up. Hopefully that helps someone too until we hear back back from someone on when to expect a fix for this.

var items = this.myCollectionView.ItemsSource;
this.myCollectionView.ItemsSource = null;
await Task.Delay(100); //I tried 10 and 1 but they didn't work for me
this.myCollectionView.ItemsSource = items;
await Task.Delay(100);

PureWeen pushed a commit that referenced this issue Feb 5, 2021
* Move layout change resolution call up to VisualElement
Fixes #13418
Fixes #13492

* Signal layout request when CollectionView is in a layout
Fixes #13551

* Fix layout error loop from test 12714

* Fix autolayout issues when CollectionView size is less than span;

* Provide measurement for default text cells (no ItemTemplate);

* Cleanup
@rd09
Copy link

rd09 commented Feb 12, 2021

I am experiencing the same issue on version 4.8.0.1821. I have a CollectionView that has IsVisible set to false initially and the bound ItemSource is set. Then when IsVisible is set to true through binding nothing is displayed. My work around is to switch the CollectionView back to a ListView.

@Huaba93
Copy link

Huaba93 commented Aug 30, 2021

@jfversluis @davidortinau could you please fix this in the upcoming SR? Still an issue that needs really ugly workarounds

@jfversluis
Copy link
Member

@Huaba93 does #14384 have anything to do with this by any chance?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/collectionview blocker Issue blocks next stable release. Prioritize fixing and reviewing this issue. i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often in-progress This issue has an associated pull request that may resolve it! p/iOS 🍎 t/bug 🐛
Projects
None yet