예제 #1
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            if (disposing)
            {
                Device.Info.PropertyChanged -= DeviceInfoPropertyChanged;

                if (Element != null)
                {
                    MasterDetailPageController.BackButtonPressed -= OnBackButtonPressed;
                    Element.PropertyChanged -= HandlePropertyChanged;
                    Element.Appearing       -= MasterDetailPageAppearing;
                    Element.Disappearing    -= MasterDetailPageDisappearing;
                }

                if (_masterLayout?.ChildView != null)
                {
                    _masterLayout.ChildView.PropertyChanged -= HandleMasterPropertyChanged;
                }

                if (!this.IsDisposed())
                {
                    RemoveDrawerListener(this);
                }

                if (_tracker != null)
                {
                    _tracker.Dispose();
                    _tracker = null;
                }

                if (_detailLayout != null)
                {
                    RemoveView(_detailLayout);
                    _detailLayout.Dispose();
                    _detailLayout = null;
                }

                if (_masterLayout != null)
                {
                    RemoveView(_masterLayout);
                    _masterLayout.Dispose();
                    _masterLayout = null;
                }

                if (Element != null)
                {
                    Element.ClearValue(Android.Platform.RendererProperty);
                    Element = null;
                }
            }

            base.Dispose(disposing);
        }
예제 #2
0
        void IVisualElementRenderer.SetElement(VisualElement element)
        {
            MasterDetailPage oldElement = Element;
            MasterDetailPage newElement = Element = element as MasterDetailPage;

            if (oldElement != null)
            {
                Device.Info.PropertyChanged -= DeviceInfoPropertyChanged;

                ((IMasterDetailPageController)oldElement).BackButtonPressed -= OnBackButtonPressed;

                oldElement.PropertyChanged -= HandlePropertyChanged;
                oldElement.Appearing       -= MasterDetailPageAppearing;
                oldElement.Disappearing    -= MasterDetailPageDisappearing;

                RemoveDrawerListener(this);

                if (_detailLayout != null)
                {
                    RemoveView(_detailLayout);
                }

                if (_masterLayout != null)
                {
                    RemoveView(_masterLayout);
                }
            }

            if (newElement != null)
            {
                if (_detailLayout == null)
                {
                    _detailLayout = new MasterDetailContainer(newElement, false, Context)
                    {
                        LayoutParameters = new LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)
                    };

                    _masterLayout = new MasterDetailContainer(newElement, true, Context)
                    {
                        LayoutParameters = new LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)
                        {
                            Gravity = (int)GravityFlags.Start
                        }
                    };

                    if (_fragmentManager != null)
                    {
                        _detailLayout.SetFragmentManager(_fragmentManager);
                        _masterLayout.SetFragmentManager(_fragmentManager);
                    }

                    AddView(_detailLayout);
                    AddView(_masterLayout);

                    Device.Info.PropertyChanged += DeviceInfoPropertyChanged;

                    AddDrawerListener(this);
                }

                UpdateBackgroundColor(newElement);
                UpdateBackgroundImage(newElement);

                UpdateMaster();
                UpdateDetail();

                UpdateFlowDirection();

                ((IMasterDetailPageController)newElement).BackButtonPressed += OnBackButtonPressed;
                newElement.PropertyChanged += HandlePropertyChanged;
                newElement.Appearing       += MasterDetailPageAppearing;
                newElement.Disappearing    += MasterDetailPageDisappearing;

                SetGestureState();

                Presented = newElement.IsPresented;

                newElement.SendViewInitialized(this);
            }

            OnElementChanged(oldElement, newElement);

            // Make sure to initialize this AFTER event is fired
            if (_tracker == null)
            {
                _tracker = new VisualElementTracker(this);
            }

            if (element != null && !string.IsNullOrEmpty(element.AutomationId))
            {
                SetAutomationId(element.AutomationId);
            }

            SetContentDescription();
        }