Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

iOS UITableView custom renderer ScrollToBottom w/ animate always wrong unless I add a 100ms delay

$
0
0

In my iOS customer renderer for a ListView I set a boolean _scrollToBottom to true and then it gets updated here. (Maybe this is the wrong place to do this?)
But if I want to animate the bottom of the table is always slightly wrong by like 20 pixels or so. If I Wait 100ms like shown it works perfect. What's the proper way to do this without the 100ms wait?

public class MyListViewRenderer : ViewRenderer<MyListView, UITableView>

public override void LayoutSubviews()
        {
            base.LayoutSubviews();

            Task.Run(() =>
            {
                if (_scrollToBottom)
                {
                    Task.Delay(100).Wait();
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        var tableView = Control;
                        // Scroll to bottom
                        if (tableView.ContentSize.Height > tableView.Frame.Height)
                        {
                            var rowCount = tableView.NumberOfRowsInSection(0);
                            if (rowCount > 0)
                            {
                                tableView.ScrollToRow(MonoTouch.Foundation.NSIndexPath.FromRowSection(rowCount - 1, 0),
                                    UITableViewScrollPosition.Bottom, true);
                            }
                        }
                        _scrollToBottom = false;
                    });
                });
             }
        }

Viewing all articles
Browse latest Browse all 58056

Trending Articles