Пример #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);
        }
        void UpdateMaster()
        {
            MasterDetailContainer masterContainer = _masterLayout;

            if (masterContainer == null)
            {
                return;
            }

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

            masterContainer.ChildView = Element.Master;
            if (Element.Master != null)
            {
                Element.Master.PropertyChanged += HandleMasterPropertyChanged;
            }
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing && !_disposed)
            {
                _disposed = true;

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

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

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

                Device.Info.PropertyChanged -= DeviceInfoPropertyChanged;

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

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

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

            var statusBarHeight = 0;

            if (Forms.IsLollipopOrNewer)
            {
                statusBarHeight = ((FormsAppCompatActivity)Context).GetStatusBarHeight();
            }

            if (newElement != null)
            {
                if (_detailLayout == null)
                {
                    _detailLayout = new MasterDetailContainer(newElement, false, Context)
                    {
                        TopPadding       = statusBarHeight,
                        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
                        }
                    };

                    AddView(_detailLayout);
                    AddView(_masterLayout);

                    Device.Info.PropertyChanged += DeviceInfoPropertyChanged;

                    AddDrawerListener(this);
                }

                UpdateBackgroundColor(newElement);
                UpdateBackgroundImage(newElement);

                UpdateMaster();
                UpdateDetail();

                ((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);
            }
        }
		void IVisualElementRenderer.SetElement(VisualElement element)
		{
			MasterDetailPage oldElement = Element;
			MasterDetailPage newElement = Element = element as MasterDetailPage;

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

			var statusBarHeight = 0;
			if (Forms.IsLollipopOrNewer)
				statusBarHeight = ((FormsAppCompatActivity)Context).GetStatusBarHeight();

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

					_masterLayout = new MasterDetailContainer(newElement, true, Context)
					{
						TopPadding = ((IMasterDetailPageController)newElement).ShouldShowSplitMode ? statusBarHeight : 0,
						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();

				((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);
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing && !_disposed)
			{
				_disposed = true;

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

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

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

				Device.Info.PropertyChanged -= DeviceInfoPropertyChanged;

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

			base.Dispose(disposing);
		}
Пример #7
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();
        }