From fe5d6f100e175fd5489b6697ccf18dca8e2d2e47 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Sat, 20 Feb 2021 17:53:57 -0300 Subject: [PATCH 1/5] added iOS platformSpecific --- .../AssemblyInfo/AssemblyInfo.shared.cs | 1 + .../iOSSpecific/PopUp.shared.cs | 36 +++++++++++++++++++ .../Views/Popup/BasePopup.shared.cs | 8 ++++- .../Popup/iOS/PopoverArrowDirection.shared.cs | 13 ------- .../Views/Popup/iOS/Popup.shared.cs | 16 --------- .../Views/Popup/iOS/PopupRenderer.ios.cs | 22 ++++++------ 6 files changed, 56 insertions(+), 40 deletions(-) create mode 100644 src/CommunityToolkit/Xamarin.CommunityToolkit/PlatformConfiguration/iOSSpecific/PopUp.shared.cs delete mode 100644 src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/iOS/PopoverArrowDirection.shared.cs delete mode 100644 src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/iOS/Popup.shared.cs diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit/AssemblyInfo/AssemblyInfo.shared.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit/AssemblyInfo/AssemblyInfo.shared.cs index 8d15fcd20..9c3a43184 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit/AssemblyInfo/AssemblyInfo.shared.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit/AssemblyInfo/AssemblyInfo.shared.cs @@ -9,4 +9,5 @@ [assembly: XmlnsDefinition("http://xamarin.com/schemas/2020/toolkit", "Xamarin.CommunityToolkit.Effects")] [assembly: XmlnsDefinition("http://xamarin.com/schemas/2020/toolkit", "Xamarin.CommunityToolkit.Extensions")] [assembly: XmlnsDefinition("http://xamarin.com/schemas/2020/toolkit", "Xamarin.CommunityToolkit.UI.Views")] +[assembly: XmlnsDefinition("http://xamarin.com/schemas/2020/toolkit", "Xamarin.CommunityToolkit.PlatformConfiguration.iOSSpecific")] #endif \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit/PlatformConfiguration/iOSSpecific/PopUp.shared.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit/PlatformConfiguration/iOSSpecific/PopUp.shared.cs new file mode 100644 index 000000000..165ab36d1 --- /dev/null +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit/PlatformConfiguration/iOSSpecific/PopUp.shared.cs @@ -0,0 +1,36 @@ +using Xamarin.CommunityToolkit.UI.Views; +using Xamarin.Forms; +using XFPC = Xamarin.Forms.PlatformConfiguration; +using XCTElement = Xamarin.CommunityToolkit.UI.Views.BasePopup; + +namespace Xamarin.CommunityToolkit.PlatformConfiguration.iOSSpecific +{ + public static class PopUp + { + public static readonly BindableProperty ArrowDirectionProperty = BindableProperty.Create( + "ArrowDirection", typeof(PopoverArrowDirection), typeof(BasePopup), PopoverArrowDirection.None); + + public static void SetArrowDirection(BindableObject element, PopoverArrowDirection color) => + element.SetValue(ArrowDirectionProperty, color); + + public static PopoverArrowDirection GetArrowDirection(BindableObject element) => + (PopoverArrowDirection)element.GetValue(ArrowDirectionProperty); + + public static IPlatformElementConfiguration UseArrowDirection(this IPlatformElementConfiguration config, PopoverArrowDirection value) + { + SetArrowDirection(config.Element, value); + return config; + } + } + + public enum PopoverArrowDirection + { + None, + Up, + Down, + Left, + Right, + Any, + Unknown + } +} diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/BasePopup.shared.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/BasePopup.shared.cs index f68a4797c..f30f8ded0 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/BasePopup.shared.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/BasePopup.shared.cs @@ -8,7 +8,7 @@ namespace Xamarin.CommunityToolkit.UI.Views /// The popup control's base implementation. /// [ContentProperty(nameof(Content))] - public abstract class BasePopup : VisualElement + public abstract class BasePopup : VisualElement, IElementConfiguration { readonly WeakEventManager dismissWeakEventManager = new WeakEventManager(); readonly WeakEventManager openedWeakEventManager = new WeakEventManager(); @@ -22,8 +22,14 @@ protected BasePopup() VerticalOptions = LayoutOptions.CenterAndExpand; HorizontalOptions = LayoutOptions.CenterAndExpand; IsLightDismissEnabled = true; + platformConfigurationRegistry = new Lazy>(() => new PlatformConfigurationRegistry(this)); } + readonly Lazy> platformConfigurationRegistry; + + public IPlatformElementConfiguration On() where T : IConfigPlatform => + platformConfigurationRegistry.Value.On(); + public static readonly BindableProperty ContentProperty = BindableProperty.Create(nameof(Content), typeof(View), typeof(BasePopup), propertyChanged: OnContentChanged); public static readonly BindableProperty ColorProperty = BindableProperty.Create(nameof(Color), typeof(Color), typeof(BasePopup), Color.Default); diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/iOS/PopoverArrowDirection.shared.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/iOS/PopoverArrowDirection.shared.cs deleted file mode 100644 index 968202f18..000000000 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/iOS/PopoverArrowDirection.shared.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Xamarin.CommunityToolkit.UI.Views.iOSSpecific -{ - public enum PopoverArrowDirection - { - None, - Up, - Down, - Left, - Right, - Any, - Unknown - } -} diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/iOS/Popup.shared.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/iOS/Popup.shared.cs deleted file mode 100644 index f4b885721..000000000 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/iOS/Popup.shared.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Xamarin.Forms; - -namespace Xamarin.CommunityToolkit.UI.Views.iOSSpecific -{ - public static class Popup - { - public static readonly BindableProperty ArrowDirectionProperty = BindableProperty.Create( - "ArrowDirection", typeof(PopoverArrowDirection), typeof(Views.Popup), PopoverArrowDirection.None); - - public static void SetArrowDirection(BindableObject element, PopoverArrowDirection color) => - element.SetValue(ArrowDirectionProperty, color); - - public static PopoverArrowDirection GetArrowDirection(BindableObject element) => - (PopoverArrowDirection)element.GetValue(ArrowDirectionProperty); - } -} diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/iOS/PopupRenderer.ios.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/iOS/PopupRenderer.ios.cs index 70cb7ee53..5c7ef970a 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/iOS/PopupRenderer.ios.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/iOS/PopupRenderer.ios.cs @@ -7,6 +7,8 @@ using Xamarin.Forms; using Xamarin.Forms.Internals; using Xamarin.Forms.Platform.iOS; +using Xamarin.CommunityToolkit.PlatformConfiguration.iOSSpecific; +using Specifics = Xamarin.CommunityToolkit.PlatformConfiguration.iOSSpecific.PopUp; [assembly: ExportRenderer(typeof(BasePopup), typeof(PopupRenderer))] @@ -82,7 +84,7 @@ protected virtual void OnElementChanged(ElementChangedEventArgs e) if (e.NewElement != null && !isDisposed) { ModalInPopover = true; - ModalPresentationStyle = UIModalPresentationStyle.Popover; + ModalPresentationStyle = UIKit.UIModalPresentationStyle.Popover; SetViewController(); SetPresentationController(); @@ -179,15 +181,15 @@ void SetLayout() var view = Platform.GetRenderer(Element.Anchor).NativeView; PopoverPresentationController.SourceView = view; PopoverPresentationController.SourceRect = view.Bounds; - var arrowDirection = Views.iOSSpecific.Popup.GetArrowDirection(Element); + var arrowDirection = Specifics.GetArrowDirection(Element); PopoverPresentationController.PermittedArrowDirections = arrowDirection switch { - Views.iOSSpecific.PopoverArrowDirection.Up => UIPopoverArrowDirection.Up, - Views.iOSSpecific.PopoverArrowDirection.Down => UIPopoverArrowDirection.Down, - Views.iOSSpecific.PopoverArrowDirection.Left => UIPopoverArrowDirection.Left, - Views.iOSSpecific.PopoverArrowDirection.Right => UIPopoverArrowDirection.Right, - Views.iOSSpecific.PopoverArrowDirection.Any => UIPopoverArrowDirection.Any, - Views.iOSSpecific.PopoverArrowDirection.Unknown => UIPopoverArrowDirection.Unknown, + PopoverArrowDirection.Up => UIPopoverArrowDirection.Up, + PopoverArrowDirection.Down => UIPopoverArrowDirection.Down, + PopoverArrowDirection.Left => UIPopoverArrowDirection.Left, + PopoverArrowDirection.Right => UIPopoverArrowDirection.Right, + PopoverArrowDirection.Any => UIPopoverArrowDirection.Any, + PopoverArrowDirection.Unknown => UIPopoverArrowDirection.Unknown, _ => 0 }; } @@ -275,8 +277,8 @@ public event EventHandler PopoverDismissed remove => popoverDismissedEventManager.RemoveEventHandler(value); } - public override UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController forPresentationController) => - UIModalPresentationStyle.None; + public override UIKit.UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController forPresentationController) => + UIKit.UIModalPresentationStyle.None; public override void DidDismiss(UIPresentationController presentationController) => popoverDismissedEventManager.RaiseEvent(this, presentationController, nameof(PopoverDismissed)); From 9625c347769638c514b63ed76222a5138aeb096b Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Sat, 20 Feb 2021 18:21:08 -0300 Subject: [PATCH 2/5] added UWP platform specific --- .../AssemblyInfo/AssemblyInfo.shared.cs | 1 - .../WindowsSpecific/PopUp.shared.cs | 25 +++++++++++++++++++ .../Views/Popup/UWP/Popup.shared.cs | 17 ------------- .../Views/Popup/UWP/PopupRenderer.uwp.cs | 3 ++- 4 files changed, 27 insertions(+), 19 deletions(-) create mode 100644 src/CommunityToolkit/Xamarin.CommunityToolkit/PlatformConfiguration/WindowsSpecific/PopUp.shared.cs delete mode 100644 src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/UWP/Popup.shared.cs diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit/AssemblyInfo/AssemblyInfo.shared.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit/AssemblyInfo/AssemblyInfo.shared.cs index 9c3a43184..8d15fcd20 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit/AssemblyInfo/AssemblyInfo.shared.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit/AssemblyInfo/AssemblyInfo.shared.cs @@ -9,5 +9,4 @@ [assembly: XmlnsDefinition("http://xamarin.com/schemas/2020/toolkit", "Xamarin.CommunityToolkit.Effects")] [assembly: XmlnsDefinition("http://xamarin.com/schemas/2020/toolkit", "Xamarin.CommunityToolkit.Extensions")] [assembly: XmlnsDefinition("http://xamarin.com/schemas/2020/toolkit", "Xamarin.CommunityToolkit.UI.Views")] -[assembly: XmlnsDefinition("http://xamarin.com/schemas/2020/toolkit", "Xamarin.CommunityToolkit.PlatformConfiguration.iOSSpecific")] #endif \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit/PlatformConfiguration/WindowsSpecific/PopUp.shared.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit/PlatformConfiguration/WindowsSpecific/PopUp.shared.cs new file mode 100644 index 000000000..1fd2b4f3d --- /dev/null +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit/PlatformConfiguration/WindowsSpecific/PopUp.shared.cs @@ -0,0 +1,25 @@ +using Xamarin.CommunityToolkit.UI.Views; +using Xamarin.Forms; +using XFPC = Xamarin.Forms.PlatformConfiguration; +using XCTElement = Xamarin.CommunityToolkit.UI.Views.BasePopup; + +namespace Xamarin.CommunityToolkit.PlatformConfiguration.WindowsSpecific +{ + public static class PopUp + { + public static readonly BindableProperty BorderColorProperty = BindableProperty.Create( + "BorderColor", typeof(Color), typeof(BasePopup), default(Color)); + + public static void SetBorderColor(BindableObject element, Color color) => + element.SetValue(BorderColorProperty, color); + + public static Color GetBorderColor(BindableObject element) => + (Color)element.GetValue(BorderColorProperty); + + public static IPlatformElementConfiguration SetBorderColor(this IPlatformElementConfiguration config, Color value) + { + SetBorderColor(config.Element, value); + return config; + } + } +} diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/UWP/Popup.shared.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/UWP/Popup.shared.cs deleted file mode 100644 index 452c9c677..000000000 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/UWP/Popup.shared.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using Xamarin.Forms; - -namespace Xamarin.CommunityToolkit.UI.Views.WindowsSpecific -{ - public static class Popup - { - public static readonly BindableProperty BorderColorProperty = BindableProperty.Create( - "BorderColor", typeof(Color), typeof(Views.Popup), default(Color)); - - public static void SetBorderColor(BindableObject? element, Color color) => - element?.SetValue(BorderColorProperty, color); - - public static Color GetBorderColor(BindableObject? element) => - (Color)(element?.GetValue(BorderColorProperty) ?? throw new NullReferenceException()); - } -} \ No newline at end of file diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/UWP/PopupRenderer.uwp.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/UWP/PopupRenderer.uwp.cs index 11c6d5b12..f20470731 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/UWP/PopupRenderer.uwp.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/UWP/PopupRenderer.uwp.cs @@ -9,6 +9,7 @@ using Xamarin.Forms.Platform.UWP; using UWPThickness = Windows.UI.Xaml.Thickness; using XamlStyle = Windows.UI.Xaml.Style; +using Specific = Xamarin.CommunityToolkit.PlatformConfiguration.WindowsSpecific.PopUp; [assembly: ExportRenderer(typeof(BasePopup), typeof(PopupRenderer))] @@ -149,7 +150,7 @@ void SetBorderColor() flyoutStyle.Setters.Add(new Windows.UI.Xaml.Setter(FlyoutPresenter.PaddingProperty, 0)); flyoutStyle.Setters.Add(new Windows.UI.Xaml.Setter(FlyoutPresenter.BorderThicknessProperty, new UWPThickness(defaultBorderThickness))); - var borderColor = WindowsSpecific.Popup.GetBorderColor(Element); + var borderColor = Specific.GetBorderColor(Element); if (borderColor == default(Color)) flyoutStyle.Setters.Add(new Windows.UI.Xaml.Setter(FlyoutPresenter.BorderBrushProperty, Color.FromHex("#2e6da0").ToWindowsColor())); else From 66cb52da14cb9f11edf0675c7fdb4fb67714ad0e Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Sat, 20 Feb 2021 18:33:32 -0300 Subject: [PATCH 3/5] Changed the sample --- .../Pages/Views/Popups/TransparentPopup.xaml | 34 ++++++++++--------- .../Views/Popups/TransparentPopup.xaml.cs | 13 ++++++- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/samples/XCT.Sample/Pages/Views/Popups/TransparentPopup.xaml b/samples/XCT.Sample/Pages/Views/Popups/TransparentPopup.xaml index 6da7dd74a..120e5726c 100644 --- a/samples/XCT.Sample/Pages/Views/Popups/TransparentPopup.xaml +++ b/samples/XCT.Sample/Pages/Views/Popups/TransparentPopup.xaml @@ -1,19 +1,21 @@  - + + + - - diff --git a/samples/XCT.Sample/Pages/Views/Popups/TransparentPopup.xaml.cs b/samples/XCT.Sample/Pages/Views/Popups/TransparentPopup.xaml.cs index c260895a6..2cdde83d4 100644 --- a/samples/XCT.Sample/Pages/Views/Popups/TransparentPopup.xaml.cs +++ b/samples/XCT.Sample/Pages/Views/Popups/TransparentPopup.xaml.cs @@ -1,7 +1,18 @@ -namespace Xamarin.CommunityToolkit.Sample.Pages.Views.Popups +using Xamarin.Forms.PlatformConfiguration; +using Xamarin.CommunityToolkit.PlatformConfiguration.iOSSpecific; +using Xamarin.CommunityToolkit.PlatformConfiguration.WindowsSpecific; + +namespace Xamarin.CommunityToolkit.Sample.Pages.Views.Popups { public partial class TransparentPopup { public TransparentPopup() => InitializeComponent(); + + protected override void OnBindingContextChanged() + { + base.OnBindingContextChanged(); + On().UseArrowDirection(PopoverArrowDirection.Right); + On().SetBorderColor(Xamarin.Forms.Color.Red); + } } } \ No newline at end of file From f0bb7787775134d3cc837410a940b7a1400de671 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Sat, 20 Feb 2021 18:50:40 -0300 Subject: [PATCH 4/5] code clean up --- .../Views/Popup/iOS/PopupRenderer.ios.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/iOS/PopupRenderer.ios.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/iOS/PopupRenderer.ios.cs index 5c7ef970a..e59135aa9 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/iOS/PopupRenderer.ios.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/iOS/PopupRenderer.ios.cs @@ -84,7 +84,7 @@ protected virtual void OnElementChanged(ElementChangedEventArgs e) if (e.NewElement != null && !isDisposed) { ModalInPopover = true; - ModalPresentationStyle = UIKit.UIModalPresentationStyle.Popover; + ModalPresentationStyle = UIModalPresentationStyle.Popover; SetViewController(); SetPresentationController(); @@ -277,8 +277,8 @@ public event EventHandler PopoverDismissed remove => popoverDismissedEventManager.RemoveEventHandler(value); } - public override UIKit.UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController forPresentationController) => - UIKit.UIModalPresentationStyle.None; + public override UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController forPresentationController) => + UIModalPresentationStyle.None; public override void DidDismiss(UIPresentationController presentationController) => popoverDismissedEventManager.RaiseEvent(this, presentationController, nameof(PopoverDismissed)); From 09baeb4ff67f09c1c2b6b7beec5e3407a7c11032 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Wed, 10 Mar 2021 20:12:43 -0300 Subject: [PATCH 5/5] added null check for Element --- .../Views/Popup/UWP/PopupRenderer.uwp.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/UWP/PopupRenderer.uwp.cs b/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/UWP/PopupRenderer.uwp.cs index f20470731..243b666cc 100644 --- a/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/UWP/PopupRenderer.uwp.cs +++ b/src/CommunityToolkit/Xamarin.CommunityToolkit/Views/Popup/UWP/PopupRenderer.uwp.cs @@ -150,6 +150,12 @@ void SetBorderColor() flyoutStyle.Setters.Add(new Windows.UI.Xaml.Setter(FlyoutPresenter.PaddingProperty, 0)); flyoutStyle.Setters.Add(new Windows.UI.Xaml.Setter(FlyoutPresenter.BorderThicknessProperty, new UWPThickness(defaultBorderThickness))); + if (Element == null) + { + Log.Warning("warning", "The PopUpView is null."); + return; + } + var borderColor = Specific.GetBorderColor(Element); if (borderColor == default(Color)) flyoutStyle.Setters.Add(new Windows.UI.Xaml.Setter(FlyoutPresenter.BorderBrushProperty, Color.FromHex("#2e6da0").ToWindowsColor()));