summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT
diff options
context:
space:
mode:
authorSamantha Houts <samantha@teamredwall.com>2016-08-30 17:46:14 (GMT)
committerJason Smith <jason.smith@xamarin.com>2016-08-30 17:46:14 (GMT)
commit5e553f6195e66e48688b8ab324f1bab1e9251f0a (patch)
treef8843e5e9e8afe89a05a1cc91c3b7fa05588bac7 /Xamarin.Forms.Platform.WinRT
parentf551654b1cfe654c579ca50978445e7cb93f287d (diff)
downloadxamarin-forms-5e553f6195e66e48688b8ab324f1bab1e9251f0a.zip
xamarin-forms-5e553f6195e66e48688b8ab324f1bab1e9251f0a.tar.gz
xamarin-forms-5e553f6195e66e48688b8ab324f1bab1e9251f0a.tar.bz2
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.Platform.WinRT')
-rw-r--r--Xamarin.Forms.Platform.WinRT/NavigationPageRenderer.cs34
-rw-r--r--Xamarin.Forms.Platform.WinRT/PageControl.xaml.cs65
-rw-r--r--Xamarin.Forms.Platform.WinRT/Platform.cs5
-rw-r--r--Xamarin.Forms.Platform.WinRT/PlatformConfigurationExtensions.cs17
-rw-r--r--Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj1
5 files changed, 95 insertions, 27 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/NavigationPageRenderer.cs b/Xamarin.Forms.Platform.WinRT/NavigationPageRenderer.cs
index df0c023..30a7487 100644
--- a/Xamarin.Forms.Platform.WinRT/NavigationPageRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/NavigationPageRenderer.cs
@@ -13,6 +13,8 @@ using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using Xamarin.Forms.Internals;
+using Xamarin.Forms.PlatformConfiguration.WindowsSpecific;
+
#if WINDOWS_UWP
using Windows.UI.Xaml.Data;
using Windows.UI.Core;
@@ -72,7 +74,7 @@ namespace Xamarin.Forms.Platform.WinRT
{
set
{
- _container.NavigationBarBackground = value;
+ _container.ToolbarBackground = value;
UpdateTitleOnParents();
}
}
@@ -97,7 +99,7 @@ namespace Xamarin.Forms.Platform.WinRT
return;
_showTitle = value;
- UpdateNavigationBarVisible();
+ UpdateTitleVisible();
UpdateTitleOnParents();
}
}
@@ -187,6 +189,7 @@ namespace Xamarin.Forms.Platform.WinRT
LookupRelevantParents();
UpdateTitleColor();
UpdateNavigationBarBackground();
+ UpdateToolbarPlacement();
Element.PropertyChanged += OnElementPropertyChanged;
((INavigationPageController)Element).PushRequested += OnPushRequested;
((INavigationPageController)Element).PopRequested += OnPopRequested;
@@ -258,6 +261,7 @@ namespace Xamarin.Forms.Platform.WinRT
return Element.BarTextColor.ToBrush();
}
+ // TODO EZH Why don't this and GetToolBarProvider ever get called on either platform?
Task<CommandBar> GetCommandBarAsync()
{
var platform = (Platform)Element.Platform;
@@ -332,7 +336,7 @@ namespace Xamarin.Forms.Platform.WinRT
else if (e.PropertyName == NavigationPage.BackButtonTitleProperty.PropertyName)
UpdateBackButtonTitle();
else if (e.PropertyName == NavigationPage.HasNavigationBarProperty.PropertyName)
- UpdateNavigationBarVisible();
+ UpdateTitleVisible();
}
void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
@@ -343,6 +347,8 @@ namespace Xamarin.Forms.Platform.WinRT
UpdateNavigationBarBackground();
else if (e.PropertyName == Page.PaddingProperty.PropertyName)
UpdatePadding();
+ else if (e.PropertyName == PlatformConfiguration.WindowsSpecific.Page.ToolbarPlacementProperty.PropertyName)
+ UpdateToolbarPlacement();
}
void OnLoaded(object sender, RoutedEventArgs args)
@@ -434,7 +440,7 @@ namespace Xamarin.Forms.Platform.WinRT
IVisualElementRenderer renderer = page.GetOrCreateRenderer();
- UpdateNavigationBarVisible();
+ UpdateTitleVisible();
UpdateTitleOnParents();
if (isAnimated && _transition == null)
@@ -484,16 +490,16 @@ namespace Xamarin.Forms.Platform.WinRT
(this as ITitleProvider).BarBackgroundBrush = GetBarBackgroundBrush();
}
- void UpdateNavigationBarVisible()
+ void UpdateTitleVisible()
{
UpdateTitleOnParents();
- bool showing = _container.ShowNavigationBar;
- bool newValue = GetIsNavBarPossible() && NavigationPage.GetHasNavigationBar(_currentPage);
+ bool showing = _container.TitleVisibility == Visibility.Visible;
+ bool newValue = GetIsNavBarPossible() && NavigationPage.GetHasNavigationBar(_currentPage) && !string.IsNullOrEmpty(_currentPage.Title);
if (showing == newValue)
return;
- _container.ShowNavigationBar = newValue;
+ _container.TitleVisibility = newValue ? Visibility.Visible : Visibility.Collapsed;
// Force ContentHeight/Width to update, doesn't work from inside PageControl for some reason
_container.UpdateLayout();
@@ -510,6 +516,18 @@ namespace Xamarin.Forms.Platform.WinRT
(this as ITitleProvider).BarForegroundBrush = GetBarForegroundBrush();
}
+ void UpdateToolbarPlacement()
+ {
+#if WINDOWS_UWP
+ if (_container == null)
+ {
+ return;
+ }
+
+ _container.ToolbarPlacement = Element.OnThisPlatform().GetToolbarPlacement();
+#endif
+ }
+
#pragma warning disable 1998 // considered for removal
async void UpdateTitleOnParents()
#pragma warning restore 1998
diff --git a/Xamarin.Forms.Platform.WinRT/PageControl.xaml.cs b/Xamarin.Forms.Platform.WinRT/PageControl.xaml.cs
index 0991db4..7be51c0 100644
--- a/Xamarin.Forms.Platform.WinRT/PageControl.xaml.cs
+++ b/Xamarin.Forms.Platform.WinRT/PageControl.xaml.cs
@@ -1,7 +1,10 @@
-using System.Threading.Tasks;
+using System.ComponentModel;
+using System.Runtime.CompilerServices;
+using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
+using Xamarin.Forms.PlatformConfiguration.WindowsSpecific;
#if WINDOWS_UWP
@@ -11,7 +14,7 @@ namespace Xamarin.Forms.Platform.UWP
namespace Xamarin.Forms.Platform.WinRT
#endif
{
- public sealed partial class PageControl : IToolbarProvider
+ public sealed partial class PageControl : IToolbarProvider
{
public static readonly DependencyProperty InvisibleBackButtonCollapsedProperty = DependencyProperty.Register("InvisibleBackButtonCollapsed", typeof(bool), typeof(PageControl),
new PropertyMetadata(true, OnInvisibleBackButtonCollapsedChanged));
@@ -19,9 +22,9 @@ namespace Xamarin.Forms.Platform.WinRT
public static readonly DependencyProperty ShowBackButtonProperty = DependencyProperty.Register("ShowBackButton", typeof(bool), typeof(PageControl),
new PropertyMetadata(false, OnShowBackButtonChanged));
- public static readonly DependencyProperty ShowNavigationBarProperty = DependencyProperty.Register("ShowNavigationBar", typeof(bool), typeof(PageControl), new PropertyMetadata(true));
+ public static readonly DependencyProperty TitleVisibilityProperty = DependencyProperty.Register(nameof(TitleVisibility), typeof(Visibility), typeof(PageControl), new PropertyMetadata(Visibility.Visible));
- public static readonly DependencyProperty NavigationBarBackgroundProperty = DependencyProperty.Register("NavigationBarBackground", typeof(Brush), typeof(PageControl),
+ public static readonly DependencyProperty ToolbarBackgroundProperty = DependencyProperty.Register(nameof(ToolbarBackground), typeof(Brush), typeof(PageControl),
new PropertyMetadata(default(Brush)));
public static readonly DependencyProperty BackButtonTitleProperty = DependencyProperty.Register("BackButtonTitle", typeof(string), typeof(PageControl), new PropertyMetadata(false));
@@ -36,10 +39,17 @@ namespace Xamarin.Forms.Platform.WinRT
AppBarButton _backButton;
CommandBar _commandBar;
- TaskCompletionSource<CommandBar> _commandBarTcs;
+#if WINDOWS_UWP
+ ToolbarPlacement _toolbarPlacement;
+ Border _bottomCommandBarArea;
+ Border _topCommandBarArea;
+#endif
+
+ TaskCompletionSource<CommandBar> _commandBarTcs;
Windows.UI.Xaml.Controls.ContentPresenter _presenter;
+
- public PageControl()
+ public PageControl()
{
InitializeComponent();
}
@@ -72,22 +82,34 @@ namespace Xamarin.Forms.Platform.WinRT
set { SetValue(InvisibleBackButtonCollapsedProperty, value); }
}
- public Brush NavigationBarBackground
+ public Brush ToolbarBackground
{
- get { return (Brush)GetValue(NavigationBarBackgroundProperty); }
- set { SetValue(NavigationBarBackgroundProperty, value); }
+ get { return (Brush)GetValue(ToolbarBackgroundProperty); }
+ set { SetValue(ToolbarBackgroundProperty, value); }
}
+#if WINDOWS_UWP
+ public ToolbarPlacement ToolbarPlacement
+ {
+ get { return _toolbarPlacement; }
+ set
+ {
+ _toolbarPlacement = value;
+ UpdateToolbarPlacement();
+ }
+ }
+#endif
+
public bool ShowBackButton
{
get { return (bool)GetValue(ShowBackButtonProperty); }
set { SetValue(ShowBackButtonProperty, value); }
}
- public bool ShowNavigationBar
+ public Visibility TitleVisibility
{
- get { return (bool)GetValue(ShowNavigationBarProperty); }
- set { SetValue(ShowNavigationBarProperty, value); }
+ get { return (Visibility)GetValue(TitleVisibilityProperty); }
+ set { SetValue(TitleVisibilityProperty, value); }
}
public Brush TitleBrush
@@ -125,12 +147,14 @@ namespace Xamarin.Forms.Platform.WinRT
_presenter = GetTemplateChild("presenter") as Windows.UI.Xaml.Controls.ContentPresenter;
_commandBar = GetTemplateChild("CommandBar") as CommandBar;
+#if WINDOWS_UWP
+ _bottomCommandBarArea = GetTemplateChild("BottomCommandBarArea") as Border;
+ _topCommandBarArea = GetTemplateChild("TopCommandBarArea") as Border;
+ UpdateToolbarPlacement();
+#endif
TaskCompletionSource<CommandBar> tcs = _commandBarTcs;
- if (tcs != null)
- {
- tcs.SetResult(_commandBar);
- }
+ tcs?.SetResult(_commandBar);
}
void OnBackClicked(object sender, RoutedEventArgs e)
@@ -162,5 +186,12 @@ namespace Xamarin.Forms.Platform.WinRT
_backButton.Opacity = ShowBackButton ? 1 : 0;
}
- }
+
+#if WINDOWS_UWP
+ void UpdateToolbarPlacement()
+ {
+ ToolbarPlacementHelper.UpdateToolbarPlacement(_commandBar, ToolbarPlacement, _bottomCommandBarArea, _topCommandBarArea);
+ }
+#endif
+ }
} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.WinRT/Platform.cs b/Xamarin.Forms.Platform.WinRT/Platform.cs
index e780d95..c16c896 100644
--- a/Xamarin.Forms.Platform.WinRT/Platform.cs
+++ b/Xamarin.Forms.Platform.WinRT/Platform.cs
@@ -506,8 +506,8 @@ namespace Xamarin.Forms.Platform.WinRT
return _page.BottomAppBar as CommandBar;
#else
IToolbarProvider provider = GetToolbarProvider();
- var titleProvider = provider as ITitleProvider;
- if (provider == null || (titleProvider != null && !titleProvider.ShowTitle))
+ //var titleProvider = provider as ITitleProvider;
+ if (provider == null) // || (titleProvider != null && !titleProvider.ShowTitle))
return null;
return await provider.GetCommandBarAsync();
@@ -521,6 +521,7 @@ namespace Xamarin.Forms.Platform.WinRT
_page.BottomAppBar = commandBar;
return commandBar;
#else
+
var bar = new FormsCommandBar();
if (Device.Idiom != TargetIdiom.Phone)
bar.Style = (Windows.UI.Xaml.Style)Windows.UI.Xaml.Application.Current.Resources["TitleToolbar"];
diff --git a/Xamarin.Forms.Platform.WinRT/PlatformConfigurationExtensions.cs b/Xamarin.Forms.Platform.WinRT/PlatformConfigurationExtensions.cs
new file mode 100644
index 0000000..f488c3c
--- /dev/null
+++ b/Xamarin.Forms.Platform.WinRT/PlatformConfigurationExtensions.cs
@@ -0,0 +1,17 @@
+#if WINDOWS_UWP
+
+namespace Xamarin.Forms.Platform.UWP
+#else
+
+namespace Xamarin.Forms.Platform.WinRT
+#endif
+{
+ public static class PlatformConfigurationExtensions
+ {
+ public static IPlatformElementConfiguration<PlatformConfiguration.Windows, T> OnThisPlatform<T>(this T element)
+ where T : Element, IElementConfiguration<T>
+ {
+ return (element).On<PlatformConfiguration.Windows>();
+ }
+ }
+}
diff --git a/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj b/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj
index 400737d..fd73aae 100644
--- a/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj
+++ b/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj
@@ -66,6 +66,7 @@
<Compile Include="..\Xamarin.Forms.Core\Properties\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
+ <Compile Include="PlatformConfigurationExtensions.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(OS)' != 'Unix' ">
<Compile Include="BrushHelpers.cs" />