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 bind to items if IsVisible=False #13203

Closed
dmariogatto opened this issue Dec 20, 2020 · 16 comments
Closed

[Bug] [iOS] CollectionView does not bind to items if IsVisible=False #13203

dmariogatto opened this issue Dec 20, 2020 · 16 comments
Assignees
Labels
4.8.0 regression on 4.8.0 a/binding ⛓ a/collectionview blocker Issue blocks next stable release. Prioritize fixing and reviewing this issue. e/3 🕒 3 i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often i/regression in-progress This issue has an associated pull request that may resolve it! p/iOS 🍎 t/bug 🐛
Milestone

Comments

@dmariogatto
Copy link
Contributor

dmariogatto commented Dec 20, 2020

Description

Bind CollectionView to an item source while not visible (i.e. IsVisible="False"), then change visibility to true, no items in the list.

Steps to Reproduce

using System.Collections.Generic;
using Xamarin.Forms;

namespace CollectionViewBrokenAgain
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
            BindingContext = this;
        }

        public List<int> Items { get; } = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

        protected override void OnAppearing()
        {
            base.OnAppearing();
           // CollectionView is bound to Items, but will be empty if visibility was initially set to false
            ItemsView.IsVisible = true;
        }
    }
}
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    x:Class="CollectionViewBrokenAgain.MainPage"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

    <CollectionView
        x:Name="ItemsView"
        IsVisible="False"
        ItemsSource="{Binding Items}">
        <CollectionView.ItemTemplate>
            <DataTemplate>
                <Frame>
                    <Label Text="{Binding}" />
                </Frame>
            </DataTemplate>
        </CollectionView.ItemTemplate>
    </CollectionView>

</ContentPage>

Expected Behavior

Should should items after visibilty 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

Can wrap CollectionView in a ContentView, and toggle the visibility on that instead.

Repro link

Repro: Issue13203.zip

@dmariogatto dmariogatto added s/unverified New report that has yet to be verified t/bug 🐛 labels Dec 20, 2020
@samhouts samhouts added this to New in Triage Dec 20, 2020
@rachelkang rachelkang added 4.8.0 regression on 4.8.0 a/collectionview i/regression p/iOS 🍎 a/binding ⛓ e/3 🕒 3 and removed s/unverified New report that has yet to be verified labels Dec 21, 2020
@rachelkang rachelkang moved this from New to Ready For Work in Triage Dec 21, 2020
@sawankumarbundelkhandi
Copy link

@rachelkang @dmariogatto same is happening with CarouselView.

@Tommigun1980
Copy link

Tommigun1980 commented Dec 26, 2020

This is the same issue as #13126, and also bugs 1 and 2 in the repro project at #13231.

The only workaround I found was to downgrade to XF 5.0.0-pre4 as this regression was introduced in 5.0.0-pre5 (and is still there in pre6), in case someone is using XF 5.

@AlleSchonWeg
Copy link
Contributor

AlleSchonWeg commented Jan 5, 2021

Hi,
i think i run into a similar issue with version 4.8.0.1560. Wrapping the collectionView inside a ContentView doesn't work for me. I have bind the IsVisible property to my model:
IsVisible="{Binding Show}"
After loading the items i set Show=true. On android it works as expected. But on ios i the CollectionView is empty. But i found a workaround. I created a Task without await (because i want no await) but with a little delay:

protected override async void OnAppearing() {
  base.OnAppearing();
  //Other code
  _ = Task.Run(async() => {
	 await Task.Delay(100);
	 var vm = (Model)BindingContext;
	 vm.Show= true;
 });
}

@Tommigun1980
Copy link

Hi,
i think i run into a similar issue with version 4.8.0.1560. Wrapping the collectionView inside a ContentView doesn't work for my. I have bind the IsVisible property to my model:
IsVisible="{Binding Show}"
After loading the items i set Show=true. On android it works as expected. But on ios i the CollectionView is empty. But i found a workaround. I created a Task without await (because i want no await) but with a little delay:

protected override async void OnAppearing() {
  base.OnAppearing();
  //Other code
  _ = Task.Run(async() => {
	 await Task.Delay(100);
	 var vm = (Model)BindingContext;
	 vm.Show= true;
 });
}

Hi @AlleSchonWeg, the problem with those delays is that its length is dependent on the amount of content and the speed of the device. So what works on one device or collection won’t work on another, so I’d discourage from using one.

@AlleSchonWeg
Copy link
Contributor

