public void Dispose() { ClearMaster(); ClearDetail(); Tracker = null; if (Element != null) SetElement(null); }
public void SetElement(VisualElement element) { var oldElement = Element; Element = element; if (oldElement != null) { oldElement.PropertyChanged -= OnElementPropertyChanged; } if (element != null) { element.PropertyChanged += OnElementPropertyChanged; if (_packager == null) { _packager = new VisualElementPackager(this); _packager.Load(); _tracker = new VisualElementTracker(this); _tracker.NativeControlUpdated += OnNativeControlUpdated; //_events = new EventTracker(this); // _events.LoadEvents(this); //_insetTracker = new KeyboardInsetTracker(this, () => Window, insets => ContentInset = ScrollIndicatorInsets = insets, point => //{ // var offset = ContentOffset; // offset.Y += point.Y; // SetContentOffset(offset, true); //}); } SetupLayer(); } OnElementChanged(new VisualElementChangedEventArgs(oldElement, element)); }
protected override void Dispose(bool disposing) { if (_disposed) { return; } _disposed = true; if (disposing) { BackgroundManager.Dispose(this); if (_visualElementTracker != null) { _visualElementTracker.Dispose(); _visualElementTracker = null; } if (_visualElementRenderer != null) { _visualElementRenderer.Dispose(); _visualElementRenderer = null; } if (Element != null) { Element.PropertyChanged -= OnElementPropertyChanged; if (Platform.GetRenderer(Element) == this) { Element.ClearValue(Platform.RendererProperty); } } } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing && !_disposed) { Element.PropertyChanged -= OnHandlePropertyChanged; Platform.SetRenderer(Element, null); if (_appeared) { Page.SendDisappearing(); } _appeared = false; if (_events != null) { _events.Dispose(); _events = null; } if (_packager != null) { _packager.Dispose(); _packager = null; } if (_tracker != null) { _tracker.Dispose(); _tracker = null; } Element = null; _disposed = true; } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (disposing) { 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 (_page != null) { MasterDetailPageController.BackButtonPressed -= OnBackButtonPressed; _page.PropertyChanged -= HandlePropertyChanged; _page.Appearing -= MasterDetailPageAppearing; _page.Disappearing -= MasterDetailPageDisappearing; //_page.ClearValue(Platform.RendererProperty); _page = null; } } base.Dispose(disposing); }
void OnElementChanged(ElementChangedEventArgs <Label> e) { ElementChanged?.Invoke(this, new VisualElementChangedEventArgs(e.OldElement, e.NewElement)); if (e.OldElement != null) { e.OldElement.PropertyChanged -= OnElementPropertyChanged; } if (e.NewElement != null) { this.EnsureId(); if (_visualElementTracker == null) { _visualElementTracker = new VisualElementTracker(this); } e.NewElement.PropertyChanged += OnElementPropertyChanged; SkipNextInvalidate(); UpdateText(); UpdateLineHeight(); if (e.OldElement?.LineBreakMode != e.NewElement.LineBreakMode) { UpdateLineBreakMode(); } if (e.OldElement?.HorizontalTextAlignment != e.NewElement.HorizontalTextAlignment || e.OldElement?.VerticalTextAlignment != e.NewElement.VerticalTextAlignment) { UpdateGravity(); } ElevationHelper.SetElevation(this, e.NewElement); } }
protected override void Dispose(bool disposing) { if ((_flags & VisualElementRendererFlags.Disposed) != 0) { return; } _flags |= VisualElementRendererFlags.Disposed; if (disposing) { if (_events != null) { _events.Dispose(); _events = null; } if (_tracker != null) { _tracker.Dispose(); _tracker = null; } if (_packager != null) { _packager.Dispose(); _packager = null; } // The ListView can create renderers and unhook them from the Element before Dispose is called in CalculateHeightForCell. // Thus, it is possible that this work is already completed. if (Element != null) { Element.ClearValue(Platform.RendererProperty); SetElement(null); } } base.Dispose(disposing); }
protected virtual void OnElementChanged(ElementChangedEventArgs <Frame> e) { ElementChanged?.Invoke(this, new VisualElementChangedEventArgs(e.OldElement, e.NewElement)); if (e.OldElement != null) { e.OldElement.PropertyChanged -= OnElementPropertyChanged; } if (e.NewElement != null) { if (_visualElementTracker == null) { _visualElementTracker = new VisualElementTracker(this); _visualElementPackager = new VisualElementPackager(this); _visualElementPackager.Load(); } e.NewElement.PropertyChanged += OnElementPropertyChanged; UpdateShadow(); UpdateBackgroundColor(); UpdateCornerRadius(); } }
/// <summary> /// Setup our SwipeRefreshLayout and register for property changed notifications. /// </summary> /// <param name="element">Element.</param> public void SetElement(VisualElement element) { var oldElement = Element; //unregister old and re-register new if (oldElement != null) { oldElement.PropertyChanged -= HandlePropertyChanged; } Element = element; if (Element != null) { UpdateContent(); Element.PropertyChanged += HandlePropertyChanged; } if (!init) { init = true; //sizes to match the forms view //updates properties, handles visual element properties Tracker = new VisualElementTracker(this); SetOnRefreshListener(this); } UpdateColors(); UpdateIsRefreshing(); UpdateIsSwipeToRefreshEnabled(); UpdateIsInterceptHorizontalScroll(); if (ElementChanged != null) { ElementChanged(this, new VisualElementChangedEventArgs(oldElement, this.Element)); } }
public void SetElement(VisualElement element) { CarouselScrollView oldElement = _view; _view = (CarouselScrollView)element; if (oldElement != null) { ((IScrollViewController)oldElement).ScrollToRequested -= OnScrollToRequested; } if (element != null) { ElementChanged?.Invoke(this, new VisualElementChangedEventArgs(oldElement, element)); if (_container == null) { Tracker = new VisualElementTracker(this); _container = new CustomScrollViewContainer(_view, Context); } Controller.ScrollToRequested += OnScrollToRequested; LoadContent(); UpdateBackgroundColor(); UpdateOrientation(); UpdateIsEnabled(); UpdateHorizontalScrollBarVisibility(); UpdateVerticalScrollBarVisibility(); UpdateFlowDirection(); if (!string.IsNullOrEmpty(element.AutomationId)) { ContentDescription = element.AutomationId; } } }
void IVisualElementRenderer.SetElement(VisualElement element) { if (element == null) { throw new ArgumentNullException(nameof(element)); } if (!(element is Entry)) { throw new ArgumentException($"{nameof(element)} must be of type {nameof(Entry)}"); } VisualElement oldElement = Entry; Entry = (Entry)element; Performance.Start(out string reference); if (oldElement != null) { oldElement.PropertyChanged -= OnElementPropertyChanged; oldElement.FocusChangeRequested -= OnFocusChangeRequested; } if (oldElement == null) { _textInputEditText = new MaterialFormsEditText(Context); AddView(_textInputEditText); _textInputEditText.FocusChange += _textInputEditText_FocusChange; Hint = Entry.Placeholder; _textInputEditText.AddTextChangedListener(this); _textInputEditText.SetOnEditorActionListener(this); _textInputEditText.OnKeyboardBackPressed += OnKeyboardBackPressed; _textInputEditText.SelectionChanged += SelectionChanged; var useLegacyColorManagement = Entry.UseLegacyColorManagement(); _textColorSwitcher = new TextColorSwitcher(_textInputEditText.TextColors, useLegacyColorManagement); _hintColorSwitcher = new TextColorSwitcher(_textInputEditText.HintTextColors, useLegacyColorManagement); } // When we set the control text, it triggers the SelectionChanged event, which updates CursorPosition and SelectionLength; // These one-time-use variables will let us initialize a CursorPosition and SelectionLength via ctor/xaml/etc. _cursorPositionChangePending = Element.IsSet(Entry.CursorPositionProperty); _selectionLengthChangePending = Element.IsSet(Entry.SelectionLengthProperty); Hint = Entry.Placeholder; _textInputEditText.Text = Entry.Text; UpdateInputType(); UpdateColor(); UpdateAlignment(); UpdateFont(); UpdatePlaceholderColor(true); UpdateMaxLength(); UpdateImeOptions(); UpdateReturnType(); UpdateBackgroundColor(); if (_cursorPositionChangePending || _selectionLengthChangePending) { UpdateCursorSelection(); } element.PropertyChanged += OnElementPropertyChanged; if (_tracker == null) { _tracker = new VisualElementTracker(this); } element.SendViewInitialized(this); EffectUtilities.RegisterEffectControlProvider(this, oldElement, element); Performance.Stop(reference); ElementChanged?.Invoke(this, new VisualElementChangedEventArgs(oldElement, element)); element.FocusChangeRequested += OnFocusChangeRequested; }
void IVisualElementRenderer.UpdateLayout() { VisualElementTracker tracker = _visualElementTracker; tracker?.UpdateLayout(); }
protected override void Dispose(bool disposing) { if (disposing && !_disposed) { _disposed = true; if (_gestureListener != null) { _gestureListener.Dispose(); _gestureListener = null; } if (_visualElementTracker != null) { _visualElementTracker.Dispose(); _visualElementTracker = null; } if (_visualElementPackager != null) { _visualElementPackager.Dispose(); _visualElementPackager = null; } if (Element != null) Element.PropertyChanged -= OnElementPropertyChanged; } base.Dispose(disposing); }
protected virtual void OnElementChanged(ElementChangedEventArgs<MasterDetailPage> e) { if (e.OldElement != null) e.OldElement.PropertyChanged -= OnElementPropertyChanged; if (e.NewElement != null) { if (Control == null) { Control = new MasterDetailControl(); Control.Loaded += OnControlLoaded; Control.Unloaded += OnControlUnlaoded; Control.SizeChanged += OnNativeSizeChanged; Control.RegisterPropertyChangedCallback(MasterDetailControl.IsPaneOpenProperty, OnIsPaneOpenChanged); Tracker = new VisualElementTracker<Page, FrameworkElement> { Container = Control, Element = Element }; } e.NewElement.PropertyChanged += OnElementPropertyChanged; UpdateDetail(); UpdateMaster(); UpdateMode(); UpdateIsPresented(); if (!string.IsNullOrEmpty(e.NewElement.AutomationId)) Control.SetValue(AutomationProperties.AutomationIdProperty, e.NewElement.AutomationId); } }
void SetTracker(VisualElementTracker tracker) => this.tracker = tracker;
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); }
protected virtual void OnElementChanged(ElementChangedEventArgs<Frame> e) { ElementChanged?.Invoke(this, new VisualElementChangedEventArgs(e.OldElement, e.NewElement)); if (e.OldElement != null) { e.OldElement.PropertyChanged -= OnElementPropertyChanged; UnsubscribeGestureRecognizers(e.OldElement); } if (e.NewElement != null) { if (_visualElementTracker == null) { SetOnClickListener(this); SetOnTouchListener(this); UpdateGestureRecognizers(true); _visualElementTracker = new VisualElementTracker(this); _visualElementPackager = new VisualElementPackager(this); _visualElementPackager.Load(); } e.NewElement.PropertyChanged += OnElementPropertyChanged; UpdateShadow(); UpdateBackgroundColor(); SubscribeGestureRecognizers(e.NewElement); } }
void SetTracker(VisualElementTracker tracker) { _tracker = tracker; }
public void SetElement(VisualElement element) { _requestedScroll = null; var oldElement = Element; Element = element; if (oldElement != null) { oldElement.PropertyChanged -= HandlePropertyChanged; ((ScrollView)oldElement).ScrollToRequested -= OnScrollToRequested; } if (element != null) { element.PropertyChanged += HandlePropertyChanged; ((ScrollView)element).ScrollToRequested += OnScrollToRequested; if (_packager == null) { _packager = new VisualElementPackager(this); _packager.Load(); _tracker = new VisualElementTracker(this); _tracker.NativeControlUpdated += OnNativeControlUpdated; _events = new EventTracker(this); _events.LoadEvents(this); _insetTracker = new KeyboardInsetTracker(this, () => Window, insets => { ContentInset = ScrollIndicatorInsets = insets; }, point => { var offset = ContentOffset; offset.Y += point.Y; SetContentOffset(offset, true); }, this); } UpdateDelaysContentTouches(); UpdateContentSize(); UpdateBackgroundColor(); UpdateBackground(); UpdateIsEnabled(); UpdateVerticalScrollBarVisibility(); UpdateHorizontalScrollBarVisibility(); OnElementChanged(new VisualElementChangedEventArgs(oldElement, element)); EffectUtilities.RegisterEffectControlProvider(this, oldElement, element); if (element != null) { element.SendViewInitialized(this); } if (!string.IsNullOrEmpty(element.AutomationId)) { AccessibilityIdentifier = element.AutomationId; } } }
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(); }
public void SetElement(TElement element) { var oldElement = Element; Element = element; Performance.Start(out string reference); if (oldElement != null) { oldElement.PropertyChanged -= _propertyChangedHandler; } if (element != null) { if (element.BackgroundColor != Color.Default || (oldElement != null && element.BackgroundColor != oldElement.BackgroundColor)) { SetBackgroundColor(element.BackgroundColor); } UpdateClipToBounds(); if (_tracker == null) { _tracker = new VisualElementTracker(this); _tracker.NativeControlUpdated += (sender, e) => UpdateNativeWidget(); } if (AutoPackage && _packager == null) { _packager = new VisualElementPackager(this); _packager.Load(); } if (AutoTrack && _events == null) { _events = new EventTracker(this); _events.LoadEvents(this); } element.PropertyChanged += _propertyChangedHandler; } OnElementChanged(new ElementChangedEventArgs <TElement>(oldElement, element)); if (element != null) { SendVisualElementInitialized(element, this); } EffectUtilities.RegisterEffectControlProvider(this, oldElement, element); if (Element != null && !string.IsNullOrEmpty(Element.AutomationId)) { SetAutomationId(Element.AutomationId); } SetAccessibilityLabel(); SetAccessibilityHint(); SetIsAccessibilityElement(); Performance.Stop(reference); }
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); }
public void SetElement(VisualElement element) { var oldElement = this.Element; if (oldElement != null) { oldElement.PropertyChanged -= HandlePropertyChanged; } this.Element = element; if (this.Element != null) { this.Element.PropertyChanged += HandlePropertyChanged; // ** fix any errors, make sure valid values **/ if (SourceView.ShadowBorders == null) { SourceView.ShadowBorders = new FrameRect(); } if (SourceView.ShadowBorders.Top < 0) { SourceView.ShadowBorders.Top = 0; } if (SourceView.ShadowBorders.Bottom < 0) { SourceView.ShadowBorders.Bottom = 0; } if (SourceView.ShadowBorders.Right < 0) { SourceView.ShadowBorders.Right = 0; } if (SourceView.ShadowBorders.Left < 0) { SourceView.ShadowBorders.Left = 0; } // ** end error check **/ // ** setbackground **/ //var border2 = Android.App.Application.Context.Resources.GetDrawable (Resource.Drawable.FrameBorder, Android.App.Application.Context.Theme).GetConstantState().NewDrawable() as LayerDrawable; // prevent changes to other instances of the drawable var border2 = Android.App.Application.Context.Resources.GetDrawable(Resource.Drawable.FrameBorder1, Android.App.Application.Context.Theme).Mutate() as LayerDrawable; var shadowLayer = border2.FindDrawableByLayerId(Resource.Id.shadowLayer).Mutate() as GradientDrawable; shadowLayer.SetCornerRadius(SourceView.Radius); if (SourceView.HasShadow == false) { // invisible shadowLayer.Alpha = 0; // no padding border2.SetLayerInset(0, 0, 0, 0, 0); } else { shadowLayer.SetStroke((int)SourceView.ShadowRadius, SourceView.ShadowColor.ToAndroid()); shadowLayer.SetCornerRadius(SourceView.Radius); } var BorderLayer = border2.FindDrawableByLayerId(Resource.Id.BorderLayer).Mutate() as GradientDrawable; BorderLayer.SetStroke(SourceView.StrokeThickness, SourceView.OutlineColor.ToAndroid()); if (SourceView.StrokeType == StrokeType.Dashed) { // dashes BorderLayer.SetStroke(SourceView.StrokeThickness, SourceView.OutlineColor.ToAndroid(), 15, 10); } else if (SourceView.StrokeType == StrokeType.Dotted) { // dots BorderLayer.SetStroke(SourceView.StrokeThickness, SourceView.OutlineColor.ToAndroid(), 5, 4); } else { BorderLayer.SetStroke(SourceView.StrokeThickness, SourceView.OutlineColor.ToAndroid()); } BorderLayer.SetCornerRadius(SourceView.Radius); var MainLayer = border2.FindDrawableByLayerId(Resource.Id.MainLayer).Mutate() as GradientDrawable; MainLayer.SetColor(SourceView.BackgroundColor.ToAndroid()); MainLayer.SetCornerRadius(SourceView.Radius); if (SourceView.HasShadow == false) { border2.SetLayerInset(1, 0, 0, 0, 0); //index, l,t,r,b border2.SetLayerInset(2, SourceView.Borders.Left == 0 ? 0 : SourceView.StrokeThickness, SourceView.Borders.Top == 0 ? 0 : SourceView.StrokeThickness, SourceView.Borders.Right == 0 ? 0 : SourceView.StrokeThickness, SourceView.Borders.Bottom == 0 ? 0 : SourceView.StrokeThickness); } else { // shadow layer. no padding border2.SetLayerInset(0, 0, 0, 0, 0); // border layer. padding=ShadowRadius, if border turned on var rect = new Rect( SourceView.ShadowBorders.Left == 0 ? 0 : (int)SourceView.ShadowRadius, SourceView.ShadowBorders.Top == 0 ? 0 : (int)SourceView.ShadowRadius, SourceView.ShadowBorders.Right == 0 ? 0 : (int)SourceView.ShadowRadius, SourceView.ShadowBorders.Bottom == 0 ? 0 : (int)SourceView.ShadowRadius); rect.Left = rect.Left < 0 ? 0 : rect.Left; rect.Top = rect.Top < 0 ? 0 : rect.Top; rect.Right = rect.Right < 0 ? 0 : rect.Right; rect.Bottom = rect.Bottom < 0 ? 0 : rect.Bottom; border2.SetLayerInset(1, rect.Left, rect.Top, rect.Right, rect.Bottom); // main layer indent shadowRadius + border size/ border2.SetLayerInset(2, SourceView.Borders.Left == 0 ? rect.Left : SourceView.StrokeThickness + rect.Left, SourceView.Borders.Top == 0 ? rect.Right : SourceView.StrokeThickness + rect.Top, SourceView.Borders.Right == 0 ? rect.Top : SourceView.StrokeThickness + rect.Right, SourceView.Borders.Bottom == 0 ? rect.Bottom : SourceView.StrokeThickness + rect.Bottom); } this.Background = border2; // ** set padding **/ this.SetPadding( (int)SourceView.Padding.Left, (int)SourceView.Padding.Top, (int)SourceView.Padding.Right, (int)SourceView.Padding.Bottom); ViewGroup.RemoveAllViews(); Tracker = new VisualElementTracker(this); Packager = new VisualElementPackager(this); Packager.Load(); if (ElementChanged != null) { ElementChanged(this, new VisualElementChangedEventArgs(oldElement, this.Element)); } } }
public void SetElement(VisualElement element) { MasterDetailPage oldElement = _page; _page = element as MasterDetailPage; _detailLayout = new MasterDetailContainer(_page, false, Context) { LayoutParameters = new LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent) }; var parameters = new CoordinatorLayout.LayoutParams(new LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent) { Gravity = (int)GravityFlags.Start }); parameters.Behavior = new AnchorBottomSheetBehavior(); _masterLayout = new MasterDetailContainer(_page, true, Context) { LayoutParameters = parameters, }; _masterLayout.RequestLayout(); AddView(_detailLayout); AddView(_masterLayout); behaviour = AnchorBottomSheetBehavior.From(_masterLayout); behaviour.PeekHeight = (int)(NowPlayingPage.TotalMiniBarHeight * Android.NGraphicsExtensions.Scale); behaviour.DragChanged = (percent) => { var panel = _page as SlideUpPanel; if (panel != null) { panel.PercentVisible = (float)percent; } }; var activity = Context as Activity; //activity.ActionBar.SetDisplayShowHomeEnabled(true); //activity.ActionBar.SetHomeButtonEnabled(true); UpdateBackgroundColor(_page); UpdateBackgroundImage(_page); OnElementChanged(oldElement, element); if (oldElement != null) { ((IMasterDetailPageController)oldElement).BackButtonPressed -= OnBackButtonPressed; } if (_page != null) { MasterDetailPageController.BackButtonPressed += OnBackButtonPressed; } if (Tracker == null) { Tracker = new VisualElementTracker(this); } _page.PropertyChanged += HandlePropertyChanged; _page.Appearing += MasterDetailPageAppearing; _page.Disappearing += MasterDetailPageDisappearing; UpdateMaster(); UpdateDetail(); //Device.Info.PropertyChanged += DeviceInfoPropertyChanged; SetGestureState(); Presented = _page.IsPresented; //AddDrawerListener(this); //if (element != null) // element.SendViewInitialized(this); if (element != null && !string.IsNullOrEmpty(element.AutomationId)) { ContentDescription = element.AutomationId; } }
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); } }
public void SetElement(VisualElement element) { //-------------------------------------------- // Initialize vars //-------------------------------------------- if (this._tracker == null) { _tracker = new VisualElementTracker(this); } if (this._events == null) { _events = new EventTracker(this); _events.LoadEvents(View); } //-------------------------------------------- // Reset the old element //-------------------------------------------- var oldElement = this.Element; if (oldElement != null) { oldElement.SizeChanged -= PageOnSizeChanged; oldElement.PropertyChanged -= HandlePropertyChanged; } //-------------------------------------------- // Assign the new element //-------------------------------------------- this.Element = element; this.Element.SizeChanged += PageOnSizeChanged; this.Element.PropertyChanged += HandlePropertyChanged; this.Presented = ((MasterDetailPage)Element).IsPresented; //-------------------------------------------- // Setup the root and menu view controller //-------------------------------------------- this.RootViewController = new ChildViewController(); this.LeftViewController = new ChildViewController(); this.RightViewController = new ChildViewController(); //-------------------------------------------- // Fire the element changed event //-------------------------------------------- OnElementChanged(new VisualElementChangedEventArgs(oldElement, element)); //-------------------------------------------- // Update the view //-------------------------------------------- /* Master Detail Container */ UpdateMasterDetailContainers(); /* Background */ UpdateBackground(); /* Menu Background */ UpdateMenuBackground(); /* Menu Width */ UpdateMenuWidth(); /* Menu Presentation Style */ UpdateMenuPresentationStyle(); /* Swipe Range */ UpdateSwipeRange(); //-------------------------------------------- // Attempt to automatically create a menu click event //-------------------------------------------- var detailRenderer = CurrentPlatform.GetRenderer((element as MasterDetailPage).Detail) as UINavigationController; if (detailRenderer != null) { UIViewController firstPage = detailRenderer?.ViewControllers.FirstOrDefault(); firstPage.NavigationItem.LeftBarButtonItem.Clicked += HandleMenuIcon_Clicked; } //EffectUtilities.RegisterEffectControlProvider(this, oldElement, element); //if (element != null) // element.SendViewInitialized(NativeView); }