summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-04-13 16:38:38 -0700
committerJason Smith <jason.smith@xamarin.com>2016-04-13 16:38:38 -0700
commite7f30c34d51140067bbad4f072bca7e8140d2450 (patch)
tree68cdc71d283dc4779e7050e707fec8b05bf43bf7 /Xamarin.Forms.Platform.iOS
parent840ec020015a257e983a8f783a80031628d502db (diff)
downloadxamarin-forms-e7f30c34d51140067bbad4f072bca7e8140d2450.tar.gz
xamarin-forms-e7f30c34d51140067bbad4f072bca7e8140d2450.tar.bz2
xamarin-forms-e7f30c34d51140067bbad4f072bca7e8140d2450.zip
Page renderer effects (#85)
* [I]PageRenderer Effect support * [I]Add Effect supprt for NavigationPage * [I]Enable Effects on remaining pages
Diffstat (limited to 'Xamarin.Forms.Platform.iOS')
-rw-r--r--Xamarin.Forms.Platform.iOS/EffectUtilities.cs17
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs49
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs41
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs11
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs11
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs11
-rw-r--r--Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs8
-rw-r--r--Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.Classic.csproj1
-rw-r--r--Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.csproj1
9 files changed, 110 insertions, 40 deletions
diff --git a/Xamarin.Forms.Platform.iOS/EffectUtilities.cs b/Xamarin.Forms.Platform.iOS/EffectUtilities.cs
new file mode 100644
index 00000000..c9523479
--- /dev/null
+++ b/Xamarin.Forms.Platform.iOS/EffectUtilities.cs
@@ -0,0 +1,17 @@
+namespace Xamarin.Forms.Platform.iOS
+{
+ internal static class EffectUtilities
+ {
+ public static void RegisterEffectControlProvider(IEffectControlProvider self, IElementController oldElement,
+ IElementController newElement)
+ {
+ IElementController controller = oldElement;
+ if (controller != null && controller.EffectControlProvider == self)
+ controller.EffectControlProvider = null;
+
+ controller = newElement;
+ if (controller != null)
+ controller.EffectControlProvider = self;
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs
index ca690eed..f09fec9a 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs
@@ -26,7 +26,7 @@ using nuint=System.UInt32;
namespace Xamarin.Forms.Platform.iOS
{
- public class NavigationRenderer : UINavigationController, IVisualElementRenderer
+ public class NavigationRenderer : UINavigationController, IVisualElementRenderer, IEffectControlProvider
{
internal const string UpdateToolbarButtons = "Xamarin.UpdateToolbarButtons";
bool _appeared;
@@ -36,7 +36,6 @@ namespace Xamarin.Forms.Platform.iOS
Size _queuedSize;
UIViewController[] _removeControllers;
UIToolbar _secondaryToolbar;
-
VisualElementTracker _tracker;
public NavigationRenderer()
@@ -74,6 +73,8 @@ namespace Xamarin.Forms.Platform.iOS
if (element != null)
element.SendViewInitialized(NativeView);
+
+ EffectUtilities.RegisterEffectControlProvider(this, oldElement, element);
}
public void SetElementSize(Size size)
@@ -174,7 +175,8 @@ namespace Xamarin.Forms.Platform.iOS
double trueBottom = toolbar.Hidden ? toolbarY : toolbar.Frame.Bottom;
var modelSize = _queuedSize.IsZero ? Element.Bounds.Size : _queuedSize;
- ((NavigationPage)Element).ContainerArea = new Rectangle(0, toolbar.Hidden ? 0 : toolbar.Frame.Height, modelSize.Width, modelSize.Height - trueBottom);
+ ((NavigationPage)Element).ContainerArea =
+ new Rectangle(0, toolbar.Hidden ? 0 : toolbar.Frame.Height, modelSize.Width, modelSize.Height - trueBottom);
if (!_queuedSize.IsZero)
{
@@ -211,7 +213,8 @@ namespace Xamarin.Forms.Platform.iOS
if (navPage.CurrentPage == null)
{
- throw new InvalidOperationException("NavigationPage must have a root Page before being used. Either call PushAsync with a valid Page, or pass a Page to the constructor before usage.");
+ throw new InvalidOperationException(
+ "NavigationPage must have a root Page before being used. Either call PushAsync with a valid Page, or pass a Page to the constructor before usage.");
}
navPage.PushRequested += OnPushRequested;
@@ -382,7 +385,8 @@ namespace Xamarin.Forms.Platform.iOS
var titleText = NavigationPage.GetBackButtonTitle(page);
if (titleText != null)
{
- pack.NavigationItem.BackBarButtonItem = new UIBarButtonItem(titleText, UIBarButtonItemStyle.Plain, async (o, e) => await PopViewAsync(page));
+ pack.NavigationItem.BackBarButtonItem =
+ new UIBarButtonItem(titleText, UIBarButtonItemStyle.Plain, async (o, e) => await PopViewAsync(page));
}
var pageRenderer = Platform.GetRenderer(page);
@@ -558,11 +562,15 @@ namespace Xamarin.Forms.Platform.iOS
// Set navigation bar background color
if (Forms.IsiOS7OrNewer)
{
- NavigationBar.BarTintColor = barBackgroundColor == Color.Default ? UINavigationBar.Appearance.BarTintColor : barBackgroundColor.ToUIColor();
+ NavigationBar.BarTintColor = barBackgroundColor == Color.Default
+ ? UINavigationBar.Appearance.BarTintColor
+ : barBackgroundColor.ToUIColor();
}
else
{
- NavigationBar.TintColor = barBackgroundColor == Color.Default ? UINavigationBar.Appearance.TintColor : barBackgroundColor.ToUIColor();
+ NavigationBar.TintColor = barBackgroundColor == Color.Default
+ ? UINavigationBar.Appearance.TintColor
+ : barBackgroundColor.ToUIColor();
}
}
@@ -586,14 +594,18 @@ namespace Xamarin.Forms.Platform.iOS
{
var titleAttributes = new UIStringAttributes();
titleAttributes.Font = globalAttributes.Font;
- titleAttributes.ForegroundColor = barTextColor == Color.Default ? titleAttributes.ForegroundColor ?? UINavigationBar.Appearance.TintColor : barTextColor.ToUIColor();
+ titleAttributes.ForegroundColor = barTextColor == Color.Default
+ ? titleAttributes.ForegroundColor ?? UINavigationBar.Appearance.TintColor
+ : barTextColor.ToUIColor();
NavigationBar.TitleTextAttributes = titleAttributes;
}
// set Tint color (i. e. Back Button arrow and Text)
if (Forms.IsiOS7OrNewer)
{
- NavigationBar.TintColor = barTextColor == Color.Default ? UINavigationBar.Appearance.TintColor : barTextColor.ToUIColor();
+ NavigationBar.TintColor = barTextColor == Color.Default
+ ? UINavigationBar.Appearance.TintColor
+ : barTextColor.ToUIColor();
}
if (barTextColor.Luminosity > 0.5)
@@ -626,8 +638,9 @@ namespace Xamarin.Forms.Platform.iOS
{
try
{
- containerController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(new UIImage(_parentMasterDetailPage.Master.Icon), UIBarButtonItemStyle.Plain,
- (o, e) => _parentMasterDetailPage.IsPresented = !_parentMasterDetailPage.IsPresented);
+ containerController.NavigationItem.LeftBarButtonItem =
+ new UIBarButtonItem(new UIImage(_parentMasterDetailPage.Master.Icon), UIBarButtonItemStyle.Plain,
+ (o, e) => _parentMasterDetailPage.IsPresented = !_parentMasterDetailPage.IsPresented);
}
catch (Exception)
{
@@ -638,7 +651,8 @@ namespace Xamarin.Forms.Platform.iOS
if (!shouldUseIcon)
{
- containerController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(_parentMasterDetailPage.Master.Title, UIBarButtonItemStyle.Plain,
+ containerController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(_parentMasterDetailPage.Master.Title,
+ UIBarButtonItemStyle.Plain,
(o, e) => _parentMasterDetailPage.IsPresented = !_parentMasterDetailPage.IsPresented);
}
}
@@ -650,7 +664,9 @@ namespace Xamarin.Forms.Platform.iOS
#pragma warning restore 0618
if (Forms.IsiOS7OrNewer)
{
- NavigationBar.BarTintColor = tintColor == Color.Default ? UINavigationBar.Appearance.BarTintColor : tintColor.ToUIColor();
+ NavigationBar.BarTintColor = tintColor == Color.Default
+ ? UINavigationBar.Appearance.BarTintColor
+ : tintColor.ToUIColor();
if (tintColor == Color.Default)
NavigationBar.TintColor = UINavigationBar.Appearance.TintColor;
else
@@ -917,5 +933,12 @@ namespace Xamarin.Forms.Platform.iOS
n.UpdateToolBarVisible();
}
}
+
+ void IEffectControlProvider.RegisterEffect(Effect effect)
+ {
+ var platformEffect = effect as PlatformEffect;
+ if (platformEffect != null)
+ platformEffect.Container = View;
+ }
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs
index 12a131f4..6db3fb61 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs
@@ -1,17 +1,17 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
-using System.Linq;
#if __UNIFIED__
using UIKit;
#else
using MonoTouch.UIKit;
+
#endif
namespace Xamarin.Forms.Platform.iOS
{
- public class PageRenderer : UIViewController, IVisualElementRenderer
+ public class PageRenderer : UIViewController, IVisualElementRenderer, IEffectControlProvider
{
bool _appeared;
bool _disposed;
@@ -25,6 +25,13 @@ namespace Xamarin.Forms.Platform.iOS
WantsFullScreenLayout = true;
}
+ void IEffectControlProvider.RegisterEffect(Effect effect)
+ {
+ var platformEffect = effect as PlatformEffect;
+ if (platformEffect != null)
+ platformEffect.Container = View;
+ }
+
public VisualElement Element { get; private set; }
public event EventHandler<VisualElementChangedEventArgs> ElementChanged;
@@ -41,7 +48,7 @@ namespace Xamarin.Forms.Platform.iOS
public void SetElement(VisualElement element)
{
- var oldElement = Element;
+ VisualElement oldElement = Element;
Element = element;
UpdateTitle();
@@ -52,6 +59,8 @@ namespace Xamarin.Forms.Platform.iOS
if (element != null)
element.SendViewInitialized(NativeView);
+
+ EffectUtilities.RegisterEffectControlProvider(this, oldElement, element);
}
public void SetElementSize(Size size)
@@ -59,10 +68,7 @@ namespace Xamarin.Forms.Platform.iOS
Element.Layout(new Rectangle(Element.X, Element.Y, size.Width, size.Height));
}
- public UIViewController ViewController
- {
- get { return _disposed ? null : this; }
- }
+ public UIViewController ViewController => _disposed ? null : this;
public override void ViewDidAppear(bool animated)
{
@@ -94,7 +100,8 @@ namespace Xamarin.Forms.Platform.iOS
uiTapGestureRecognizer.ShouldRecognizeSimultaneously = (recognizer, gestureRecognizer) => true;
uiTapGestureRecognizer.ShouldReceiveTouch = OnShouldReceiveTouch;
- uiTapGestureRecognizer.DelaysTouchesBegan = uiTapGestureRecognizer.DelaysTouchesEnded = uiTapGestureRecognizer.CancelsTouchesInView = false;
+ uiTapGestureRecognizer.DelaysTouchesBegan =
+ uiTapGestureRecognizer.DelaysTouchesEnded = uiTapGestureRecognizer.CancelsTouchesInView = false;
View.AddGestureRecognizer(uiTapGestureRecognizer);
UpdateBackground();
@@ -115,8 +122,7 @@ namespace Xamarin.Forms.Platform.iOS
{
base.ViewWillDisappear(animated);
- if (View.Window != null)
- View.Window.EndEditing(true);
+ View.Window?.EndEditing(true);
}
protected override void Dispose(bool disposing)
@@ -157,9 +163,7 @@ namespace Xamarin.Forms.Platform.iOS
protected virtual void OnElementChanged(VisualElementChangedEventArgs e)
{
- var changed = ElementChanged;
- if (changed != null)
- changed(this, e);
+ ElementChanged?.Invoke(this, e);
}
protected virtual void SetAutomationId(string id)
@@ -180,20 +184,23 @@ namespace Xamarin.Forms.Platform.iOS
bool OnShouldReceiveTouch(UIGestureRecognizer recognizer, UITouch touch)
{
- if (ViewAndSuperviewsOfView(touch.View).Any(v => v is UITableView || v is UITableViewCell || v.CanBecomeFirstResponder))
- return false;
+ foreach (UIView v in ViewAndSuperviewsOfView(touch.View))
+ {
+ if (v is UITableView || v is UITableViewCell || v.CanBecomeFirstResponder)
+ return false;
+ }
return true;
}
void UpdateBackground()
{
- var bgImage = ((Page)Element).BackgroundImage;
+ string bgImage = ((Page)Element).BackgroundImage;
if (!string.IsNullOrEmpty(bgImage))
{
View.BackgroundColor = UIColor.FromPatternImage(UIImage.FromBundle(bgImage));
return;
}
- var bgColor = Element.BackgroundColor;
+ Color bgColor = Element.BackgroundColor;
if (bgColor.IsDefault)
View.BackgroundColor = UIColor.White;
else
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs
index 070a0389..dcefbcf6 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs
@@ -20,7 +20,7 @@ using nuint=System.UInt32;
namespace Xamarin.Forms.Platform.iOS
{
- public class PhoneMasterDetailRenderer : UIViewController, IVisualElementRenderer
+ public class PhoneMasterDetailRenderer : UIViewController, IVisualElementRenderer, IEffectControlProvider
{
UIView _clickOffView;
UIViewController _detailController;
@@ -91,6 +91,8 @@ namespace Xamarin.Forms.Platform.iOS
OnElementChanged(new VisualElementChangedEventArgs(oldElement, element));
+ EffectUtilities.RegisterEffectControlProvider(this, oldElement, element);
+
if (element != null)
element.SendViewInitialized(NativeView);
}
@@ -397,5 +399,12 @@ namespace Xamarin.Forms.Platform.iOS
vc.View.Frame = View.Bounds;
}
}
+
+ void IEffectControlProvider.RegisterEffect(Effect effect)
+ {
+ var platformEffect = effect as PlatformEffect;
+ if (platformEffect != null)
+ platformEffect.Container = View;
+ }
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs
index 7e5121fd..14bf4a24 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs
@@ -21,7 +21,7 @@ using nuint=System.UInt32;
namespace Xamarin.Forms.Platform.iOS
{
- public class TabbedRenderer : UITabBarController, IVisualElementRenderer
+ public class TabbedRenderer : UITabBarController, IVisualElementRenderer, IEffectControlProvider
{
bool _loaded;
Size _queuedSize;
@@ -73,6 +73,8 @@ namespace Xamarin.Forms.Platform.iOS
//disable edit/reorder of tabs
CustomizableViewControllers = null;
+
+ EffectUtilities.RegisterEffectControlProvider(this, oldElement, element);
}
public void SetElementSize(Size size)
@@ -307,5 +309,12 @@ namespace Xamarin.Forms.Platform.iOS
{
((TabbedPage)Element).CurrentPage = SelectedIndex >= 0 && SelectedIndex < Tabbed.InternalChildren.Count ? Tabbed.GetPageByIndex((int)SelectedIndex) : null;
}
+
+ void IEffectControlProvider.RegisterEffect(Effect effect)
+ {
+ var platformEffect = effect as PlatformEffect;
+ if (platformEffect != null)
+ platformEffect.Container = View;
+ }
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs
index 6bf2aa86..e7c92dfa 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs
@@ -43,7 +43,7 @@ namespace Xamarin.Forms.Platform.iOS
public event EventHandler WillDisappear;
}
- public class TabletMasterDetailRenderer : UISplitViewController, IVisualElementRenderer
+ public class TabletMasterDetailRenderer : UISplitViewController, IVisualElementRenderer, IEffectControlProvider
{
UIViewController _detailController;
@@ -135,6 +135,8 @@ namespace Xamarin.Forms.Platform.iOS
OnElementChanged(new VisualElementChangedEventArgs(oldElement, element));
+ EffectUtilities.RegisterEffectControlProvider(this, oldElement, element);
+
if (element != null)
element.SendViewInitialized(NativeView);
}
@@ -368,5 +370,12 @@ namespace Xamarin.Forms.Platform.iOS
PresentButton = barButtonItem;
}
}
+
+ void IEffectControlProvider.RegisterEffect(Effect effect)
+ {
+ var platformEffect = effect as PlatformEffect;
+ if (platformEffect != null)
+ platformEffect.Container = View;
+ }
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs b/Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs
index d14c288c..68ae10bb 100644
--- a/Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs
@@ -169,13 +169,7 @@ namespace Xamarin.Forms.Platform.iOS
if (element != null)
SendVisualElementInitialized(element, this);
- var controller = (IElementController)oldElement;
- if (controller != null && controller.EffectControlProvider == this)
- controller.EffectControlProvider = null;
-
- controller = element;
- if (controller != null)
- controller.EffectControlProvider = this;
+ EffectUtilities.RegisterEffectControlProvider(this, oldElement, element);
if (Element != null && !string.IsNullOrEmpty(Element.AutomationId))
SetAutomationId(Element.AutomationId);
diff --git a/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.Classic.csproj b/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.Classic.csproj
index d8679944..cc6aa44c 100644
--- a/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.Classic.csproj
+++ b/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.Classic.csproj
@@ -63,6 +63,7 @@
<Compile Include="CADisplayLinkTicker.cs" />
<Compile Include="ContextActionCell.cs" />
<Compile Include="ContextScrollViewDelegate.cs" />
+ <Compile Include="EffectUtilities.cs" />
<Compile Include="Extensions\CellExtensions.cs" />
<Compile Include="Forms.cs" />
<Compile Include="GlobalCloseContextGestureRecognizer.cs" />
diff --git a/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.csproj b/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.csproj
index 5c75adf0..62993b4a 100644
--- a/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.csproj
+++ b/Xamarin.Forms.Platform.iOS/Xamarin.Forms.Platform.iOS.csproj
@@ -125,6 +125,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions\CellExtensions.cs" />
<Compile Include="CADisplayLinkTicker.cs" />
+ <Compile Include="EffectUtilities.cs" />
<Compile Include="ExportCellAttribute.cs" />
<Compile Include="ExportImageSourceHandlerAttribute.cs" />
<Compile Include="ExportRendererAttribute.cs" />