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

            _disposed = true;

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

                if (Element != null)
                {
                    FlyoutPageController.BackButtonPressed -= OnBackButtonPressed;
                    Element.PropertyChanged -= HandlePropertyChanged;
                    Element.Appearing       -= FlyoutPageAppearing;
                    Element.Disappearing    -= FlyoutPageDisappearing;
                }

                if (_flyoutLayout?.ChildView != null)
                {
                    _flyoutLayout.ChildView.PropertyChanged -= HandleFlyoutPropertyChanged;
                }

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

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

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

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

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

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

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

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

                oldElement.PropertyChanged -= HandlePropertyChanged;
                oldElement.Appearing       -= FlyoutPageAppearing;
                oldElement.Disappearing    -= FlyoutPageDisappearing;

                RemoveDrawerListener(this);

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

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

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

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

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

                    AddView(_detailLayout);
                    AddView(_flyoutLayout);

                    Device.Info.PropertyChanged += DeviceInfoPropertyChanged;

                    AddDrawerListener(this);
                }

                UpdateBackgroundColor(newElement);
                UpdateBackgroundImage(newElement);

                UpdateFlyout();
                UpdateDetail();

                UpdateFlowDirection();

                ((IFlyoutPageController)newElement).BackButtonPressed += OnBackButtonPressed;
                newElement.PropertyChanged += HandlePropertyChanged;
                newElement.Appearing       += FlyoutPageAppearing;
                newElement.Disappearing    += FlyoutPageDisappearing;

                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();
        }