/// <summary>
        /// Ons the element changed.
        /// </summary>
        /// <param name="e">E.</param>
        protected override void OnElementChanged(ElementChangedEventArgs <SettingsView> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                // Fix scrollbar visibility and flash. https://github.com/xamarin/Xamarin.Forms/pull/10893
                var recyclerView = new RecyclerView(new ContextThemeWrapper(Context, Resource.Style.settingsViewTheme), null, Resource.Attribute.settingsViewStyle);
                recyclerView.NestedScrollingEnabled = false;

                // When replaced, No animation.
                //(recyclerView.GetItemAnimator() as DefaultItemAnimator).SupportsChangeAnimations = false;

                _layoutManager = new SettingsViewLayoutManager(Context, e.NewElement);
                recyclerView.SetLayoutManager(_layoutManager);

                _divider        = Context.GetDrawable(Resource.Drawable.divider);
                _itemDecoration = new SVItemdecoration(_divider, e.NewElement);
                recyclerView.AddItemDecoration(_itemDecoration);

                SetNativeControl(recyclerView);

                Control.Focusable = false;
                Control.DescendantFocusability = DescendantFocusability.AfterDescendants;

                UpdateSeparatorColor();
                UpdateBackgroundColor();
                UpdateRowHeight();

                _adapter = new SettingsViewRecyclerAdapter(Context, e.NewElement, recyclerView);
                Control.SetAdapter(_adapter);

                _simpleCallback  = new SettingsViewSimpleCallback(e.NewElement, ItemTouchHelper.Up | ItemTouchHelper.Down, 0);
                _itemTouchhelper = new ItemTouchHelper(_simpleCallback);
                _itemTouchhelper.AttachToRecyclerView(Control);

                Element elm = Element;
                while (elm != null)
                {
                    elm = elm.Parent;
                    if (elm is Page)
                    {
                        break;
                    }
                }

                _parentPage            = elm as Page;
                _parentPage.Appearing += ParentPageAppearing;

                e.NewElement.Root.CollectionChanged += RootCollectionChanged;
            }
        }
        /// <summary>
        /// Dispose the specified disposing.
        /// </summary>
        /// <returns>The dispose.</returns>
        /// <param name="disposing">If set to <c>true</c> disposing.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                foreach (var section in Element.Root)
                {
                    if (section.HeaderView != null)
                    {
                        DisposeChildRenderer(section.HeaderView);
                    }
                    if (section.FooterView != null)
                    {
                        DisposeChildRenderer(section.FooterView);
                    }
                }

                foreach (var renderer in _shouldDisposeRenderers)
                {
                    if (renderer.View.Handle != IntPtr.Zero)
                    {
                        renderer.View.RemoveFromParent();
                        renderer.View.Dispose();
                    }
                    renderer.Dispose();
                }
                _shouldDisposeRenderers.Clear();
                _shouldDisposeRenderers = null;

                Control.RemoveItemDecoration(_itemDecoration);
                _parentPage.Appearing -= ParentPageAppearing;
                _adapter?.Dispose();
                _adapter = null;
                _layoutManager?.Dispose();
                _layoutManager = null;
                _simpleCallback?.Dispose();
                _simpleCallback = null;
                _itemTouchhelper?.Dispose();
                _itemTouchhelper = null;

                _itemDecoration?.Dispose();
                _itemDecoration = null;
                _divider?.Dispose();
                _divider = null;

                Element.Root.CollectionChanged -= RootCollectionChanged;
            }
            base.Dispose(disposing);
        }
Esempio n. 3
0
 /// <summary>
 /// Dispose the specified disposing.
 /// </summary>
 /// <returns>The dispose.</returns>
 /// <param name="disposing">If set to <c>true</c> disposing.</param>
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         _parentPage.Appearing -= ParentPageAppearing;
         _adapter?.Dispose();
         _adapter = null;
         _layoutManager?.Dispose();
         _layoutManager = null;
         _simpleCallback?.Dispose();
         _simpleCallback = null;
         _itemTouchhelper?.Dispose();
         _itemTouchhelper = null;
     }
     base.Dispose(disposing);
 }
        /// <summary>
        /// Ons the element changed.
        /// </summary>
        /// <param name="e">E.</param>
        protected override void OnElementChanged(ElementChangedEventArgs <SettingsView> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                var recyclerView = new RecyclerView(Context);
                _layoutManager = new SettingsViewLayoutManager(Context, e.NewElement);
                recyclerView.SetLayoutManager(_layoutManager);

                _divider        = Context.GetDrawable(Resource.Drawable.divider);
                _itemDecoration = new SVItemdecoration(_divider, e.NewElement);
                recyclerView.AddItemDecoration(_itemDecoration);

                SetNativeControl(recyclerView);

                Control.Focusable = false;
                Control.DescendantFocusability = DescendantFocusability.AfterDescendants;

                UpdateSeparatorColor();
                UpdateBackgroundColor();
                UpdateRowHeight();

                _adapter = new SettingsViewRecyclerAdapter(Context, e.NewElement, recyclerView);
                Control.SetAdapter(_adapter);

                _simpleCallback  = new SettingsViewSimpleCallback(e.NewElement, ItemTouchHelper.Up | ItemTouchHelper.Down, 0);
                _itemTouchhelper = new ItemTouchHelper(_simpleCallback);
                _itemTouchhelper.AttachToRecyclerView(Control);

                Element elm = Element;
                while (elm != null)
                {
                    elm = elm.Parent;
                    if (elm is Page)
                    {
                        break;
                    }
                }

                _parentPage            = elm as Page;
                _parentPage.Appearing += ParentPageAppearing;

                e.NewElement.Root.CollectionChanged += RootCollectionChanged;
            }
        }