Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScrollView.Content is not re-layouted on Android #2595

Closed
rodja opened this issue May 3, 2018 · 1 comment

Comments

@rodja
Copy link

commented May 3, 2018

Description

When changing Views inside of a ScrollView they are not updated properly on Android.

Steps to Reproduce

This example is a good way to reproduce the issue. Swipe in the menu to switch to the broken pages:

public class App : Application {
    public App() {
        MainPage = new MasterDetailPage {
            Master = new ContentPage {
                Title = "Menu",
                Content = new StackLayout {
                    Children = {
                        new Button { Text = "Broken ScrollView", Command = new Command(obj => Open(new ScrollPage())) },
                        new Button { Text = "Fixed Label on ScrollView", Command = new Command(obj => Open(new FixedLabelOnScrollPage())) },
                        new Button { Text = "Fully Fixed ScrollView", Command = new Command(obj => Open(new FixedScrollPage())) },
                    },
                },
            },
            Detail = new FixedScrollPage(),
        };
    }

    void Open(ContentPage page) {
        (MainPage as MasterDetailPage).Detail = page;
        (MainPage as MasterDetailPage).IsPresented = false;
    }
}

public class FixedScrollPage : ScrollPage {
    protected override async void OnAppearing() {
        await Task.Delay(1);
        var content = ScrollContent;
        ScrollContent = null;
        ScrollContent = content;
        base.OnAppearing();
    }
}

public class FixedLabelOnScrollPage : ScrollPage {
    public FixedLabelOnScrollPage() {
        Label.HorizontalOptions = LayoutOptions.Fill;
    }

}

public class ScrollPage : ContentPage {
    Timer timer = new Timer(1000);
    protected Label Label;

    public ScrollPage() {
        Content = new ScrollView {
            Content = new StackLayout {
                Children = {
                    (Label = new Label {
                        Text = "this text should disappear after 1 sec",
                        BackgroundColor = Color.LightBlue,
                        HorizontalOptions = LayoutOptions.StartAndExpand,
                    })
                }
            }
        };
    }

    protected StackLayout ScrollContent {
        get => (Content as ScrollView).Content as StackLayout;
        set => (Content as ScrollView).Content = value;
    }

    protected override void OnAppearing() {
        base.OnAppearing();
        timer.Elapsed += (s, e) => Device.BeginInvokeOnMainThread(OnTimerElapsed);

        timer.Start();
    }

    void OnTimerElapsed() {
        Label.Text = $"{ DateTime.Now.ToString() }: expecting {ScrollContent?.Children.Count} dates to show up.";
        ScrollContent.Children.Add(new Label { Text = DateTime.Now.ToString() });
    }
}

Expected Behavior

When changing Label.Text or adding children to an StackLayout inside of an ScrollView we should see it.

Actual Behavior

The new content is not visible.

Basic Information

  • Version with issue: Xamrin.Forms 3.0.0
  • Last known good version: ?
  • IDE: Visual Studio 7.3.3
  • Platform Target Frameworks:
    • Android: 8.0
  • Android Support Library Version: 25.4
  • Affected Devices: all

@pauldipietro pauldipietro added this to New in Triage May 3, 2018

@hartez

This comment has been minimized.

Copy link
Member

commented May 3, 2018

This may be a duplicate of #1760.

@hartez hartez self-assigned this May 3, 2018

@hartez hartez moved this from New to Ready For Work in Triage May 3, 2018

@samhouts samhouts added this to In Progress in v3.1.0 May 8, 2018

rmarinho added a commit that referenced this issue May 10, 2018
Merge pull request #2635 from xamarin/gh-1760 fixes #1760 fixes #2595 f…
…ixes #1332

[Android] Force ScrollView layout when changing ContentView content

@samhouts samhouts moved this from In Progress to Done in v3.1.0 May 10, 2018

Triage automation moved this from Ready For Work to Closed May 14, 2018

@samhouts samhouts removed this from Closed in Triage Jun 13, 2018

@samhouts samhouts added this to To do in Sprint 146 Dec 15, 2018

@samhouts samhouts moved this from To do to Done in Sprint 146 Dec 15, 2018

@samhouts samhouts added this to To do in Sprint 147 Jan 9, 2019

@samhouts samhouts moved this from To do to Done in Sprint 147 Jan 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
2 participants
You can’t perform that action at this time.