diff options
author | Samantha Houts <samantha@teamredwall.com> | 2016-08-30 10:46:14 -0700 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-08-30 10:46:14 -0700 |
commit | 5e553f6195e66e48688b8ab324f1bab1e9251f0a (patch) | |
tree | f8843e5e9e8afe89a05a1cc91c3b7fa05588bac7 /Xamarin.Forms.Core | |
parent | f551654b1cfe654c579ca50978445e7cb93f287d (diff) | |
download | xamarin-forms-5e553f6195e66e48688b8ab324f1bab1e9251f0a.tar.gz xamarin-forms-5e553f6195e66e48688b8ab324f1bab1e9251f0a.tar.bz2 xamarin-forms-5e553f6195e66e48688b8ab324f1bab1e9251f0a.zip |
Platform Specifics (#301)
* Playing around with how the platform specifics interfaces etc. might work
* Sample implementation of iOS navigation translucency
* Very slightly reduced code
* Better vendor stuff
* Drop single-implemenation interfaces
* Generics on NavigationPage
* On-demand vendor stuff
* Remove functionally duplicate classes and make ControlGallery work again
* Namespace all the things. XAML test.
* Can use Effect to attach platform specific
* Attach Effect on PropertyChanging for XAML support!
* Rename IConfigPlatform interfaces for readability
* Some renaming to match the documents
* Split class files
* Clear out test-only code
* Re-namespace
* Added On method to rendered Elements
* Allow for removal of platform suffix, convenience methods on specific platforms
* Creating a gallery page for specifics
* Add rudimentary Platform Specifics gallery; make CollapseStyle work on UWP;
Add CollapsedPaneWidth specific property
* Toolbar now working with both collapse styles
* MDP now displaying Content title; toolbar routing around title
* Add a gallery for the iOS NavigationPage stuff
* Add Navigation Page as detail page to verify it works with new Toolbar options
* Make titlebar/toolbar background colors consistent
* ToolbarPlacement now working on NavigationPage
* Toolbar Placement working for tabbed and nav pages
* Fix bug where phone doesn't get default toolbar placement on start
* [Core] Add PS WindowSoftInputModeAdjust
[Core] Make Application extendable
* Toolbar placement now working on Nav, Tabbed, and Master pages on desktop/phone
Remove unnecessary style indirection
Fix build errors
* [A] Add PlatformConfigurationExtensions
* SetSoftInputMode test page
* [A] SetSoftInputMode
Known issue: Status bar color does not work in AdjustResize mode
* [Core] Add PS Blur
* [iOS] Configure renderer for blur
* Add test page
* Move to blur VisualElement for broader support
* Move test pages to gallery
* Update docs
* Use lazy initializer for PlatformConfigurationRegistry
Diffstat (limited to 'Xamarin.Forms.Core')
46 files changed, 745 insertions, 32 deletions
diff --git a/Xamarin.Forms.Core/ActivityIndicator.cs b/Xamarin.Forms.Core/ActivityIndicator.cs index 3689609a..f0b98887 100644 --- a/Xamarin.Forms.Core/ActivityIndicator.cs +++ b/Xamarin.Forms.Core/ActivityIndicator.cs @@ -1,14 +1,22 @@ +using System; using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_ActivityIndicatorRenderer))] - public class ActivityIndicator : View + public class ActivityIndicator : View, IElementConfiguration<ActivityIndicator> { public static readonly BindableProperty IsRunningProperty = BindableProperty.Create("IsRunning", typeof(bool), typeof(ActivityIndicator), default(bool)); public static readonly BindableProperty ColorProperty = BindableProperty.Create("Color", typeof(Color), typeof(ActivityIndicator), Color.Default); + readonly Lazy<PlatformConfigurationRegistry<ActivityIndicator>> _platformConfigurationRegistry; + + public ActivityIndicator() + { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<ActivityIndicator>>(() => new PlatformConfigurationRegistry<ActivityIndicator>(this)); + } + public Color Color { get { return (Color)GetValue(ColorProperty); } @@ -20,5 +28,9 @@ namespace Xamarin.Forms get { return (bool)GetValue(IsRunningProperty); } set { SetValue(IsRunningProperty, value); } } + public IPlatformElementConfiguration<T, ActivityIndicator> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/Application.cs b/Xamarin.Forms.Core/Application.cs index 4b5a91af..c6943817 100644 --- a/Xamarin.Forms.Core/Application.cs +++ b/Xamarin.Forms.Core/Application.cs @@ -6,10 +6,11 @@ using Xamarin.Forms.Platform; namespace Xamarin.Forms { - public class Application : Element, IResourcesProvider, IApplicationController + public class Application : Element, IResourcesProvider, IApplicationController, IElementConfiguration<Application> { static Application s_current; readonly Task<IDictionary<string, object>> _propertiesTask; + readonly Lazy<PlatformConfigurationRegistry<Application>> _platformConfigurationRegistry; IAppIndexingProvider _appIndexProvider; bool _isSaving; @@ -32,6 +33,7 @@ namespace Xamarin.Forms SystemResources = DependencyService.Get<ISystemResourcesProvider>().GetSystemResources(); SystemResources.ValuesChanged += OnParentResourcesChanged; + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Application>>(() => new PlatformConfigurationRegistry<Application>(this)); } public IAppLinks AppLinks @@ -146,6 +148,11 @@ namespace Xamarin.Forms await SetPropertiesAsync(); } + public IPlatformElementConfiguration<T, Application> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } + protected virtual void OnAppLinkRequestReceived(Uri uri) { } diff --git a/Xamarin.Forms.Core/BoxView.cs b/Xamarin.Forms.Core/BoxView.cs index 79fef390..9a7a4f77 100644 --- a/Xamarin.Forms.Core/BoxView.cs +++ b/Xamarin.Forms.Core/BoxView.cs @@ -4,16 +4,28 @@ using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_BoxViewRenderer))] - public class BoxView : View + public class BoxView : View, IElementConfiguration<BoxView> { public static readonly BindableProperty ColorProperty = BindableProperty.Create("Color", typeof(Color), typeof(BoxView), Color.Default); + readonly Lazy<PlatformConfigurationRegistry<BoxView>> _platformConfigurationRegistry; + + public BoxView() + { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<BoxView>>(() => new PlatformConfigurationRegistry<BoxView>(this)); + } + public Color Color { get { return (Color)GetValue(ColorProperty); } set { SetValue(ColorProperty, value); } } + public IPlatformElementConfiguration<T, BoxView> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } + [Obsolete("Use OnMeasure")] protected override SizeRequest OnSizeRequest(double widthConstraint, double heightConstraint) { diff --git a/Xamarin.Forms.Core/Button.cs b/Xamarin.Forms.Core/Button.cs index 72f98814..31573076 100644 --- a/Xamarin.Forms.Core/Button.cs +++ b/Xamarin.Forms.Core/Button.cs @@ -8,7 +8,7 @@ using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_ButtonRenderer))] - public class Button : View, IFontElement, IButtonController + public class Button : View, IFontElement, IButtonController, IElementConfiguration<Button> { public static readonly BindableProperty CommandProperty = BindableProperty.Create("Command", typeof(ICommand), typeof(Button), null, propertyChanged: (bo, o, n) => ((Button)bo).OnCommandChanged()); @@ -43,6 +43,8 @@ namespace Xamarin.Forms propertyChanging: (bindable, oldvalue, newvalue) => ((Button)bindable).OnSourcePropertyChanging((ImageSource)oldvalue, (ImageSource)newvalue), propertyChanged: (bindable, oldvalue, newvalue) => ((Button)bindable).OnSourcePropertyChanged((ImageSource)oldvalue, (ImageSource)newvalue)); + readonly Lazy<PlatformConfigurationRegistry<Button>> _platformConfigurationRegistry; + bool _cancelEvents; const double DefaultSpacing = 10; @@ -144,6 +146,16 @@ namespace Xamarin.Forms public event EventHandler Clicked; + public Button() + { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Button>>(() => new PlatformConfigurationRegistry<Button>(this)); + } + + public IPlatformElementConfiguration<T, Button> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } + protected override void OnBindingContextChanged() { FileImageSource image = Image; diff --git a/Xamarin.Forms.Core/CarouselPage.cs b/Xamarin.Forms.Core/CarouselPage.cs index a6f769e5..b7d494cb 100644 --- a/Xamarin.Forms.Core/CarouselPage.cs +++ b/Xamarin.Forms.Core/CarouselPage.cs @@ -1,10 +1,23 @@ +using System; using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_CarouselPageRenderer))] - public class CarouselPage : MultiPage<ContentPage> + public class CarouselPage : MultiPage<ContentPage>, IElementConfiguration<CarouselPage> { + readonly Lazy<PlatformConfigurationRegistry<CarouselPage>> _platformConfigurationRegistry; + + public CarouselPage() + { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<CarouselPage>>(() => new PlatformConfigurationRegistry<CarouselPage>(this)); + } + + public new IPlatformElementConfiguration<T, CarouselPage> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } + protected override ContentPage CreateDefault(object item) { var page = new ContentPage(); diff --git a/Xamarin.Forms.Core/Configuration.cs b/Xamarin.Forms.Core/Configuration.cs new file mode 100644 index 00000000..0e00d942 --- /dev/null +++ b/Xamarin.Forms.Core/Configuration.cs @@ -0,0 +1,21 @@ + +namespace Xamarin.Forms +{ + public class Configuration<TPlatform, TElement> : IPlatformElementConfiguration<TPlatform, TElement> + where TPlatform : IConfigPlatform + where TElement : Element + + { + public Configuration(TElement element) + { + Element = element; + } + + public TElement Element { get; } + + public static Configuration<TPlatform, TElement> Create(TElement element) + { + return new Configuration<TPlatform, TElement>(element); + } + } +} diff --git a/Xamarin.Forms.Core/DatePicker.cs b/Xamarin.Forms.Core/DatePicker.cs index 20eecae4..9ef7a7eb 100644 --- a/Xamarin.Forms.Core/DatePicker.cs +++ b/Xamarin.Forms.Core/DatePicker.cs @@ -4,7 +4,7 @@ using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_DatePickerRenderer))] - public class DatePicker : View + public class DatePicker : View, IElementConfiguration<DatePicker> { public static readonly BindableProperty FormatProperty = BindableProperty.Create(nameof(Format), typeof(string), typeof(DatePicker), "d"); @@ -19,6 +19,13 @@ namespace Xamarin.Forms public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(DatePicker), Color.Default); + readonly Lazy<PlatformConfigurationRegistry<DatePicker>> _platformConfigurationRegistry; + + public DatePicker() + { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<DatePicker>>(() => new PlatformConfigurationRegistry<DatePicker>(this)); + } + public DateTime Date { get { return (DateTime)GetValue(DateProperty); } @@ -103,5 +110,10 @@ namespace Xamarin.Forms { return (DateTime)value <= ((DatePicker)bindable).MaximumDate; } + + public IPlatformElementConfiguration<T, DatePicker> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/Editor.cs b/Xamarin.Forms.Core/Editor.cs index 949c0865..26c6fd4c 100644 --- a/Xamarin.Forms.Core/Editor.cs +++ b/Xamarin.Forms.Core/Editor.cs @@ -4,7 +4,7 @@ using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_EditorRenderer))] - public class Editor : InputView, IFontElement + public class Editor : InputView, IFontElement, IElementConfiguration<Editor> { public static readonly BindableProperty TextProperty = BindableProperty.Create("Text", typeof(string), typeof(Editor), null, BindingMode.TwoWay, propertyChanged: (bindable, oldValue, newValue) => { @@ -21,6 +21,7 @@ namespace Xamarin.Forms public static readonly BindableProperty FontAttributesProperty = BindableProperty.Create("FontAttributes", typeof(FontAttributes), typeof(Editor), FontAttributes.None); public static readonly BindableProperty TextColorProperty = BindableProperty.Create("TextColor", typeof(Color), typeof(Editor), Color.Default); + readonly Lazy<PlatformConfigurationRegistry<Editor>> _platformConfigurationRegistry; public string Text { @@ -57,6 +58,16 @@ namespace Xamarin.Forms public event EventHandler<TextChangedEventArgs> TextChanged; + public Editor() + { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Editor>>(() => new PlatformConfigurationRegistry<Editor>(this)); + } + + public IPlatformElementConfiguration<T, Editor> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } + internal void SendCompleted() { EventHandler handler = Completed; diff --git a/Xamarin.Forms.Core/Element.cs b/Xamarin.Forms.Core/Element.cs index 3bfa5cd6..19d7d855 100644 --- a/Xamarin.Forms.Core/Element.cs +++ b/Xamarin.Forms.Core/Element.cs @@ -254,6 +254,16 @@ namespace Xamarin.Forms SetValueCore(property, value); } + bool IElementController.EffectIsAttached(string name) + { + foreach (var effect in Effects) + { + if (effect.ResolveId == name) + return true; + } + return false; + } + object INameScope.FindByName(string name) { INameScope namescope = GetNameScope(); diff --git a/Xamarin.Forms.Core/Entry.cs b/Xamarin.Forms.Core/Entry.cs index 1ee2f856..ac16dc52 100644 --- a/Xamarin.Forms.Core/Entry.cs +++ b/Xamarin.Forms.Core/Entry.cs @@ -4,7 +4,7 @@ using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_EntryRenderer))] - public class Entry : InputView, IFontElement, IEntryController + public class Entry : InputView, IFontElement, IEntryController, IElementConfiguration<Entry> { public static readonly BindableProperty PlaceholderProperty = BindableProperty.Create("Placeholder", typeof(string), typeof(Entry), default(string)); @@ -25,6 +25,13 @@ namespace Xamarin.Forms public static readonly BindableProperty FontAttributesProperty = BindableProperty.Create("FontAttributes", typeof(FontAttributes), typeof(Entry), FontAttributes.None); + readonly Lazy<PlatformConfigurationRegistry<Entry>> _platformConfigurationRegistry; + + public Entry() + { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Entry>>(() => new PlatformConfigurationRegistry<Entry>(this)); + } + public TextAlignment HorizontalTextAlignment { get { return (TextAlignment)GetValue(HorizontalTextAlignmentProperty); } @@ -95,5 +102,10 @@ namespace Xamarin.Forms entry.TextChanged?.Invoke(entry, new TextChangedEventArgs((string)oldValue, (string)newValue)); } + + public IPlatformElementConfiguration<T, Entry> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/Frame.cs b/Xamarin.Forms.Core/Frame.cs index 01f409e4..a298c0f0 100644 --- a/Xamarin.Forms.Core/Frame.cs +++ b/Xamarin.Forms.Core/Frame.cs @@ -1,18 +1,22 @@ +using System; using Xamarin.Forms.Platform; namespace Xamarin.Forms { [ContentProperty("Content")] [RenderWith(typeof(_FrameRenderer))] - public class Frame : ContentView + public class Frame : ContentView, IElementConfiguration<Frame> { public static readonly BindableProperty OutlineColorProperty = BindableProperty.Create("OutlineColor", typeof(Color), typeof(Frame), Color.Default); public static readonly BindableProperty HasShadowProperty = BindableProperty.Create("HasShadow", typeof(bool), typeof(Frame), true); + readonly Lazy<PlatformConfigurationRegistry<Frame>> _platformConfigurationRegistry; + public Frame() { Padding = new Size(20, 20); + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Frame>>(() => new PlatformConfigurationRegistry<Frame>(this)); } public bool HasShadow @@ -26,5 +30,10 @@ namespace Xamarin.Forms get { return (Color)GetValue(OutlineColorProperty); } set { SetValue(OutlineColorProperty, value); } } + + public IPlatformElementConfiguration<T, Frame> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/IConfigElement.cs b/Xamarin.Forms.Core/IConfigElement.cs new file mode 100644 index 00000000..f1ce0b0b --- /dev/null +++ b/Xamarin.Forms.Core/IConfigElement.cs @@ -0,0 +1,8 @@ + +namespace Xamarin.Forms +{ + public interface IConfigElement<out T> where T : Element + { + T Element { get; } + } +} diff --git a/Xamarin.Forms.Core/IConfigPlatform.cs b/Xamarin.Forms.Core/IConfigPlatform.cs new file mode 100644 index 00000000..6f95a8f3 --- /dev/null +++ b/Xamarin.Forms.Core/IConfigPlatform.cs @@ -0,0 +1,5 @@ + +namespace Xamarin.Forms +{ + public interface IConfigPlatform { } +} diff --git a/Xamarin.Forms.Core/IElementConfiguration.cs b/Xamarin.Forms.Core/IElementConfiguration.cs new file mode 100644 index 00000000..2086fba7 --- /dev/null +++ b/Xamarin.Forms.Core/IElementConfiguration.cs @@ -0,0 +1,8 @@ + +namespace Xamarin.Forms +{ + public interface IElementConfiguration<out TElement> where TElement : Element + { + IPlatformElementConfiguration<T, TElement> On<T>() where T : IConfigPlatform; + } +} diff --git a/Xamarin.Forms.Core/IElementController.cs b/Xamarin.Forms.Core/IElementController.cs index 41f229c4..24713b0e 100644 --- a/Xamarin.Forms.Core/IElementController.cs +++ b/Xamarin.Forms.Core/IElementController.cs @@ -6,6 +6,8 @@ namespace Xamarin.Forms { IEffectControlProvider EffectControlProvider { get; set; } + bool EffectIsAttached(string name); + void SetValueFromRenderer(BindableProperty property, object value); void SetValueFromRenderer(BindablePropertyKey propertyKey, object value); ReadOnlyCollection<Element> LogicalChildren { get; } diff --git a/Xamarin.Forms.Core/IPlatformElementConfiguration.cs b/Xamarin.Forms.Core/IPlatformElementConfiguration.cs new file mode 100644 index 00000000..43083d34 --- /dev/null +++ b/Xamarin.Forms.Core/IPlatformElementConfiguration.cs @@ -0,0 +1,9 @@ + +namespace Xamarin.Forms +{ + public interface IPlatformElementConfiguration<out TPlatform, out TElement> : IConfigElement<TElement> + where TPlatform : IConfigPlatform + where TElement : Element + { + } +} diff --git a/Xamarin.Forms.Core/Image.cs b/Xamarin.Forms.Core/Image.cs index dd2692ad..5a9386c6 100644 --- a/Xamarin.Forms.Core/Image.cs +++ b/Xamarin.Forms.Core/Image.cs @@ -7,7 +7,7 @@ using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_ImageRenderer))] - public class Image : View, IImageController + public class Image : View, IImageController, IElementConfiguration<Image> { public static readonly BindableProperty SourceProperty = BindableProperty.Create("Source", typeof(ImageSource), typeof(Image), default(ImageSource), propertyChanging: OnSourcePropertyChanging, propertyChanged: OnSourcePropertyChanged); @@ -20,6 +20,13 @@ namespace Xamarin.Forms public static readonly BindableProperty IsLoadingProperty = IsLoadingPropertyKey.BindableProperty; + readonly Lazy<PlatformConfigurationRegistry<Image>> _platformConfigurationRegistry; + + public Image() + { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Image>>(() => new PlatformConfigurationRegistry<Image>(this)); + } + public Aspect Aspect { get { return (Aspect)GetValue(AspectProperty); } @@ -157,5 +164,10 @@ namespace Xamarin.Forms { SetValue(IsLoadingPropertyKey, isLoading); } + + public IPlatformElementConfiguration<T, Image> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/Label.cs b/Xamarin.Forms.Core/Label.cs index a6390b2d..0634e080 100644 --- a/Xamarin.Forms.Core/Label.cs +++ b/Xamarin.Forms.Core/Label.cs @@ -7,17 +7,19 @@ namespace Xamarin.Forms { [ContentProperty("Text")] [RenderWith(typeof(_LabelRenderer))] - public class Label : View, IFontElement + public class Label : View, IFontElement, IElementConfiguration<Label> { public static readonly BindableProperty HorizontalTextAlignmentProperty = BindableProperty.Create("HorizontalTextAlignment", typeof(TextAlignment), typeof(Label), TextAlignment.Start, propertyChanged: OnHorizontalTextAlignmentPropertyChanged); - [Obsolete("XAlignProperty is obsolete. Please use HorizontalTextAlignmentProperty instead.")] public static readonly BindableProperty XAlignProperty = HorizontalTextAlignmentProperty; + [Obsolete("XAlignProperty is obsolete. Please use HorizontalTextAlignmentProperty instead.")] + public static readonly BindableProperty XAlignProperty = HorizontalTextAlignmentProperty; public static readonly BindableProperty VerticalTextAlignmentProperty = BindableProperty.Create("VerticalTextAlignment", typeof(TextAlignment), typeof(Label), TextAlignment.Start, propertyChanged: OnVerticalTextAlignmentPropertyChanged); - [Obsolete("YAlignProperty is obsolete. Please use VerticalTextAlignmentProperty instead.")] public static readonly BindableProperty YAlignProperty = VerticalTextAlignmentProperty; + [Obsolete("YAlignProperty is obsolete. Please use VerticalTextAlignmentProperty instead.")] + public static readonly BindableProperty YAlignProperty = VerticalTextAlignmentProperty; public static readonly BindableProperty TextColorProperty = BindableProperty.Create("TextColor", typeof(Color), typeof(Label), Color.Default); @@ -50,6 +52,13 @@ namespace Xamarin.Forms public static readonly BindableProperty LineBreakModeProperty = BindableProperty.Create("LineBreakMode", typeof(LineBreakMode), typeof(Label), LineBreakMode.WordWrap, propertyChanged: (bindable, oldvalue, newvalue) => ((Label)bindable).InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged)); + readonly Lazy<PlatformConfigurationRegistry<Label>> _platformConfigurationRegistry; + + public Label() + { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Label>>(() => new PlatformConfigurationRegistry<Label>(this)); + } + bool _cancelEvents; [Obsolete("Please use the Font attributes which are on the class itself. Obsoleted in v1.3.0")] @@ -284,5 +293,10 @@ namespace Xamarin.Forms label.OnPropertyChanged(nameof(YAlign)); #pragma warning restore 0618 } + + public IPlatformElementConfiguration<T, Label> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/ListView.cs b/Xamarin.Forms.Core/ListView.cs index deebda7f..fa9f738e 100644 --- a/Xamarin.Forms.Core/ListView.cs +++ b/Xamarin.Forms.Core/ListView.cs @@ -8,7 +8,7 @@ using Xamarin.Forms.Internals; namespace Xamarin.Forms { [RenderWith(typeof(_ListViewRenderer))] - public class ListView : ItemsView<Cell>, IListViewController + public class ListView : ItemsView<Cell>, IListViewController, IElementConfiguration<ListView> { public static readonly BindableProperty IsPullToRefreshEnabledProperty = BindableProperty.Create("IsPullToRefreshEnabled", typeof(bool), typeof(ListView), false); @@ -43,6 +43,8 @@ namespace Xamarin.Forms public static readonly BindableProperty SeparatorColorProperty = BindableProperty.Create("SeparatorColor", typeof(Color), typeof(ListView), Color.Default); + readonly Lazy<PlatformConfigurationRegistry<ListView>> _platformConfigurationRegistry; + BindingBase _groupDisplayBinding; BindingBase _groupShortNameBinding; @@ -64,6 +66,7 @@ namespace Xamarin.Forms TemplatedItems.IsGroupingEnabledProperty = IsGroupingEnabledProperty; TemplatedItems.GroupHeaderTemplateProperty = GroupHeaderTemplateProperty; + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<ListView>>(() => new PlatformConfigurationRegistry<ListView>(this)); } public ListView([Parameter("CachingStrategy")] ListViewCachingStrategy cachingStrategy) : this() @@ -573,5 +576,10 @@ namespace Xamarin.Forms var template = (DataTemplate)value; return template.CreateContent() is View; } + + public IPlatformElementConfiguration<T, ListView> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/MasterDetailPage.cs b/Xamarin.Forms.Core/MasterDetailPage.cs index 61cc42db..2ab08e98 100644 --- a/Xamarin.Forms.Core/MasterDetailPage.cs +++ b/Xamarin.Forms.Core/MasterDetailPage.cs @@ -1,10 +1,11 @@ using System; +using System.Collections.Generic; using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_MasterDetailPageRenderer))] - public class MasterDetailPage : Page, IMasterDetailPageController + public class MasterDetailPage : Page, IMasterDetailPageController, IElementConfiguration<MasterDetailPage> { public static readonly BindableProperty IsGestureEnabledProperty = BindableProperty.Create("IsGestureEnabled", typeof(bool), typeof(MasterDetailPage), true); @@ -237,5 +238,17 @@ namespace Xamarin.Forms var page = (MasterDetailPage)sender; UpdateMasterBehavior(page); } + + public MasterDetailPage() + { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<MasterDetailPage>>(() => new PlatformConfigurationRegistry<MasterDetailPage>(this)); + } + + readonly Lazy<PlatformConfigurationRegistry<MasterDetailPage>> _platformConfigurationRegistry; + + public new IPlatformElementConfiguration<T, MasterDetailPage> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/NavigationMenu.cs b/Xamarin.Forms.Core/NavigationMenu.cs index 2386dd29..2283bd51 100644 --- a/Xamarin.Forms.Core/NavigationMenu.cs +++ b/Xamarin.Forms.Core/NavigationMenu.cs @@ -7,10 +7,17 @@ namespace Xamarin.Forms { // Mark as internal until renderers are ready for release after 1.0 [RenderWith(typeof(_NavigationMenuRenderer))] - internal class NavigationMenu : View + internal class NavigationMenu : View, IElementConfiguration<NavigationMenu> { readonly List<Page> _targets = new List<Page>(); + readonly Lazy<PlatformConfigurationRegistry<NavigationMenu>> _platformConfigurationRegistry; + + public NavigationMenu() + { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<NavigationMenu>>(() => new PlatformConfigurationRegistry<NavigationMenu>(this)); + } + public IEnumerable<Page> Targets { get { return _targets; } @@ -52,6 +59,11 @@ namespace Xamarin.Forms } } + public IPlatformElementConfiguration<T, NavigationMenu> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } + internal void SendTargetSelected(Page target) { TargetSelected(target); diff --git a/Xamarin.Forms.Core/NavigationPage.cs b/Xamarin.Forms.Core/NavigationPage.cs index d7fb5f3e..7b393b9c 100644 --- a/Xamarin.Forms.Core/NavigationPage.cs +++ b/Xamarin.Forms.Core/NavigationPage.cs @@ -8,7 +8,7 @@ using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_NavigationPageRenderer))] - public class NavigationPage : Page, IPageContainer<Page>, INavigationPageController + public class NavigationPage : Page, IPageContainer<Page>, INavigationPageController, IElementConfiguration<NavigationPage> { public static readonly BindableProperty BackButtonTitleProperty = BindableProperty.CreateAttached("BackButtonTitle", typeof(string), typeof(Page), null); @@ -27,9 +27,11 @@ namespace Xamarin.Forms static readonly BindablePropertyKey CurrentPagePropertyKey = BindableProperty.CreateReadOnly("CurrentPage", typeof(Page), typeof(NavigationPage), null); public static readonly BindableProperty CurrentPageProperty = CurrentPagePropertyKey.BindableProperty; - + public NavigationPage() { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<NavigationPage>>(() => new PlatformConfigurationRegistry<NavigationPage>(this)); + Navigation = new NavigationImpl(this); } @@ -441,5 +443,12 @@ namespace Xamarin.Forms Owner.RemovePage(page); } } + + readonly Lazy<PlatformConfigurationRegistry<NavigationPage>> _platformConfigurationRegistry; + + public new IPlatformElementConfiguration<T, NavigationPage> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/OpenGLView.cs b/Xamarin.Forms.Core/OpenGLView.cs index 530a2f0d..39e49a90 100644 --- a/Xamarin.Forms.Core/OpenGLView.cs +++ b/Xamarin.Forms.Core/OpenGLView.cs @@ -4,12 +4,14 @@ using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_OpenGLViewRenderer))] - public sealed class OpenGLView : View, IOpenGlViewController + public sealed class OpenGLView : View, IOpenGlViewController, IElementConfiguration<OpenGLView> { #region Statics public static readonly BindableProperty HasRenderLoopProperty = BindableProperty.Create("HasRenderLoop", typeof(bool), typeof(OpenGLView), default(bool)); + readonly Lazy<PlatformConfigurationRegistry<OpenGLView>> _platformConfigurationRegistry; + #endregion public bool HasRenderLoop @@ -34,5 +36,15 @@ namespace Xamarin.Forms } event EventHandler DisplayRequested; + + public OpenGLView() + { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<OpenGLView>>(() => new PlatformConfigurationRegistry<OpenGLView>(this)); + } + + public IPlatformElementConfiguration<T, OpenGLView> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/Page.cs b/Xamarin.Forms.Core/Page.cs index 7c21a3b9..87b54bd3 100644 --- a/Xamarin.Forms.Core/Page.cs +++ b/Xamarin.Forms.Core/Page.cs @@ -11,7 +11,7 @@ using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_PageRenderer))] - public class Page : VisualElement, ILayout, IPageController + public class Page : VisualElement, ILayout, IPageController, IElementConfiguration<Page> { public const string BusySetSignalName = "Xamarin.BusySet"; @@ -35,6 +35,8 @@ namespace Xamarin.Forms public static readonly BindableProperty IconProperty = BindableProperty.Create("Icon", typeof(FileImageSource), typeof(Page), default(FileImageSource)); + readonly Lazy<PlatformConfigurationRegistry<Page>> _platformConfigurationRegistry; + bool _allocatedFlag; Rectangle _containerArea; @@ -53,6 +55,7 @@ namespace Xamarin.Forms toolbarItems.CollectionChanged += OnToolbarItemsCollectionChanged; ToolbarItems = toolbarItems; PageController.InternalChildren.CollectionChanged += InternalChildrenOnCollectionChanged; + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Page>>(() => new PlatformConfigurationRegistry<Page>(this)); } public string BackgroundImage @@ -401,5 +404,10 @@ namespace Xamarin.Forms } return !any; } + + public IPlatformElementConfiguration<T, Page> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/Picker.cs b/Xamarin.Forms.Core/Picker.cs index 5c2fb72b..d5f60e9d 100644 --- a/Xamarin.Forms.Core/Picker.cs +++ b/Xamarin.Forms.Core/Picker.cs @@ -6,7 +6,7 @@ using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_PickerRenderer))] - public class Picker : View + public class Picker : View, IElementConfiguration<Picker> { public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(Picker), Color.Default); @@ -20,10 +20,13 @@ namespace Xamarin.Forms eh(bindable, EventArgs.Empty); }, coerceValue: CoerceSelectedIndex); + readonly Lazy<PlatformConfigurationRegistry<Picker>> _platformConfigurationRegistry; + public Picker() { Items = new ObservableList<string>(); ((ObservableList<string>)Items).CollectionChanged += OnItemsCollectionChanged; + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Picker>>(() => new PlatformConfigurationRegistry<Picker>(this)); } public IList<string> Items { get; } @@ -58,5 +61,10 @@ namespace Xamarin.Forms { SelectedIndex = SelectedIndex.Clamp(-1, Items.Count - 1); } + + public IPlatformElementConfiguration<T, Picker> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/PlatformConfiguration/AndroidSpecific/Application.cs b/Xamarin.Forms.Core/PlatformConfiguration/AndroidSpecific/Application.cs new file mode 100644 index 00000000..9366019f --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfiguration/AndroidSpecific/Application.cs @@ -0,0 +1,38 @@ +namespace Xamarin.Forms.PlatformConfiguration.AndroidSpecific +{ + using FormsElement = Forms.Application; + + public enum WindowSoftInputModeAdjust + { + Pan, + Resize + } + + public static class Application + { + public static readonly BindableProperty WindowSoftInputModeAdjustProperty = + BindableProperty.Create("WindowSoftInputModeAdjust", typeof(WindowSoftInputModeAdjust), + typeof(Application), WindowSoftInputModeAdjust.Pan); + + public static WindowSoftInputModeAdjust GetWindowSoftInputModeAdjust(BindableObject element) + { + return (WindowSoftInputModeAdjust)element.GetValue(WindowSoftInputModeAdjustProperty); + } + + public static void SetWindowSoftInputModeAdjust(BindableObject element, WindowSoftInputModeAdjust value) + { + element.SetValue(WindowSoftInputModeAdjustProperty, value); + } + + public static WindowSoftInputModeAdjust GetWindowSoftInputModeAdjust(this IPlatformElementConfiguration<Android, FormsElement> config) + { + return GetWindowSoftInputModeAdjust(config.Element); + } + + public static IPlatformElementConfiguration<Android, FormsElement> UseWindowSoftInputModeAdjust(this IPlatformElementConfiguration<Android, FormsElement> config, WindowSoftInputModeAdjust value) + { + SetWindowSoftInputModeAdjust(config.Element, value); + return config; + } + } +} diff --git a/Xamarin.Forms.Core/PlatformConfiguration/ExtensionPoints.cs b/Xamarin.Forms.Core/PlatformConfiguration/ExtensionPoints.cs new file mode 100644 index 00000000..341d9319 --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfiguration/ExtensionPoints.cs @@ -0,0 +1,7 @@ + +namespace Xamarin.Forms.PlatformConfiguration +{ + public sealed class Android : IConfigPlatform { } + public sealed class iOS : IConfigPlatform { } + public sealed class Windows : IConfigPlatform { } +} diff --git a/Xamarin.Forms.Core/PlatformConfiguration/WindowsSpecific/CollapseStyle.cs b/Xamarin.Forms.Core/PlatformConfiguration/WindowsSpecific/CollapseStyle.cs new file mode 100644 index 00000000..afd9b51d --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfiguration/WindowsSpecific/CollapseStyle.cs @@ -0,0 +1,9 @@ + +namespace Xamarin.Forms.PlatformConfiguration.WindowsSpecific +{ + public enum CollapseStyle + { + Full, + Partial + } +} diff --git a/Xamarin.Forms.Core/PlatformConfiguration/WindowsSpecific/MasterDetailPage.cs b/Xamarin.Forms.Core/PlatformConfiguration/WindowsSpecific/MasterDetailPage.cs new file mode 100644 index 00000000..abfaec4d --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfiguration/WindowsSpecific/MasterDetailPage.cs @@ -0,0 +1,76 @@ +using System; + +namespace Xamarin.Forms.PlatformConfiguration.WindowsSpecific +{ + using FormsElement = Forms.MasterDetailPage; + + public static class MasterDetailPage + { + #region CollapsedStyle + + public static readonly BindableProperty CollapseStyleProperty = + BindableProperty.CreateAttached("CollapseStyle", typeof(CollapseStyle), + typeof(MasterDetailPage), CollapseStyle.Full); + + public static CollapseStyle GetCollapseStyle(BindableObject element) + { + return (CollapseStyle)element.GetValue(CollapseStyleProperty); + } + + public static void SetCollapseStyle(BindableObject element, CollapseStyle collapseStyle) + { + element.SetValue(CollapseStyleProperty, collapseStyle); + } + + public static CollapseStyle GetCollapseStyle(this IPlatformElementConfiguration<Windows, FormsElement> config) + { + return (CollapseStyle)config.Element.GetValue(CollapseStyleProperty); + } + + public static IPlatformElementConfiguration<Windows, FormsElement> SetCollapseStyle( + this IPlatformElementConfiguration<Windows, FormsElement> config, CollapseStyle value) + { + config.Element.SetValue(CollapseStyleProperty, value); + return config; + } + + public static IPlatformElementConfiguration<Windows, FormsElement> UsePartialCollapse( + this IPlatformElementConfiguration<Windows, FormsElement> config) + { + SetCollapseStyle(config, CollapseStyle.Partial); + return config; + } + + #endregion + + #region CollapsedPaneWidth + + public static readonly BindableProperty CollapsedPaneWidthProperty = + BindableProperty.CreateAttached("CollapsedPaneWidth", typeof(double), + typeof(MasterDetailPage), 48d, validateValue: (bindable, value) => (double)value >= 0); + + public static double GetCollapsedPaneWidth(BindableObject element) + { + return (double)element.GetValue(CollapsedPaneWidthProperty); + } + + public static void SetCollapsedPaneWidth(BindableObject element, double collapsedPaneWidth) + { + element.SetValue(CollapsedPaneWidthProperty, collapsedPaneWidth); + } + + public static double CollapsedPaneWidth(this IPlatformElementConfiguration<Windows, FormsElement> config) + { + return (double)config.Element.GetValue(CollapsedPaneWidthProperty); + } + + public static IPlatformElementConfiguration<Windows, FormsElement> CollapsedPaneWidth( + this IPlatformElementConfiguration<Windows, FormsElement> config, double value) + { + config.Element.SetValue(CollapsedPaneWidthProperty, value); + return config; + } + + #endregion + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Core/PlatformConfiguration/WindowsSpecific/Page.cs b/Xamarin.Forms.Core/PlatformConfiguration/WindowsSpecific/Page.cs new file mode 100644 index 00000000..59e53b5f --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfiguration/WindowsSpecific/Page.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Xamarin.Forms.PlatformConfiguration.WindowsSpecific +{ + using FormsElement = Forms.Page; + + public static class Page + { + #region ToolbarPlacement + + public static readonly BindableProperty ToolbarPlacementProperty = + BindableProperty.CreateAttached("ToolbarPlacement", typeof(ToolbarPlacement), + typeof(Page), ToolbarPlacement.Default); + + public static ToolbarPlacement GetToolbarPlacement(BindableObject element) + { + return (ToolbarPlacement)element.GetValue(ToolbarPlacementProperty); + } + + public static void SetToolbarPlacement(BindableObject element, ToolbarPlacement toolbarPlacement) + { + element.SetValue(ToolbarPlacementProperty, toolbarPlacement); + } + + public static ToolbarPlacement GetToolbarPlacement(this IPlatformElementConfiguration<Windows, FormsElement> config) + { + return (ToolbarPlacement)config.Element.GetValue(ToolbarPlacementProperty); + } + + public static IPlatformElementConfiguration<Windows, FormsElement> SetToolbarPlacement( + this IPlatformElementConfiguration<Windows, FormsElement> config, ToolbarPlacement value) + { + config.Element.SetValue(ToolbarPlacementProperty, value); + return config; + } + + #endregion + } +} diff --git a/Xamarin.Forms.Core/PlatformConfiguration/WindowsSpecific/ToolbarPlacement.cs b/Xamarin.Forms.Core/PlatformConfiguration/WindowsSpecific/ToolbarPlacement.cs new file mode 100644 index 00000000..60fbdc25 --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfiguration/WindowsSpecific/ToolbarPlacement.cs @@ -0,0 +1,23 @@ +namespace Xamarin.Forms.PlatformConfiguration.WindowsSpecific +{ + public enum ToolbarPlacement + { + /// <summary> + /// Default will place the Toolbar at the bottom of the screen on phones and + /// at the top of the screen on larger devices + /// </summary> + Default, + + /// <summary> + /// Always place the Toolbar at the top of the screen + /// </summary> + Top, + + /// <summary> + /// Always place the Toolbar at the bottom of the screen + /// </summary> + Bottom + } + + +}
\ No newline at end of file diff --git a/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/BlurEffectStyle.cs b/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/BlurEffectStyle.cs new file mode 100644 index 00000000..d6c46e26 --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/BlurEffectStyle.cs @@ -0,0 +1,20 @@ +namespace Xamarin.Forms.PlatformConfiguration.iOSSpecific +{ + + public enum BlurEffectStyle + { + None, + /// <summary> + /// Available in iOS 8.0 and later. + /// </summary> + ExtraLight, + /// <summary> + /// Available in iOS 8.0 and later. + /// </summary> + Light, + /// <summary> + /// Available in iOS 8.0 and later. + /// </summary> + Dark + } +} diff --git a/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/NavigationPage.cs b/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/NavigationPage.cs new file mode 100644 index 00000000..4ca5976a --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/NavigationPage.cs @@ -0,0 +1,45 @@ + +namespace Xamarin.Forms.PlatformConfiguration.iOSSpecific +{ + using FormsElement = Forms.NavigationPage; + + public static class NavigationPage + { + public static readonly BindableProperty IsNavigationBarTranslucentProperty = + BindableProperty.Create("IsNavigationBarTranslucent", typeof(bool), + typeof(NavigationPage), false); + + public static bool GetIsNavigationBarTranslucent(BindableObject element) + { + return (bool)element.GetValue(IsNavigationBarTranslucentProperty); + } + + public static void SetIsNavigationBarTranslucent(BindableObject element, bool value) + { + element.SetValue(IsNavigationBarTranslucentProperty, value); + } + + public static bool IsNavigationBarTranslucent(this IPlatformElementConfiguration<iOS, FormsElement> config) + { + return GetIsNavigationBarTranslucent(config.Element); + } + + public static IPlatformElementConfiguration<iOS, FormsElement> SetIsNavigationBarTranslucent(this IPlatformElementConfiguration<iOS, FormsElement> config, bool value) + { + SetIsNavigationBarTranslucent(config.Element, value); + return config; + } + + public static IPlatformElementConfiguration<iOS, FormsElement> EnableTranslucentNavigationBar(this IPlatformElementConfiguration<iOS, FormsElement> config) + { + SetIsNavigationBarTranslucent(config.Element, true); + return config; + } + + public static IPlatformElementConfiguration<iOS, FormsElement>DisableTranslucentNavigationBar(this IPlatformElementConfiguration<iOS, FormsElement> config) + { + SetIsNavigationBarTranslucent(config.Element, false); + return config; + } + } +} diff --git a/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/VisualElement.cs b/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/VisualElement.cs new file mode 100644 index 00000000..1b3760e9 --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfiguration/iOSSpecific/VisualElement.cs @@ -0,0 +1,33 @@ + +namespace Xamarin.Forms.PlatformConfiguration.iOSSpecific +{ + using FormsElement = Forms.VisualElement; + + public static class VisualElement + { + public static readonly BindableProperty BlurEffectProperty = + BindableProperty.Create("BlurEffect", typeof(BlurEffectStyle), + typeof(VisualElement), BlurEffectStyle.None); + + public static BlurEffectStyle GetBlurEffect(BindableObject element) + { + return (BlurEffectStyle)element.GetValue(BlurEffectProperty); + } + + public static void SetBlurEffect(BindableObject element, BlurEffectStyle value) + { + element.SetValue(BlurEffectProperty, value); + } + + public static BlurEffectStyle GetBlurEffect(this IPlatformElementConfiguration<iOS, FormsElement> config) + { + return GetBlurEffect(config.Element); + } + + public static IPlatformElementConfiguration<iOS, FormsElement> UseBlurEffect(this IPlatformElementConfiguration<iOS, FormsElement> config, BlurEffectStyle value) + { + SetBlurEffect(config.Element, value); + return config; + } + } +} diff --git a/Xamarin.Forms.Core/PlatformConfigurationRegistry.cs b/Xamarin.Forms.Core/PlatformConfigurationRegistry.cs new file mode 100644 index 00000000..dada7c6d --- /dev/null +++ b/Xamarin.Forms.Core/PlatformConfigurationRegistry.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; + +namespace Xamarin.Forms +{ + /// <summary> + /// Helper that handles storing and lookup of platform specifics implementations + /// </summary> + /// <typeparam name="TElement">The Element type</typeparam> + internal class PlatformConfigurationRegistry<TElement> : IElementConfiguration<TElement> + where TElement : Element + { + readonly TElement _element; + readonly Dictionary<Type, object> _platformSpecifics = new Dictionary<Type, object>(); + + internal PlatformConfigurationRegistry(TElement element) + { + _element = element; + } + + public IPlatformElementConfiguration<T, TElement> On<T>() where T : IConfigPlatform + { + if (_platformSpecifics.ContainsKey(typeof(T))) + { + return (IPlatformElementConfiguration<T, TElement>)_platformSpecifics[typeof(T)]; + } + + var emptyConfig = Configuration<T, TElement>.Create(_element); + + _platformSpecifics.Add(typeof(T), emptyConfig); + + return emptyConfig; + } + } +} diff --git a/Xamarin.Forms.Core/ProgressBar.cs b/Xamarin.Forms.Core/ProgressBar.cs index cd8addf6..323cc514 100644 --- a/Xamarin.Forms.Core/ProgressBar.cs +++ b/Xamarin.Forms.Core/ProgressBar.cs @@ -1,13 +1,21 @@ +using System; using System.Threading.Tasks; using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_ProgressBarRenderer))] - public class ProgressBar : View + public class ProgressBar : View, IElementConfiguration<ProgressBar> { public static readonly BindableProperty ProgressProperty = BindableProperty.Create("Progress", typeof(double), typeof(ProgressBar), 0d, coerceValue: (bo, v) => ((double)v).Clamp(0, 1)); + readonly Lazy<PlatformConfigurationRegistry<ProgressBar>> _platformConfigurationRegistry; + + public ProgressBar() + { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<ProgressBar>>(() => new PlatformConfigurationRegistry<ProgressBar>(this)); + } + public double Progress { get { return (double)GetValue(ProgressProperty); } @@ -22,5 +30,10 @@ namespace Xamarin.Forms return tcs.Task; } + + public IPlatformElementConfiguration<T, ProgressBar> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/ScrollView.cs b/Xamarin.Forms.Core/ScrollView.cs index 143d0a61..13ae6ad9 100644 --- a/Xamarin.Forms.Core/ScrollView.cs +++ b/Xamarin.Forms.Core/ScrollView.cs @@ -6,7 +6,7 @@ namespace Xamarin.Forms { [ContentProperty("Content")] [RenderWith(typeof(_ScrollViewRenderer))] - public class ScrollView : Layout, IScrollViewController + public class ScrollView : Layout, IScrollViewController, IElementConfiguration<ScrollView> { public static readonly BindableProperty OrientationProperty = BindableProperty.Create("Orientation", typeof(ScrollOrientation), typeof(ScrollView), ScrollOrientation.Vertical); @@ -22,6 +22,8 @@ namespace Xamarin.Forms public static readonly BindableProperty ContentSizeProperty = ContentSizePropertyKey.BindableProperty; + readonly Lazy<PlatformConfigurationRegistry<ScrollView>> _platformConfigurationRegistry; + View _content; TaskCompletionSource<bool> _scrollCompletionSource; @@ -68,6 +70,11 @@ namespace Xamarin.Forms private set { SetValue(ScrollYPropertyKey, value); } } + public ScrollView() + { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<ScrollView>>(() => new PlatformConfigurationRegistry<ScrollView>(this)); + } + Point IScrollViewController.GetScrollPositionForElement(VisualElement item, ScrollToPosition pos) { ScrollToPosition position = pos; @@ -133,6 +140,11 @@ namespace Xamarin.Forms public event EventHandler<ScrolledEventArgs> Scrolled; + public IPlatformElementConfiguration<T, ScrollView> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } + public Task ScrollToAsync(double x, double y, bool animated) { var args = new ScrollToRequestedEventArgs(x, y, animated); diff --git a/Xamarin.Forms.Core/SearchBar.cs b/Xamarin.Forms.Core/SearchBar.cs index 40bf2502..6e2a6c63 100644 --- a/Xamarin.Forms.Core/SearchBar.cs +++ b/Xamarin.Forms.Core/SearchBar.cs @@ -5,7 +5,7 @@ using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_SearchBarRenderer))] - public class SearchBar : View, IFontElement, ISearchBarController + public class SearchBar : View, IFontElement, ISearchBarController, IElementConfiguration<SearchBar> { public static readonly BindableProperty SearchCommandProperty = BindableProperty.Create("SearchCommand", typeof(ICommand), typeof(SearchBar), null, propertyChanged: OnCommandChanged); @@ -37,6 +37,8 @@ namespace Xamarin.Forms public static readonly BindableProperty PlaceholderColorProperty = BindableProperty.Create("PlaceholderColor", typeof(Color), typeof(SearchBar), Color.Default); + readonly Lazy<PlatformConfigurationRegistry<SearchBar>> _platformConfigurationRegistry; + public Color CancelButtonColor { get { return (Color)GetValue(CancelButtonColorProperty); } @@ -113,6 +115,11 @@ namespace Xamarin.Forms public event EventHandler<TextChangedEventArgs> TextChanged; + public SearchBar() + { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<SearchBar>>(() => new PlatformConfigurationRegistry<SearchBar>(this)); + } + void ISearchBarController.OnSearchButtonPressed() { ICommand cmd = SearchCommand; @@ -152,5 +159,10 @@ namespace Xamarin.Forms self.IsEnabledCore = true; } } + + public IPlatformElementConfiguration<T, SearchBar> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/Slider.cs b/Xamarin.Forms.Core/Slider.cs index 6363c410..5f5f5317 100644 --- a/Xamarin.Forms.Core/Slider.cs +++ b/Xamarin.Forms.Core/Slider.cs @@ -4,7 +4,7 @@ using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_SliderRenderer))] - public class Slider : View + public class Slider : View, IElementConfiguration<Slider> { public static readonly BindableProperty MinimumProperty = BindableProperty.Create("Minimum", typeof(double), typeof(Slider), 0d, validateValue: (bindable, value) => { @@ -40,11 +40,14 @@ namespace Xamarin.Forms eh(slider, new ValueChangedEventArgs((double)oldValue, (double)newValue)); }); + readonly Lazy<PlatformConfigurationRegistry<Slider>> _platformConfigurationRegistry; + public Slider() { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Slider>>(() => new PlatformConfigurationRegistry<Slider>(this)); } - public Slider(double min, double max, double val) + public Slider(double min, double max, double val) : this() { if (min >= max) throw new ArgumentOutOfRangeException("min"); @@ -81,5 +84,10 @@ namespace Xamarin.Forms } public event EventHandler<ValueChangedEventArgs> ValueChanged; + + public IPlatformElementConfiguration<T, Slider> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/Stepper.cs b/Xamarin.Forms.Core/Stepper.cs index 2a3de841..f9742ccc 100644 --- a/Xamarin.Forms.Core/Stepper.cs +++ b/Xamarin.Forms.Core/Stepper.cs @@ -4,7 +4,7 @@ using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_StepperRenderer))] - public class Stepper : View + public class Stepper : View, IElementConfiguration<Stepper> { public static readonly BindableProperty MaximumProperty = BindableProperty.Create("Maximum", typeof(double), typeof(Stepper), 100.0, validateValue: (bindable, value) => { @@ -42,8 +42,11 @@ namespace Xamarin.Forms public static readonly BindableProperty IncrementProperty = BindableProperty.Create("Increment", typeof(double), typeof(Stepper), 1.0); + readonly Lazy<PlatformConfigurationRegistry<Stepper>> _platformConfigurationRegistry; + public Stepper() { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Stepper>>(() => new PlatformConfigurationRegistry<Stepper>(this)); } public Stepper(double min, double max, double val, double increment) @@ -90,5 +93,10 @@ namespace Xamarin.Forms } public event EventHandler<ValueChangedEventArgs> ValueChanged; + + public IPlatformElementConfiguration<T, Stepper> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/Switch.cs b/Xamarin.Forms.Core/Switch.cs index 394e050a..73524b04 100644 --- a/Xamarin.Forms.Core/Switch.cs +++ b/Xamarin.Forms.Core/Switch.cs @@ -4,7 +4,7 @@ using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_SwitchRenderer))] - public class Switch : View + public class Switch : View, IElementConfiguration<Switch> { public static readonly BindableProperty IsToggledProperty = BindableProperty.Create("IsToggled", typeof(bool), typeof(Switch), false, propertyChanged: (bindable, oldValue, newValue) => { @@ -13,6 +13,13 @@ namespace Xamarin.Forms eh(bindable, new ToggledEventArgs((bool)newValue)); }, defaultBindingMode: BindingMode.TwoWay); + readonly Lazy<PlatformConfigurationRegistry<Switch>> _platformConfigurationRegistry; + + public Switch() + { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Switch>>(() => new PlatformConfigurationRegistry<Switch>(this)); + } + public bool IsToggled { get { return (bool)GetValue(IsToggledProperty); } @@ -20,5 +27,10 @@ namespace Xamarin.Forms } public event EventHandler<ToggledEventArgs> Toggled; + + public IPlatformElementConfiguration<T, Switch> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/TabbedPage.cs b/Xamarin.Forms.Core/TabbedPage.cs index 5fb6bf9c..ee9b81ff 100644 --- a/Xamarin.Forms.Core/TabbedPage.cs +++ b/Xamarin.Forms.Core/TabbedPage.cs @@ -1,14 +1,17 @@ +using System; using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_TabbedPageRenderer))] - public class TabbedPage : MultiPage<Page> + public class TabbedPage : MultiPage<Page>, IElementConfiguration<TabbedPage> { public static readonly BindableProperty BarBackgroundColorProperty = BindableProperty.Create(nameof(BarBackgroundColor), typeof(Color), typeof(TabbedPage), Color.Default); public static readonly BindableProperty BarTextColorProperty = BindableProperty.Create(nameof(BarTextColor), typeof(Color), typeof(TabbedPage), Color.Default); + readonly Lazy<PlatformConfigurationRegistry<TabbedPage>> _platformConfigurationRegistry; + public Color BarBackgroundColor { get @@ -41,5 +44,15 @@ namespace Xamarin.Forms return page; } + + public TabbedPage() + { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<TabbedPage>>(() => new PlatformConfigurationRegistry<TabbedPage>(this)); + } + + public new IPlatformElementConfiguration<T, TabbedPage> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/TableView.cs b/Xamarin.Forms.Core/TableView.cs index bd9f964e..b6c66800 100644 --- a/Xamarin.Forms.Core/TableView.cs +++ b/Xamarin.Forms.Core/TableView.cs @@ -9,12 +9,14 @@ namespace Xamarin.Forms { [ContentProperty("Root")] [RenderWith(typeof(_TableViewRenderer))] - public class TableView : View, ITableViewController + public class TableView : View, ITableViewController, IElementConfiguration<TableView> { public static readonly BindableProperty RowHeightProperty = BindableProperty.Create("RowHeight", typeof(int), typeof(TableView), -1); public static readonly BindableProperty HasUnevenRowsProperty = BindableProperty.Create("HasUnevenRows", typeof(bool), typeof(TableView), false); + readonly Lazy<PlatformConfigurationRegistry<TableView>> _platformConfigurationRegistry; + readonly TableSectionModel _tableModel; TableIntent _intent = TableIntent.Data; @@ -29,6 +31,7 @@ namespace Xamarin.Forms { VerticalOptions = HorizontalOptions = LayoutOptions.FillAndExpand; Model = _tableModel = new TableSectionModel(this, root); + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<TableView>>(() => new PlatformConfigurationRegistry<TableView>(this)); } public bool HasUnevenRows @@ -127,6 +130,11 @@ namespace Xamarin.Forms remove { ModelChanged -= value; } } + public IPlatformElementConfiguration<T, TableView> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } + void CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { OnModelChanged(); diff --git a/Xamarin.Forms.Core/TimePicker.cs b/Xamarin.Forms.Core/TimePicker.cs index 0a33c2e3..a90b378e 100644 --- a/Xamarin.Forms.Core/TimePicker.cs +++ b/Xamarin.Forms.Core/TimePicker.cs @@ -4,7 +4,7 @@ using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_TimePickerRenderer))] - public class TimePicker : View + public class TimePicker : View, IElementConfiguration<TimePicker> { public static readonly BindableProperty FormatProperty = BindableProperty.Create(nameof(Format), typeof(string), typeof(TimePicker), "t"); @@ -16,6 +16,13 @@ namespace Xamarin.Forms return time.TotalHours < 24 && time.TotalMilliseconds >= 0; }); + readonly Lazy<PlatformConfigurationRegistry<TimePicker>> _platformConfigurationRegistry; + + public TimePicker() + { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<TimePicker>>(() => new PlatformConfigurationRegistry<TimePicker>(this)); + } + public string Format { get { return (string)GetValue(FormatProperty); } @@ -33,5 +40,10 @@ namespace Xamarin.Forms get { return (TimeSpan)GetValue(TimeProperty); } set { SetValue(TimeProperty, value); } } + + public IPlatformElementConfiguration<T, TimePicker> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/WebView.cs b/Xamarin.Forms.Core/WebView.cs index 8f28497c..b366bb4b 100644 --- a/Xamarin.Forms.Core/WebView.cs +++ b/Xamarin.Forms.Core/WebView.cs @@ -5,7 +5,7 @@ using Xamarin.Forms.Platform; namespace Xamarin.Forms { [RenderWith(typeof(_WebViewRenderer))] - public class WebView : View + public class WebView : View, IElementConfiguration<WebView> { public static readonly BindableProperty SourceProperty = BindableProperty.Create("Source", typeof(WebViewSource), typeof(WebView), default(WebViewSource), propertyChanging: (bindable, oldvalue, newvalue) => @@ -32,6 +32,13 @@ namespace Xamarin.Forms public static readonly BindableProperty CanGoForwardProperty = CanGoForwardPropertyKey.BindableProperty; + readonly Lazy<PlatformConfigurationRegistry<WebView>> _platformConfigurationRegistry; + + public WebView() + { + _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<WebView>>(() => new PlatformConfigurationRegistry<WebView>(this)); + } + public bool CanGoBack { get { return (bool)GetValue(CanGoBackProperty); } @@ -122,5 +129,10 @@ namespace Xamarin.Forms if (handler != null) handler(this, args); } + + public IPlatformElementConfiguration<T, WebView> On<T>() where T : IConfigPlatform + { + return _platformConfigurationRegistry.Value.On<T>(); + } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj b/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj index 0541673f..4fa202aa 100644 --- a/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj +++ b/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj @@ -87,6 +87,19 @@ <Compile Include="DateChangedEventArgs.cs" /> <Compile Include="DelegateLogListener.cs" /> <Compile Include="EnumerableExtensions.cs" /> + <Compile Include="PlatformConfiguration\AndroidSpecific\Application.cs" /> + <Compile Include="PlatformConfiguration\ExtensionPoints.cs" /> + <Compile Include="PlatformConfiguration\iOSSpecific\BlurEffectStyle.cs" /> + <Compile Include="PlatformConfiguration\iOSSpecific\NavigationPage.cs" /> + <Compile Include="PlatformConfiguration\iOSSpecific\VisualElement.cs" /> + <Compile Include="PlatformConfiguration\WindowsSpecific\MasterDetailPage.cs" /> + <Compile Include="PlatformConfiguration\WindowsSpecific\CollapseStyle.cs" /> + <Compile Include="Configuration.cs" /> + <Compile Include="IConfigElement.cs" /> + <Compile Include="IConfigPlatform.cs" /> + <Compile Include="IElementConfiguration.cs" /> + <Compile Include="IPlatformElementConfiguration.cs" /> + <Compile Include="PlatformConfigurationRegistry.cs" /> <Compile Include="IFontElement.cs" /> <Compile Include="DependencyAttribute.cs" /> <Compile Include="DependencyFetchTarget.cs" /> @@ -195,6 +208,8 @@ <Compile Include="PanUpdatedEventArgs.cs" /> <Compile Include="Performance.cs" /> <Compile Include="PinchGestureUpdatedEventArgs.cs" /> + <Compile Include="PlatformConfiguration\WindowsSpecific\Page.cs" /> + <Compile Include="PlatformConfiguration\WindowsSpecific\ToolbarPlacement.cs" /> <Compile Include="PlatformEffect.cs" /> <Compile Include="PointTypeConverter.cs" /> <Compile Include="Internals\PreserveAttribute.cs" /> |