Xamarin Forms - Hide navigation bar on custom list view scroll

I have a custom listview on a page and I want to be able to show or hide the nav bar as I scroll the custom listview in Android.

In the android listview adapter GetView() method I can get the current item position and last position to determine whether I need to show or hide, but I'm unable to access the nav bar to do this.

Custom listview
public class NativeResultsListView : ListView
{
public static readonly BindableProperty ItemsProperty =
BindableProperty.Create("Items", typeof(IEnumerable), typeof(NativeResultsListView), new List());

                                public NativeResultsListView(ListViewCachingStrategy strategy) : base (strategy)
                                {     
                                }

                            public IEnumerable<Result> Items
                            {
                                get { return (IEnumerable<Result>)GetValue(ItemsProperty); }
                                set { SetValue(ItemsProperty, value); }
                            }

                            public event EventHandler<SelectedItemChangedEventArgs> ItemSelected;

                            public void NotifyItemSelected(object item)
                            {
                                ItemSelected?.Invoke(this, new SelectedItemChangedEventArgs(item));
                            }

                            public event EventHandler<ItemVisibilityEventArgs> ItemAppearing;

                            public void NotifyItemAppearing(object item)
                            {
                                ItemAppearing?.Invoke(this, new ItemVisibilityEventArgs(item));
                            }
                        }

Custom listview renderer
public class NativeResultsListView : ListView
{
public static readonly BindableProperty ItemsProperty =
BindableProperty.Create("Items", typeof(IEnumerable), typeof(NativeResultsListView), new List());

                        public NativeResultsListView(ListViewCachingStrategy strategy) : base (strategy)
                        {     
                        }

                        public IEnumerable<Result> Items
                        {
                            get { return (IEnumerable<Result>)GetValue(ItemsProperty); }
                            set { SetValue(ItemsProperty, value); }
                        }

                        public event EventHandler<SelectedItemChangedEventArgs> ItemSelected;

                        public void NotifyItemSelected(object item)
                        {
                            ItemSelected?.Invoke(this, new SelectedItemChangedEventArgs(item));
                        }

                        public event EventHandler<ItemVisibilityEventArgs> ItemAppearing;

                        public void NotifyItemAppearing(object item)
                        {
                            ItemAppearing?.Invoke(this, new ItemVisibilityEventArgs(item));
                        }
                    }

GetView() in Adapter
public override View GetView(int position, View convertView, ViewGroup parent)
{
var item = tableItems[position];

                            ResultViewHolder resultViewHolder = null;

                            var view = convertView;
                            if (view != null)
                            {
                                // Gets a reference to the ViewHolder instance which was assigned to the view which is being recycled
                                resultViewHolder = view.Tag as ResultViewHolder;
                            }

                            // Setup a value holder so we the use of FindViewById and view inflations.
                            if (resultViewHolder == null)
                            {
                                // no view to re-use, create new
                                view = context.LayoutInflater.Inflate(Resource.Layout.AndroidResultsListViewCell, null);
                                resultViewHolder = PopulateResultViewHolder(view);
                                view.Tag = resultViewHolder;
                            }

                            // Set values on  holder
                            resultViewHolder.Name.Text = item.Name;
                            resultViewHolder.Author.Text = item.Author;
                            resultViewHolder.Rating.Rating = Convert.ToSingle(item.Rating);
                            resultViewHolder.Distance.Text = item.Distance.ToString() + " km";
                            resultViewHolder.ReviewCount.Text = item.ReviewCount + " reviews";
                            resultViewHolder.Price.Text = item.Downloaded ? "DOWNLOADED" : item.Price;

                            // Main image
                            DisplayImage(resultViewHolder.Image, view, item);

                            // Official owner medal
                            DisplayImage(resultViewHolder.OfficialOwner, view, item);

                            return view;
                        }

Answers

Sign In or Register to comment.