public static IDisposable SubscribeOnScrollEnd(this MvxRecyclerView recyclerView, IMvxAsyncCommand loadElements, Func <bool> canExecute)
        {
            var propertyChanged = Observable.FromEventPattern <EventHandler <View.ScrollChangeEventArgs>, View.ScrollChangeEventArgs>(
                h => recyclerView.ScrollChange += h, h => recyclerView.ScrollChange -= h);

            return(propertyChanged
                   .Select(_ => recyclerView.GetLayoutManager() as LinearLayoutManager ??
                           recyclerView.GetLayoutManager() as GridLayoutManager)
                   .Where(lm => lm != null && canExecute() &&
                          (lm.StackFromEnd
                                 ? lm.FindFirstVisibleItemPosition() <= 10
                                 : lm.FindFirstVisibleItemPosition() + lm.ChildCount >= lm.ItemCount - 10))
                   .Throttle(TimeSpan.FromMilliseconds(100))
                   .ObserveOn(Application.SynchronizationContext)
                   .Subscribe(
                       async _ => await loadElements.ExecuteAsync(),
                       exception =>
                       Mvx.Resolve <IToastSerivce>().ShowByResourceId(exception.Message)));
        }
Ejemplo n.º 2
0
        public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            ViewModel.PropertyChanged += (o, e) =>
            {
                if (e.PropertyName == nameof(ViewModel.ChatMessages) && ViewModel.ChatMessages?.Count > 0)
                {
                    var _scroller = new ToEndSmoothScroller(Android.App.Application.Context);
                    _scroller.TargetPosition = ViewModel.ChatMessages.Count - 1;
                    _chatListView.GetLayoutManager().StartSmoothScroll(_scroller);
                }
            };
        }