jamesmontemagno / Xamarin.Forms-PullToRefreshLayout

Pull To Refresh a ScrollView or ListView in Xamarin.Forms
218 stars 49 forks source link

Changing PullToRefreshLayout.Content in RefreshCommand does render a white page #36

Closed bacheric closed 6 years ago

bacheric commented 6 years ago

Hi, I want to use PullToRefresh in a scrollview. I have a RefreshCommand which replaces the PullToRefreshLayouts' Content with some other content. Whatever I do, the content is not rendered properly and just a white page is appearing. I could reproduce it in the sample project with this ScrollViewPage.cs:

namespace RefreshSample.Views
{
    public class ScrollViewPage : ContentPage
    {
        PullToRefreshLayout refreshView;
        private void doStuff()
        {
            StackLayout testStack = new StackLayout();
            testStack.BackgroundColor = Color.Green;
            testStack.VerticalOptions = LayoutOptions.FillAndExpand;
            Label a = new Label();
            a.Text = "rw3rsr33";
            testStack.Children.Add(a);
            refreshView.IsRefreshing = false;
            refreshView.Content = testStack;
         }
        public ScrollViewPage(bool insideLayout)
        {
            var random = new Random();
            Title = "ScrollView (Pull to Refresh)";

            BindingContext = new TestViewModel (this);

            var grid = new Grid
                {
                    VerticalOptions = LayoutOptions.FillAndExpand,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    RowSpacing = 0,
                    ColumnSpacing = 0
                };            
            var scrollView = new ScrollView
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                    Content = grid
            };
            for (int i = 0; i < 20; i++)
            {
                grid.ColumnDefinitions.Add(new ColumnDefinition{ Width = GridLength.Auto });
                for (int j = 0; j < 20; j++)
                {

                    if (i == 0)
                    {
                        grid.RowDefinitions.Add(new RowDefinition{ Height = GridLength.Auto });

                    }

                    grid.Children.Add(new BoxView
                        {
                            HeightRequest = 50,
                            VerticalOptions = LayoutOptions.FillAndExpand,
                            HorizontalOptions = LayoutOptions.FillAndExpand,
                            BackgroundColor = Color.FromRgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255))
                        }, i, j);
                }

            }

            Command command = new Command(doStuff);
            refreshView = new PullToRefreshLayout {
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Content = scrollView,
                RefreshColor = Color.FromHex("#3498db"),
                RefreshCommand = command
            };

            refreshView.SetBinding<TestViewModel> (PullToRefreshLayout.IsRefreshingProperty, vm => vm.IsBusy, BindingMode.OneWay);
            //refreshView.SetBinding<TestViewModel>(PullToRefreshLayout.RefreshCommandProperty, vm => vm.RefreshCommand);

//No changes afterwards

To my understanding this should display a green page with a label in it, after doing a Pull-To-Refresh, however it just shows a blank white page. This happens in my "real" project, too. When using UISleuth there, it tells me that all the elements are "there", they are just not rendered. I am using Android and can't test this on iOS, so I don't know if it works there.

jamesmontemagno commented 6 years ago

Download the project it has samples and works great.

ParticularPhil commented 6 years ago

Hi James,

I'm having the same problem as Eric – the samples don't cover changing the page's content within the refresh command. My code is based on the sample (and I think this is true for Eric's code as well), but we're both altering the page content within the command.

I'm also getting a white page – is this a known issue?

Thank you Phil

bacheric commented 6 years ago

Hi James, could you please reopen the issue? I did not find a solution to fix the issue yet.

mwkoehler commented 5 years ago

Late to this, but I ran into it with 2.4.1.1-beta

I tracked it down to an async call to a rest api that I was issuing before setting App.MainPage.

The non-rendering bug clears if I either comment out the async call or comment out the pulltorefresh xaml.

For now I have worked around this by delaying the api call until after the form loads.

I have no idea how that async call combined with this nuget triggers this bug.

manisha787 commented 5 years ago

Its not working in ios