Hi,
i think i run into a similar issue with version 4.8.0.1560. Wrapping the collectionView inside a ContentView doesn't work for my. I have bind the IsVisible property to my model:
IsVisible="{Binding Show}"
After loading the items i set Show=true. On android it works as expected. But on ios i the CollectionView is empty. But i found a workaround. I created a Task without await (because i want no await) but with a little delay:

protected override async void OnAppearing() {
  base.OnAppearing();
  //Other code
  _ = Task.Run(async() => {
	 await Task.Delay(100);
	 var vm = (Model)BindingContext;
	 vm.Show= true;
 });
}

Hi @AlleSchonWeg, the problem with those delays is that its length is dependent on the amount of content and the speed of the device. So what works on one device or collection won’t work on another, so I’d discourage from using one.

Sure,
this is not a perfect workaround. I only want to share it and perhaps it gives others a hint to workaround their issues. But XF has so many bugs, we have to deal with workarounds every day. Especially CollectionView.

@mahesh139
Copy link

This is the same issue as #13126, and also bugs 1 and 2 in the repro project at #13231.

The only workaround I found was to downgrade to XF 5.0.0-pre4 as this regression was introduced in 5.0.0-pre5 (and is still there in pre6), in case someone is using XF 5.

same issue on stable release XF 5 (5.0.0.1874)

@Tommigun1980
Copy link

Tommigun1980 commented Jan 8, 2021

This is a fatal regression, so is there any chance this could be fixed soon?

Repros at #13126 (comment) and #13231, where the latter exposes more regressions related to this that would be great if were fixed at the same time.

Thanks!

@hartez hartez added this to Backlog in CollectionView via automation Jan 8, 2021
@hartez hartez removed this from Ready For Work in Triage Jan 8, 2021
@hartez hartez self-assigned this Jan 8, 2021
@hartez hartez added the i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often label Jan 8, 2021
@hartez hartez modified the milestones: 4.8.0, 5.0.0 Jan 8, 2021
@hartez hartez added the blocker Issue blocks next stable release. Prioritize fixing and reviewing this issue. label Jan 8, 2021
@hartez hartez added this to To do in vNext+1 (5.0.0) via automation Jan 8, 2021
@hartez hartez added the in-progress This issue has an associated pull request that may resolve it! label Jan 12, 2021
@hartez hartez moved this from To do to In Review in vNext+1 (5.0.0) Jan 12, 2021
@hartez hartez moved this from Backlog to In Review in CollectionView Jan 12, 2021
@rmarinho rmarinho moved this from In Review to In Progress in vNext+1 (5.0.0) Jan 12, 2021
CollectionView automation moved this from In Review to Done Jan 18, 2021
vNext+1 (5.0.0) automation moved this from In Progress to Done Jan 18, 2021
@Tommigun1980
Copy link

Hi @rmarinho. I tested with the latest nightly build of XF and this issue still happens. Is the fix not in the nightly build yet?

Thank you.

@dmariogatto
Copy link
Contributor Author

@Tommigun1980 I think it was only just merged into 5.0. So probably not in the nightly yet.

@Tommigun1980
Copy link

@dmariogatto It was committed four days ago to the 5.0.0 branch (c419953). I tested with the latest nightly again and it's not fixed. I have provided two different repro cases for this issue.

@rmarinho @hartez Is the fix supposed to be in the latest nightly?

Thank you.

@dmariogatto
Copy link
Contributor Author

@Tommigun1980 @rmarinho @hartez @rachelkang

Don't think this one is completely fixed for all scenarios, see #13551.

@developer9969
Copy link

developer9969 commented Feb 1, 2021

@rmarinho Hi tested this against 5.0.0.1931 and this is still an issue as collectionView does not show the first time round.

@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.

@amritpa9
Copy link

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.

i am also facing same issue, i also tried Listview but this issue still appearing on IOS , have you found any solution ?

@Sasha111ua
Copy link

Sasha111ua commented Mar 9, 2021

protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs changedProperty)
{
base.OnElementPropertyChanged(sender, changedProperty);
if (changedProperty.PropertyName == "IsVisible")
{
if (Element.IsVisible)
{
Element.Layout(NativeView.Frame.ToRectangle());
}
}
}

this helped me`

or a combination of
InputTransparent="True"
Opacity="0"

@zleao
Copy link

zleao commented Jan 25, 2023

I confirm that this is still happening on XF 5.0.0.2545 :(

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

No branches or pull requests