From 73b4fd11af556b474f1c0b72780c54c11555d8f5 Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Sat, 18 Jan 2020 11:42:44 -0800 Subject: [PATCH] Only expose ApplyPageBehaviors --- .../Behaviors/IPageBehaviorFactory.cs | 33 ------------------- .../Behaviors/PageBehaviorFactory.cs | 26 ++++++++++----- 2 files changed, 17 insertions(+), 42 deletions(-) diff --git a/Source/Xamarin/Prism.Forms/Behaviors/IPageBehaviorFactory.cs b/Source/Xamarin/Prism.Forms/Behaviors/IPageBehaviorFactory.cs index 2cc88c5704..2d8979d4ae 100644 --- a/Source/Xamarin/Prism.Forms/Behaviors/IPageBehaviorFactory.cs +++ b/Source/Xamarin/Prism.Forms/Behaviors/IPageBehaviorFactory.cs @@ -13,38 +13,5 @@ public interface IPageBehaviorFactory /// The page to apply the behaviors /// The PageLifeCycleAwareBehavior is applied to all pages void ApplyPageBehaviors(Page page); - - /// - /// Applies behaviors to a CarouselPage. - /// - /// The CarouselPage to apply the behaviors - /// The CarouselPageActiveAwareBehavior is applied by default - void ApplyCarouselPageBehaviors(CarouselPage page); - - /// - /// Applies behaviors to a ContentPage. - /// - /// The ContentPage to apply the behaviors - void ApplyContentPageBehaviors(ContentPage page); - - /// - /// Applies behaviors to a MasterDetailPage. - /// - /// The MasterDetailPage to apply the behaviors - void ApplyMasterDetailPageBehaviors(MasterDetailPage page); - - /// - /// Applies behaviors to a NavigationPage. - /// - /// The NavigationPage to apply the behaviors - /// The NavigationPageSystemGoBackBehavior and NavigationPageActiveAwareBehavior are applied by default - void ApplyNavigationPageBehaviors(NavigationPage page); - - /// - /// Applies behaviors to a TabbedPage. - /// - /// The TabbedPage to apply the behaviors - /// The TabbedPageActiveAwareBehavior is added by default - void ApplyTabbedPageBehaviors(TabbedPage page); } } diff --git a/Source/Xamarin/Prism.Forms/Behaviors/PageBehaviorFactory.cs b/Source/Xamarin/Prism.Forms/Behaviors/PageBehaviorFactory.cs index 6f636c9a5d..108ae7b7b1 100644 --- a/Source/Xamarin/Prism.Forms/Behaviors/PageBehaviorFactory.cs +++ b/Source/Xamarin/Prism.Forms/Behaviors/PageBehaviorFactory.cs @@ -12,7 +12,7 @@ public class PageBehaviorFactory : IPageBehaviorFactory /// /// The CarouselPage to apply the behaviors /// The CarouselPageActiveAwareBehavior is applied by default - public virtual void ApplyCarouselPageBehaviors(CarouselPage page) + protected virtual void ApplyCarouselPageBehaviors(CarouselPage page) { page.Behaviors.Add(new CarouselPageActiveAwareBehavior()); } @@ -21,18 +21,18 @@ public virtual void ApplyCarouselPageBehaviors(CarouselPage page) /// Applies behaviors to a ContentPage. /// /// The ContentPage to apply the behaviors - public virtual void ApplyContentPageBehaviors(ContentPage page) + protected virtual void ApplyContentPageBehaviors(ContentPage page) { - + } /// /// Applies behaviors to a MasterDetailPage. /// /// The MasterDetailPage to apply the behaviors - public virtual void ApplyMasterDetailPageBehaviors(MasterDetailPage page) + protected virtual void ApplyMasterDetailPageBehaviors(MasterDetailPage page) { - + } /// @@ -40,7 +40,7 @@ public virtual void ApplyMasterDetailPageBehaviors(MasterDetailPage page) /// /// The NavigationPage to apply the behaviors /// The NavigationPageSystemGoBackBehavior and NavigationPageActiveAwareBehavior are applied by default - public virtual void ApplyNavigationPageBehaviors(NavigationPage page) + protected virtual void ApplyNavigationPageBehaviors(NavigationPage page) { page.Behaviors.Add(new NavigationPageSystemGoBackBehavior()); page.Behaviors.Add(new NavigationPageActiveAwareBehavior()); @@ -50,8 +50,15 @@ public virtual void ApplyNavigationPageBehaviors(NavigationPage page) /// Applies behaviors to a page based on the page type. /// /// The page to apply the behaviors - /// The PageLifeCycleAwareBehavior is applied to all pages - public virtual void ApplyPageBehaviors(Page page) + /// + /// There is no need to call base.ApplyPageBehaviors when overriding. + /// All Prism behaviors have already been applied. + /// + protected virtual void ApplyPageBehaviors(Page page) + { + } + + void IPageBehaviorFactory.ApplyPageBehaviors(Page page) { switch (page) { @@ -73,6 +80,7 @@ public virtual void ApplyPageBehaviors(Page page) } page.Behaviors.Add(new PageLifeCycleAwareBehavior()); + ApplyPageBehaviors(page); } /// @@ -80,7 +88,7 @@ public virtual void ApplyPageBehaviors(Page page) /// /// The TabbedPage to apply the behaviors /// The TabbedPageActiveAwareBehavior is added by default - public virtual void ApplyTabbedPageBehaviors(TabbedPage page) + protected virtual void ApplyTabbedPageBehaviors(TabbedPage page) { page.Behaviors.Add(new TabbedPageActiveAwareBehavior()); }