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

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

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

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

rodja opened this issue May 3, 2018 · 1 comment

Comments

@rodja
Copy link

rodja 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
@hartez
Copy link
Contributor

hartez commented May 3, 2018

This may be a duplicate of #1760.

@hartez hartez self-assigned this May 3, 2018
rmarinho added a commit that referenced this issue May 10, 2018
…ixes #1332

[Android] Force ScrollView layout when changing ContentView content
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants