diff options
Diffstat (limited to 'Xamarin.Forms.Platform.iOS')
32 files changed, 186 insertions, 1059 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Cells/CellTableViewCell.cs b/Xamarin.Forms.Platform.iOS/Cells/CellTableViewCell.cs index b42f69f4..e32e86cd 100644 --- a/Xamarin.Forms.Platform.iOS/Cells/CellTableViewCell.cs +++ b/Xamarin.Forms.Platform.iOS/Cells/CellTableViewCell.cs @@ -7,8 +7,8 @@ namespace Xamarin.Forms.Platform.iOS public class CellTableViewCell : UITableViewCell, INativeElementView { Cell _cell; + public Action<object, PropertyChangedEventArgs> PropertyChanged; - bool _disposed; public CellTableViewCell(UITableViewCellStyle style, string key) : base(style, key) { @@ -95,21 +95,5 @@ namespace Xamarin.Forms.Platform.iOS return nativeCell; } - - protected override void Dispose(bool disposing) - { - if (_disposed) - return; - - if (disposing) - { - PropertyChanged = null; - _cell = null; - } - - _disposed = true; - - base.Dispose(disposing); - } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.iOS/Cells/ViewCellRenderer.cs b/Xamarin.Forms.Platform.iOS/Cells/ViewCellRenderer.cs index 30c17234..8f8a92ce 100644 --- a/Xamarin.Forms.Platform.iOS/Cells/ViewCellRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Cells/ViewCellRenderer.cs @@ -48,11 +48,8 @@ namespace Xamarin.Forms.Platform.iOS internal class ViewTableCell : UITableViewCell, INativeElementView { WeakReference<IVisualElementRenderer> _rendererRef; - ViewCell _viewCell; - Element INativeElementView.Element => ViewCell; - internal bool SupressSeparator { get; set; } - bool _disposed; + ViewCell _viewCell; public ViewTableCell(string key) : base(UITableViewCellStyle.Default, key) { @@ -69,6 +66,10 @@ namespace Xamarin.Forms.Platform.iOS } } + Element INativeElementView.Element => ViewCell; + + internal bool SupressSeparator { get; set; } + public override void LayoutSubviews() { //This sets the content views frame. @@ -114,9 +115,6 @@ namespace Xamarin.Forms.Platform.iOS protected override void Dispose(bool disposing) { - if (_disposed) - return; - if (disposing) { IVisualElementRenderer renderer; @@ -128,12 +126,8 @@ namespace Xamarin.Forms.Platform.iOS _rendererRef = null; } - - _viewCell = null; } - _disposed = true; - base.Dispose(disposing); } diff --git a/Xamarin.Forms.Platform.iOS/Deserializer.cs b/Xamarin.Forms.Platform.iOS/Deserializer.cs index dcef049c..86657578 100644 --- a/Xamarin.Forms.Platform.iOS/Deserializer.cs +++ b/Xamarin.Forms.Platform.iOS/Deserializer.cs @@ -6,12 +6,7 @@ using System.Runtime.Serialization; using System.Threading.Tasks; using System.Xml; -#if __MOBILE__ namespace Xamarin.Forms.Platform.iOS -#else - -namespace Xamarin.Forms.Platform.MacOS -#endif { internal class Deserializer : IDeserializer { diff --git a/Xamarin.Forms.Platform.iOS/EffectUtilities.cs b/Xamarin.Forms.Platform.iOS/EffectUtilities.cs index 6b053787..c9523479 100644 --- a/Xamarin.Forms.Platform.iOS/EffectUtilities.cs +++ b/Xamarin.Forms.Platform.iOS/EffectUtilities.cs @@ -1,10 +1,4 @@ - -#if __MOBILE__ namespace Xamarin.Forms.Platform.iOS -#else - -namespace Xamarin.Forms.Platform.MacOS -#endif { internal static class EffectUtilities { diff --git a/Xamarin.Forms.Platform.iOS/ElementChangedEventArgs.cs b/Xamarin.Forms.Platform.iOS/ElementChangedEventArgs.cs index 49cf85d9..560cfd1c 100644 --- a/Xamarin.Forms.Platform.iOS/ElementChangedEventArgs.cs +++ b/Xamarin.Forms.Platform.iOS/ElementChangedEventArgs.cs @@ -1,16 +1,10 @@ using System; -#if __MOBILE__ namespace Xamarin.Forms.Platform.iOS -#else - -namespace Xamarin.Forms.Platform.MacOS -#endif { public class VisualElementChangedEventArgs : ElementChangedEventArgs<VisualElement> { - public VisualElementChangedEventArgs(VisualElement oldElement, VisualElement newElement) - : base(oldElement, newElement) + public VisualElementChangedEventArgs(VisualElement oldElement, VisualElement newElement) : base(oldElement, newElement) { } } diff --git a/Xamarin.Forms.Platform.iOS/EventTracker.cs b/Xamarin.Forms.Platform.iOS/EventTracker.cs index 596506a5..9c6c90e9 100644 --- a/Xamarin.Forms.Platform.iOS/EventTracker.cs +++ b/Xamarin.Forms.Platform.iOS/EventTracker.cs @@ -3,42 +3,27 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Linq; - -#if __MOBILE__ using UIKit; -using NativeView = UIKit.UIView; -using NativeGestureRecognizer = UIKit.UIGestureRecognizer; -using NativeGestureRecognizerState = UIKit.UIGestureRecognizerState; namespace Xamarin.Forms.Platform.iOS -#else -using AppKit; -using NativeView = AppKit.NSView; -using NativeGestureRecognizer = AppKit.NSGestureRecognizer; -using NativeGestureRecognizerState = AppKit.NSGestureRecognizerState; - -namespace Xamarin.Forms.Platform.MacOS -#endif { public class EventTracker : IDisposable { readonly NotifyCollectionChangedEventHandler _collectionChangedHandler; - readonly Dictionary<IGestureRecognizer, NativeGestureRecognizer> _gestureRecognizers = new Dictionary<IGestureRecognizer, NativeGestureRecognizer>(); + readonly Dictionary<IGestureRecognizer, UIGestureRecognizer> _gestureRecognizers = new Dictionary<IGestureRecognizer, UIGestureRecognizer>(); readonly IVisualElementRenderer _renderer; bool _disposed; - NativeView _handler; + UIView _handler; double _previousScale = 1.0; -#if __MOBILE__ UITouchEventArgs _shouldReceive; -#endif public EventTracker(IVisualElementRenderer renderer) { if (renderer == null) - throw new ArgumentNullException(nameof(renderer)); + throw new ArgumentNullException("renderer"); _collectionChangedHandler = ModelGestureRecognizersOnCollectionChanged; @@ -77,18 +62,18 @@ namespace Xamarin.Forms.Platform.MacOS _handler = null; } - public void LoadEvents(NativeView handler) + public void LoadEvents(UIView handler) { if (_disposed) throw new ObjectDisposedException(null); -#if __MOBILE__ + _shouldReceive = (r, t) => t.View is IVisualElementRenderer; -#endif + _handler = handler; OnElementChanged(this, new VisualElementChangedEventArgs(null, _renderer.Element)); } - protected virtual NativeGestureRecognizer GetNativeRecognizer(IGestureRecognizer recognizer) + protected virtual UIGestureRecognizer GetNativeRecognizer(IGestureRecognizer recognizer) { if (recognizer == null) return null; @@ -99,7 +84,7 @@ namespace Xamarin.Forms.Platform.MacOS var tapRecognizer = recognizer as TapGestureRecognizer; if (tapRecognizer != null) { - var returnAction = new Action(() => + var uiRecognizer = CreateTapRecognizer(1, tapRecognizer.NumberOfTapsRequired, r => { var tapGestureRecognizer = weakRecognizer.Target as TapGestureRecognizer; var eventTracker = weakEventTracker.Target as EventTracker; @@ -108,7 +93,6 @@ namespace Xamarin.Forms.Platform.MacOS if (tapGestureRecognizer != null && view != null) tapGestureRecognizer.SendTapped(view); }); - var uiRecognizer = CreateTapRecognizer(tapRecognizer.NumberOfTapsRequired, returnAction); return uiRecognizer; } @@ -126,51 +110,41 @@ namespace Xamarin.Forms.Platform.MacOS { var oldScale = eventTracker._previousScale; var originPoint = r.LocationInView(null); -#if __MOBILE__ originPoint = UIApplication.SharedApplication.KeyWindow.ConvertPointToView(originPoint, eventTracker._renderer.NativeView); -#else - originPoint = NSApplication.SharedApplication.KeyWindow.ContentView.ConvertPointToView(originPoint, eventTracker._renderer.NativeView); -#endif var scaledPoint = new Point(originPoint.X / view.Width, originPoint.Y / view.Height); switch (r.State) { - case NativeGestureRecognizerState.Began: -#if __MOBILE__ + case UIGestureRecognizerState.Began: if (r.NumberOfTouches < 2) return; -#endif pinchGestureRecognizer.SendPinchStarted(view, scaledPoint); startingScale = view.Scale; break; - case NativeGestureRecognizerState.Changed: -#if __MOBILE__ + case UIGestureRecognizerState.Changed: if (r.NumberOfTouches < 2 && pinchGestureRecognizer.IsPinching) { - r.State = NativeGestureRecognizerState.Ended; + r.State = UIGestureRecognizerState.Ended; pinchGestureRecognizer.SendPinchEnded(view); return; } - var scale = r.Scale; -#else - var scale = r.Magnification; -#endif + var delta = 1.0; - var dif = Math.Abs(scale - oldScale) * startingScale; - if (oldScale < scale) + var dif = Math.Abs(r.Scale - oldScale) * startingScale; + if (oldScale < r.Scale) delta = 1 + dif; - if (oldScale > scale) + if (oldScale > r.Scale) delta = 1 - dif; pinchGestureRecognizer.SendPinch(view, delta, scaledPoint); - eventTracker._previousScale = scale; + eventTracker._previousScale = r.Scale; break; - case NativeGestureRecognizerState.Cancelled: - case NativeGestureRecognizerState.Failed: + case UIGestureRecognizerState.Cancelled: + case UIGestureRecognizerState.Failed: if (pinchGestureRecognizer.IsPinching) pinchGestureRecognizer.SendPinchCanceled(view); break; - case NativeGestureRecognizerState.Ended: + case UIGestureRecognizerState.Ended: if (pinchGestureRecognizer.IsPinching) pinchGestureRecognizer.SendPinchEnded(view); eventTracker._previousScale = 1; @@ -194,42 +168,33 @@ namespace Xamarin.Forms.Platform.MacOS { switch (r.State) { - case NativeGestureRecognizerState.Began: -#if __MOBILE__ + case UIGestureRecognizerState.Began: if (r.NumberOfTouches != panRecognizer.TouchPoints) return; -#endif panGestureRecognizer.SendPanStarted(view, Application.Current.PanGestureId); break; - case NativeGestureRecognizerState.Changed: -#if __MOBILE__ + case UIGestureRecognizerState.Changed: if (r.NumberOfTouches != panRecognizer.TouchPoints) { - r.State = NativeGestureRecognizerState.Ended; + r.State = UIGestureRecognizerState.Ended; panGestureRecognizer.SendPanCompleted(view, Application.Current.PanGestureId); Application.Current.PanGestureId++; return; } -#endif var translationInView = r.TranslationInView(_handler); panGestureRecognizer.SendPan(view, translationInView.X, translationInView.Y, Application.Current.PanGestureId); break; - case NativeGestureRecognizerState.Cancelled: - case NativeGestureRecognizerState.Failed: + case UIGestureRecognizerState.Cancelled: + case UIGestureRecognizerState.Failed: panGestureRecognizer.SendPanCanceled(view, Application.Current.PanGestureId); Application.Current.PanGestureId++; break; - case NativeGestureRecognizerState.Ended: -#if __MOBILE__ + case UIGestureRecognizerState.Ended: if (r.NumberOfTouches != panRecognizer.TouchPoints) { panGestureRecognizer.SendPanCompleted(view, Application.Current.PanGestureId); Application.Current.PanGestureId++; } -#else - panGestureRecognizer.SendPanCompleted(view, Application.Current.PanGestureId); - Application.Current.PanGestureId++; -#endif break; } } @@ -239,7 +204,7 @@ namespace Xamarin.Forms.Platform.MacOS return null; } -#if __MOBILE__ + UIPanGestureRecognizer CreatePanRecognizer(int numTouches, Action<UIPanGestureRecognizer> action) { var result = new UIPanGestureRecognizer(action); @@ -253,33 +218,14 @@ namespace Xamarin.Forms.Platform.MacOS return result; } - UITapGestureRecognizer CreateTapRecognizer(int numTaps, Action action, int numFingers = 1) + UITapGestureRecognizer CreateTapRecognizer(int numFingers, int numTaps, Action<UITapGestureRecognizer> action) { var result = new UITapGestureRecognizer(action); result.NumberOfTouchesRequired = (uint)numFingers; result.NumberOfTapsRequired = (uint)numTaps; return result; } -#else - NSPanGestureRecognizer CreatePanRecognizer(int numTouches, Action<NSPanGestureRecognizer> action) - { - var result = new NSPanGestureRecognizer(action); - return result; - } - - NSMagnificationGestureRecognizer CreatePinchRecognizer(Action<NSMagnificationGestureRecognizer> action) - { - var result = new NSMagnificationGestureRecognizer(action); - return result; - } - NSClickGestureRecognizer CreateTapRecognizer(int numTaps, Action action) - { - var result = new NSClickGestureRecognizer(action); - result.NumberOfClicksRequired = numTaps; - return result; - } -#endif void LoadRecognizers() { if (ElementGestureRecognizers == null) @@ -293,9 +239,7 @@ namespace Xamarin.Forms.Platform.MacOS var nativeRecognizer = GetNativeRecognizer(recognizer); if (nativeRecognizer != null) { -#if __MOBILE__ nativeRecognizer.ShouldReceiveTouch = _shouldReceive; -#endif _handler.AddGestureRecognizer(nativeRecognizer); _gestureRecognizers[recognizer] = nativeRecognizer; diff --git a/Xamarin.Forms.Platform.iOS/ExportRendererAttribute.cs b/Xamarin.Forms.Platform.iOS/ExportRendererAttribute.cs index 3b3ef91b..50bba17f 100644 --- a/Xamarin.Forms.Platform.iOS/ExportRendererAttribute.cs +++ b/Xamarin.Forms.Platform.iOS/ExportRendererAttribute.cs @@ -1,37 +1,29 @@ using System; - -#if __MOBILE__ using UIKit; -#endif namespace Xamarin.Forms { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] public sealed class ExportRendererAttribute : HandlerAttribute { -#if __MOBILE__ public ExportRendererAttribute(Type handler, Type target, UIUserInterfaceIdiom idiom) : base(handler, target) { Idiomatic = true; Idiom = idiom; } - internal UIUserInterfaceIdiom Idiom { get; } -#endif public ExportRendererAttribute(Type handler, Type target) : base(handler, target) { Idiomatic = false; } + internal UIUserInterfaceIdiom Idiom { get; } + internal bool Idiomatic { get; } public override bool ShouldRegister() { -#if __MOBILE__ return !Idiomatic || Idiom == UIDevice.CurrentDevice.UserInterfaceIdiom; -#else - return !Idiomatic; -#endif } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs b/Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs index 2b8b9101..bb4342ab 100644 --- a/Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs +++ b/Xamarin.Forms.Platform.iOS/Extensions/ColorExtensions.cs @@ -1,27 +1,16 @@ using System; using CoreGraphics; +using UIKit; using PointF = CoreGraphics.CGPoint; using RectangleF = CoreGraphics.CGRect; using SizeF = CoreGraphics.CGSize; -#if __MOBILE__ -using UIKit; -namespace Xamarin.Forms.Platform.iOS -#else -using AppKit; -using UIColor = AppKit.NSColor; -namespace Xamarin.Forms.Platform.MacOS -#endif +namespace Xamarin.Forms.Platform.iOS { public static class ColorExtensions { -#if __MOBILE__ internal static readonly UIColor Black = UIColor.Black; internal static readonly UIColor SeventyPercentGrey = new UIColor(0.7f, 0.7f, 0.7f, 1); -#else - internal static readonly NSColor Black = NSColor.Black; - internal static readonly NSColor SeventyPercentGrey = NSColor.FromRgba(0.7f, 0.7f, 0.7f, 1); -#endif public static CGColor ToCGColor(this Color color) { @@ -34,15 +23,10 @@ namespace Xamarin.Forms.Platform.MacOS nfloat green; nfloat blue; nfloat alpha; -#if __MOBILE__ color.GetRGBA(out red, out green, out blue, out alpha); -#else - color.GetRgba(out red, out green, out blue, out alpha); -#endif return new Color(red, green, blue, alpha); } -#if __MOBILE__ public static UIColor ToUIColor(this Color color) { return new UIColor((float)color.R, (float)color.G, (float)color.B, (float)color.A); @@ -63,28 +47,6 @@ namespace Xamarin.Forms.Platform.MacOS return color.ToUIColor(); } -#else - public static NSColor ToNSColor(this Color color) - { - return NSColor.FromRgba((float)color.R, (float)color.G, (float)color.B, (float)color.A); - } - - public static NSColor ToNSColor(this Color color, Color defaultColor) - { - if (color.IsDefault) - return defaultColor.ToNSColor(); - - return color.ToNSColor(); - } - - public static NSColor ToNSColor(this Color color, NSColor defaultColor) - { - if (color.IsDefault) - return defaultColor; - - return color.ToNSColor(); - } -#endif } public static class PointExtensions @@ -93,11 +55,6 @@ namespace Xamarin.Forms.Platform.MacOS { return new Point(point.X, point.Y); } - - public static PointF ToPointF(this Point point) - { - return new PointF(point.X, point.Y); - } } public static class SizeExtensions diff --git a/Xamarin.Forms.Platform.iOS/Extensions/DateExtensions.cs b/Xamarin.Forms.Platform.iOS/Extensions/DateExtensions.cs index 73ca347c..bb0dfff9 100644 --- a/Xamarin.Forms.Platform.iOS/Extensions/DateExtensions.cs +++ b/Xamarin.Forms.Platform.iOS/Extensions/DateExtensions.cs @@ -1,12 +1,7 @@ using System; using Foundation; -#if __MOBILE__ namespace Xamarin.Forms.Platform.iOS -#else - -namespace Xamarin.Forms.Platform.MacOS -#endif { public static class DateExtensions { diff --git a/Xamarin.Forms.Platform.iOS/Extensions/LayoutExtensions.cs b/Xamarin.Forms.Platform.iOS/Extensions/LayoutExtensions.cs index d65caf12..823c3f30 100644 --- a/Xamarin.Forms.Platform.iOS/Extensions/LayoutExtensions.cs +++ b/Xamarin.Forms.Platform.iOS/Extensions/LayoutExtensions.cs @@ -1,19 +1,10 @@ using System.Collections.Generic; using CoreGraphics; -#if __MOBILE__ using UIKit; -using Xamarin.Forms.Platform.iOS; -namespace Xamarin.Forms.Platform.iOS -#else -using AppKit; -using UIView = AppKit.NSView; -using Xamarin.Forms.Platform.MacOS; -namespace Xamarin.Forms.Platform.MacOS -#endif +namespace Xamarin.Forms.Platform.iOS { - public delegate SizeRequest? GetDesiredSizeDelegate( - NativeViewWrapperRenderer renderer, double widthConstraint, double heightConstraint); + public delegate SizeRequest? GetDesiredSizeDelegate(NativeViewWrapperRenderer renderer, double widthConstraint, double heightConstraint); public delegate CGSize? SizeThatFitsDelegate(CGSize size); @@ -21,15 +12,13 @@ namespace Xamarin.Forms.Platform.MacOS public static class LayoutExtensions { - public static void Add(this IList<View> children, UIView view, GetDesiredSizeDelegate getDesiredSizeDelegate = null, - SizeThatFitsDelegate sizeThatFitsDelegate = null, - LayoutSubviewsDelegate layoutSubViews = null) + public static void Add(this IList<View> children, UIView view, GetDesiredSizeDelegate getDesiredSizeDelegate = null, SizeThatFitsDelegate sizeThatFitsDelegate = null, + LayoutSubviewsDelegate layoutSubViews = null) { children.Add(view.ToView(getDesiredSizeDelegate, sizeThatFitsDelegate, layoutSubViews)); } - public static View ToView(this UIView view, GetDesiredSizeDelegate getDesiredSizeDelegate = null, - SizeThatFitsDelegate sizeThatFitsDelegate = null, LayoutSubviewsDelegate layoutSubViews = null) + public static View ToView(this UIView view, GetDesiredSizeDelegate getDesiredSizeDelegate = null, SizeThatFitsDelegate sizeThatFitsDelegate = null, LayoutSubviewsDelegate layoutSubViews = null) { return new NativeViewWrapper(view, getDesiredSizeDelegate, sizeThatFitsDelegate, layoutSubViews); } diff --git a/Xamarin.Forms.Platform.iOS/Extensions/PlatformConfigurationExtensions.cs b/Xamarin.Forms.Platform.iOS/Extensions/PlatformConfigurationExtensions.cs index f2932e3a..f61837f2 100644 --- a/Xamarin.Forms.Platform.iOS/Extensions/PlatformConfigurationExtensions.cs +++ b/Xamarin.Forms.Platform.iOS/Extensions/PlatformConfigurationExtensions.cs @@ -1,18 +1,11 @@ -#if __MOBILE__ -using CurrentPlatform = Xamarin.Forms.PlatformConfiguration.iOS; namespace Xamarin.Forms.Platform.iOS -#else -using CurrentPlatform = Xamarin.Forms.PlatformConfiguration.macOS; - -namespace Xamarin.Forms.Platform.MacOS -#endif { public static class PlatformConfigurationExtensions { - public static IPlatformElementConfiguration<CurrentPlatform, T> OnThisPlatform<T>(this T element) + public static IPlatformElementConfiguration<PlatformConfiguration.iOS, T> OnThisPlatform<T>(this T element) where T : Element, IElementConfiguration<T> { - return (element).On<CurrentPlatform>(); + return (element).On<PlatformConfiguration.iOS>(); } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs b/Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs index 8248af11..4c3eed98 100644 --- a/Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs +++ b/Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs @@ -2,15 +2,10 @@ using System; using System.Collections.Generic; using System.Drawing; using System.Linq; -using static System.String; -#if __MOBILE__ using UIKit; -namespace Xamarin.Forms.Platform.iOS -#else -using UIView = AppKit.NSView; +using static System.String; -namespace Xamarin.Forms.Platform.MacOS -#endif +namespace Xamarin.Forms.Platform.iOS { public static class UIViewExtensions { @@ -21,28 +16,15 @@ namespace Xamarin.Forms.Platform.MacOS return self.Subviews.Concat(self.Subviews.SelectMany(s => s.Descendants())); } - public static SizeRequest GetSizeRequest(this UIView self, double widthConstraint, double heightConstraint, - double minimumWidth = -1, double minimumHeight = -1) + public static SizeRequest GetSizeRequest(this UIView self, double widthConstraint, double heightConstraint, double minimumWidth = -1, double minimumHeight = -1) { - CoreGraphics.CGSize s; -#if __MOBILE__ - s = self.SizeThatFits(new SizeF((float)widthConstraint, (float)heightConstraint)); -#else - var control = self as AppKit.NSControl; - if (control != null) - s = control.SizeThatFits(new CoreGraphics.CGSize(widthConstraint, heightConstraint)); - else - s = self.FittingSize; -#endif - var request = new Size(s.Width == float.PositiveInfinity ? double.PositiveInfinity : s.Width, - s.Height == float.PositiveInfinity ? double.PositiveInfinity : s.Height); - var minimum = new Size(minimumWidth < 0 ? request.Width : minimumWidth, - minimumHeight < 0 ? request.Height : minimumHeight); + var s = self.SizeThatFits(new SizeF((float)widthConstraint, (float)heightConstraint)); + var request = new Size(s.Width == float.PositiveInfinity ? double.PositiveInfinity : s.Width, s.Height == float.PositiveInfinity ? double.PositiveInfinity : s.Height); + var minimum = new Size(minimumWidth < 0 ? request.Width : minimumWidth, minimumHeight < 0 ? request.Height : minimumHeight); return new SizeRequest(request, minimum); } - public static void SetBinding(this UIView view, string propertyName, BindingBase bindingBase, - string updateSourceEventName = null) + public static void SetBinding(this UIView view, string propertyName, BindingBase bindingBase, string updateSourceEventName = null) { var binding = bindingBase as Binding; //This will allow setting bindings from Xaml by reusing the MarkupExtension @@ -69,7 +51,6 @@ namespace Xamarin.Forms.Platform.MacOS view.AddObserver(nativePropertyListener, key, Foundation.NSKeyValueObservingOptions.New, IntPtr.Zero); } } -#if __MOBILE__ catch (Foundation.MonoTouchException ex) { nativePropertyListener = null; @@ -80,12 +61,7 @@ namespace Xamarin.Forms.Platform.MacOS } throw ex; } -#else - catch (Exception ex) - { - throw ex; - } -#endif + } NativeBindingHelpers.SetBinding(view, propertyName, bindingBase, nativePropertyListener); @@ -101,8 +77,7 @@ namespace Xamarin.Forms.Platform.MacOS NativeBindingHelpers.SetValue(target, targetProperty, value); } - public static void SetBindingContext(this UIView target, object bindingContext, - Func<UIView, IEnumerable<UIView>> getChildren = null) + public static void SetBindingContext(this UIView target, object bindingContext, Func<UIView, IEnumerable<UIView>> getChildren = null) { NativeBindingHelpers.SetBindingContext(target, bindingContext, getChildren); } @@ -132,7 +107,6 @@ namespace Xamarin.Forms.Platform.MacOS return null; } -#if __MOBILE__ internal static UIView FindFirstResponder(this UIView view) { if (view.IsFirstResponder) @@ -147,6 +121,5 @@ namespace Xamarin.Forms.Platform.MacOS return null; } -#endif } }
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.iOS/Forms.cs b/Xamarin.Forms.Platform.iOS/Forms.cs index d51e1495..2c8fc6f7 100644 --- a/Xamarin.Forms.Platform.iOS/Forms.cs +++ b/Xamarin.Forms.Platform.iOS/Forms.cs @@ -11,18 +11,11 @@ using System.Security.Cryptography; using System.Text; using System.Threading; using System.Threading.Tasks; -using Xamarin.Forms.Internals; +using CoreFoundation; using Foundation; -#if __MOBILE__ using UIKit; +using Xamarin.Forms.Internals; using Xamarin.Forms.Platform.iOS; -using TNativeView = UIKit.UIView; -#else -using AppKit; -using Xamarin.Forms.Platform.MacOS; -using TNativeView = AppKit.NSView; - -#endif namespace Xamarin.Forms { @@ -31,11 +24,7 @@ namespace Xamarin.Forms //Preserve GetCallingAssembly static readonly bool nevertrue = false; - public static bool IsInitialized { get; private set; } - -#if __MOBILE__ static bool? s_isiOS9OrNewer; -#endif static Forms() { @@ -43,7 +32,8 @@ namespace Xamarin.Forms Assembly.GetCallingAssembly(); } -#if __MOBILE__ + public static bool IsInitialized { get; private set; } + internal static bool IsiOS9OrNewer { get @@ -53,7 +43,6 @@ namespace Xamarin.Forms return s_isiOS9OrNewer.Value; } } -#endif public static void Init() { @@ -64,22 +53,19 @@ namespace Xamarin.Forms Log.Listeners.Add(new DelegateLogListener((c, m) => Trace.WriteLine(m, c))); -#if __MOBILE__ - Device.Idiom = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? TargetIdiom.Tablet : TargetIdiom.Phone; -#else - Device.Idiom = TargetIdiom.Desktop; -#endif Device.PlatformServices = new IOSPlatformServices(); Device.Info = new IOSDeviceInfo(); - Registrar.RegisterAll(new[] - { typeof(ExportRendererAttribute), typeof(ExportCellAttribute), typeof(ExportImageSourceHandlerAttribute) }); + Registrar.RegisterAll(new[] { typeof(ExportRendererAttribute), typeof(ExportCellAttribute), typeof(ExportImageSourceHandlerAttribute) }); + + Device.Idiom = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? TargetIdiom.Tablet : TargetIdiom.Phone; + ExpressionSearch.Default = new iOSExpressionSearch(); } public static event EventHandler<ViewInitializedEventArgs> ViewInitialized; - internal static void SendViewInitialized(this VisualElement self, TNativeView nativeView) + internal static void SendViewInitialized(this VisualElement self, UIView nativeView) { ViewInitialized?.Invoke(self, new ViewInitializedEventArgs { View = self, NativeView = nativeView }); } @@ -113,22 +99,16 @@ namespace Xamarin.Forms internal class IOSDeviceInfo : DeviceInfo { -#if __MOBILE__ readonly NSObject _notification; -#endif readonly Size _scaledScreenSize; readonly double _scalingFactor; public IOSDeviceInfo() { -#if __MOBILE__ _notification = UIDevice.Notifications.ObserveOrientationDidChange((sender, args) => CurrentOrientation = UIDevice.CurrentDevice.Orientation.ToDeviceOrientation()); + _scalingFactor = UIScreen.MainScreen.Scale; _scaledScreenSize = new Size(UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height); -#else - _scalingFactor = NSScreen.MainScreen.BackingScaleFactor; - _scaledScreenSize = new Size(NSScreen.MainScreen.Frame.Width, NSScreen.MainScreen.Frame.Height); -#endif PixelScreenSize = new Size(_scaledScreenSize.Width * _scalingFactor, _scaledScreenSize.Height * _scalingFactor); } @@ -140,9 +120,7 @@ namespace Xamarin.Forms protected override void Dispose(bool disposing) { -#if __MOBILE__ _notification.Dispose(); -#endif base.Dispose(disposing); } } @@ -220,20 +198,11 @@ namespace Xamarin.Forms public bool IsInvokeRequired => !NSThread.IsMain; -#if __MOBILE__ public string RuntimePlatform => Device.iOS; -#else - public string RuntimePlatform => Device.macOS; -#endif public void OpenUriAction(Uri uri) { - var url = NSUrl.FromString(uri.ToString()) ?? new NSUrl(uri.Scheme, uri.Host, uri.LocalPath); -#if __MOBILE__ - UIApplication.SharedApplication.OpenUrl(url); -#else - NSWorkspace.SharedWorkspace.OpenUrl(url); -#endif + UIApplication.SharedApplication.OpenUrl(new NSUrl(uri.AbsoluteUri)); } public void StartTimer(TimeSpan interval, Func<bool> callback) @@ -248,11 +217,11 @@ namespace Xamarin.Forms HttpClient GetHttpClient() { - var proxy = CoreFoundation.CFNetwork.GetSystemProxySettings(); + var proxy = CFNetwork.GetSystemProxySettings(); var handler = new HttpClientHandler(); if (!string.IsNullOrEmpty(proxy.HTTPProxy)) { - handler.Proxy = CoreFoundation.CFNetwork.GetDefaultProxy(); + handler.Proxy = CFNetwork.GetDefaultProxy(); handler.UseProxy = true; } return new HttpClient(handler); @@ -303,8 +272,7 @@ namespace Xamarin.Forms public Task<Stream> OpenFileAsync(string path, FileMode mode, FileAccess access, FileShare share) { - Stream stream = _isolatedStorageFile.OpenFile(path, (System.IO.FileMode)mode, (System.IO.FileAccess)access, - (System.IO.FileShare)share); + Stream stream = _isolatedStorageFile.OpenFile(path, (System.IO.FileMode)mode, (System.IO.FileAccess)access, (System.IO.FileShare)share); return Task.FromResult(stream); } } diff --git a/Xamarin.Forms.Platform.iOS/IVisualElementRenderer.cs b/Xamarin.Forms.Platform.iOS/IVisualElementRenderer.cs index ffb2de29..9a2bf580 100644 --- a/Xamarin.Forms.Platform.iOS/IVisualElementRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/IVisualElementRenderer.cs @@ -1,24 +1,15 @@ using System; -#if __MOBILE__ using UIKit; -using NativeView = UIKit.UIView; -using NativeViewController = UIKit.UIViewController; namespace Xamarin.Forms.Platform.iOS -#else -using NativeView = AppKit.NSView; -using NativeViewController = AppKit.NSViewController; - -namespace Xamarin.Forms.Platform.MacOS -#endif { public interface IVisualElementRenderer : IDisposable, IRegisterable { VisualElement Element { get; } - NativeView NativeView { get; } + UIView NativeView { get; } - NativeViewController ViewController { get; } + UIViewController ViewController { get; } event EventHandler<VisualElementChangedEventArgs> ElementChanged; diff --git a/Xamarin.Forms.Platform.iOS/NativeValueConverterService.cs b/Xamarin.Forms.Platform.iOS/NativeValueConverterService.cs index acdd6523..9e20e045 100644 --- a/Xamarin.Forms.Platform.iOS/NativeValueConverterService.cs +++ b/Xamarin.Forms.Platform.iOS/NativeValueConverterService.cs @@ -1,23 +1,16 @@ using System; -#if __MOBILE__ using UIKit; -[assembly: Xamarin.Forms.Dependency(typeof(Xamarin.Forms.Platform.iOS.NativeValueConverterService))] -namespace Xamarin.Forms.Platform.iOS -#else -using UIView = AppKit.NSView; -[assembly: Xamarin.Forms.Dependency(typeof(Xamarin.Forms.Platform.MacOS.NativeValueConverterService))] +[assembly: Xamarin.Forms.Dependency(typeof(Xamarin.Forms.Platform.iOS.NativeValueConverterService))] -namespace Xamarin.Forms.Platform.MacOS -#endif +namespace Xamarin.Forms.Platform.iOS { class NativeValueConverterService : Xaml.INativeValueConverterService { public bool ConvertTo(object value, Type toType, out object nativeValue) { nativeValue = null; - if (typeof(UIView).IsInstanceOfType(value) && toType.IsAssignableFrom(typeof(View))) - { + if (typeof(UIView).IsInstanceOfType(value) && toType.IsAssignableFrom(typeof(View))) { nativeValue = ((UIView)value).ToView(); return true; } diff --git a/Xamarin.Forms.Platform.iOS/NativeViewPropertyListener.cs b/Xamarin.Forms.Platform.iOS/NativeViewPropertyListener.cs index e819519a..4e6601ef 100644 --- a/Xamarin.Forms.Platform.iOS/NativeViewPropertyListener.cs +++ b/Xamarin.Forms.Platform.iOS/NativeViewPropertyListener.cs @@ -2,12 +2,7 @@ using System; using System.ComponentModel; using Foundation; -#if __MOBILE__ namespace Xamarin.Forms.Platform.iOS -#else - -namespace Xamarin.Forms.Platform.MacOS -#endif { class NativeViewPropertyListener : NSObject, INotifyPropertyChanged { @@ -28,4 +23,4 @@ namespace Xamarin.Forms.Platform.MacOS base.ObserveValue(keyPath, ofObject, change, context); } } -}
\ No newline at end of file +} diff --git a/Xamarin.Forms.Platform.iOS/NativeViewWrapper.cs b/Xamarin.Forms.Platform.iOS/NativeViewWrapper.cs index 165bc0f9..31cb186d 100644 --- a/Xamarin.Forms.Platform.iOS/NativeViewWrapper.cs +++ b/Xamarin.Forms.Platform.iOS/NativeViewWrapper.cs @@ -1,16 +1,10 @@ -#if __MOBILE__ -using UIKit; -namespace Xamarin.Forms.Platform.iOS -#else -using UIView = AppKit.NSView; +using UIKit; -namespace Xamarin.Forms.Platform.MacOS -#endif +namespace Xamarin.Forms.Platform.iOS { public class NativeViewWrapper : View { - public NativeViewWrapper(UIView nativeView, GetDesiredSizeDelegate getDesiredSizeDelegate = null, - SizeThatFitsDelegate sizeThatFitsDelegate = null, LayoutSubviewsDelegate layoutSubViews = null) + public NativeViewWrapper(UIView nativeView, GetDesiredSizeDelegate getDesiredSizeDelegate = null, SizeThatFitsDelegate sizeThatFitsDelegate = null, LayoutSubviewsDelegate layoutSubViews = null) { GetDesiredSizeDelegate = getDesiredSizeDelegate; SizeThatFitsDelegate = sizeThatFitsDelegate; diff --git a/Xamarin.Forms.Platform.iOS/NativeViewWrapperRenderer.cs b/Xamarin.Forms.Platform.iOS/NativeViewWrapperRenderer.cs index cde9fe81..4d1252ee 100644 --- a/Xamarin.Forms.Platform.iOS/NativeViewWrapperRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/NativeViewWrapperRenderer.cs @@ -1,13 +1,8 @@ using CoreGraphics; -using Xamarin.Forms.Internals; -#if __MOBILE__ using UIKit; -namespace Xamarin.Forms.Platform.iOS -#else -using UIView = AppKit.NSView; +using Xamarin.Forms.Internals; -namespace Xamarin.Forms.Platform.MacOS -#endif +namespace Xamarin.Forms.Platform.iOS { public class NativeViewWrapperRenderer : ViewRenderer<NativeViewWrapper, UIView> { @@ -24,7 +19,6 @@ namespace Xamarin.Forms.Platform.MacOS return result ?? base.GetDesiredSize(widthConstraint, heightConstraint); } -#if __MOBILE__ public override void LayoutSubviews() { if (Element?.LayoutSubViews == null) @@ -56,26 +50,6 @@ namespace Xamarin.Forms.Platform.MacOS // if it returns null, fall back to the default implementation return result ?? base.SizeThatFits(size); } -#else - public override void Layout() - { - if (Element?.LayoutSubViews == null) - { - ((IVisualElementController)Element)?.InvalidateMeasure(InvalidationTrigger.MeasureChanged); - base.Layout(); - return; - } - - // The user has specified a different implementation of LayoutSubviews - var handled = Element.LayoutSubViews(); - - if (!handled) - { - // If the delegate wasn't able to handle the request, fall back to the default implementation - base.Layout(); - } - } -#endif protected override void OnElementChanged(ElementChangedEventArgs<NativeViewWrapper> e) { diff --git a/Xamarin.Forms.Platform.iOS/PlatformEffect.cs b/Xamarin.Forms.Platform.iOS/PlatformEffect.cs index 6a1ca494..8fb4f975 100644 --- a/Xamarin.Forms.Platform.iOS/PlatformEffect.cs +++ b/Xamarin.Forms.Platform.iOS/PlatformEffect.cs @@ -1,11 +1,6 @@ -#if __MOBILE__ -using UIKit; -namespace Xamarin.Forms.Platform.iOS -#else -using UIView = AppKit.NSView; +using UIKit; -namespace Xamarin.Forms.Platform.MacOS -#endif +namespace Xamarin.Forms.Platform.iOS { public abstract class PlatformEffect : PlatformEffect<UIView, UIView> { diff --git a/Xamarin.Forms.Platform.iOS/RendererPool.cs b/Xamarin.Forms.Platform.iOS/RendererPool.cs index 38fe3c02..babfa7bc 100644 --- a/Xamarin.Forms.Platform.iOS/RendererPool.cs +++ b/Xamarin.Forms.Platform.iOS/RendererPool.cs @@ -1,17 +1,11 @@ using System; using System.Collections.Generic; -#if __MOBILE__ namespace Xamarin.Forms.Platform.iOS -#else - -namespace Xamarin.Forms.Platform.MacOS -#endif { public sealed class RendererPool { - readonly Dictionary<Type, Stack<IVisualElementRenderer>> _freeRenderers = - new Dictionary<Type, Stack<IVisualElementRenderer>>(); + readonly Dictionary<Type, Stack<IVisualElementRenderer>> _freeRenderers = new Dictionary<Type, Stack<IVisualElementRenderer>>(); readonly VisualElement _oldElement; diff --git a/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs index 5eb9b777..68d4702d 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs @@ -38,10 +38,7 @@ namespace Xamarin.Forms.Platform.iOS protected override void Dispose(bool disposing) { if (Control != null) - { Control.TouchUpInside -= OnButtonTouchUpInside; - Control.TouchDown -= OnButtonTouchDown; - } base.Dispose(disposing); } @@ -63,7 +60,6 @@ namespace Xamarin.Forms.Platform.iOS _buttonTextColorDefaultDisabled = Control.TitleColor(UIControlState.Disabled); Control.TouchUpInside += OnButtonTouchUpInside; - Control.TouchDown += OnButtonTouchDown; } UpdateText(); @@ -90,32 +86,11 @@ namespace Xamarin.Forms.Platform.iOS UpdateImage(); } - protected override void SetAccessibilityLabel() - { - // If we have not specified an AccessibilityLabel and the AccessibiltyLabel is current bound to the Title, - // exit this method so we don't set the AccessibilityLabel value and break the binding. - // This may pose a problem for users who want to explicitly set the AccessibilityLabel to null, but this - // will prevent us from inadvertently breaking UI Tests that are using Query.Marked to get the dynamic Title - // of the Button. - - var elemValue = (string)Element?.GetValue(Accessibility.NameProperty); - if (string.IsNullOrWhiteSpace(elemValue) && Control?.AccessibilityLabel == Control?.Title(UIControlState.Normal)) - return; - - base.SetAccessibilityLabel(); - } - void OnButtonTouchUpInside(object sender, EventArgs eventArgs) { - ((IButtonController)Element)?.SendReleased(); ((IButtonController)Element)?.SendClicked(); } - void OnButtonTouchDown(object sender, EventArgs eventArgs) - { - ((IButtonController)Element)?.SendPressed(); - } - void UpdateBorder() { var uiButton = Control; diff --git a/Xamarin.Forms.Platform.iOS/Renderers/FontExtensions.cs b/Xamarin.Forms.Platform.iOS/Renderers/FontExtensions.cs index ba8acbe5..cbc2e625 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/FontExtensions.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/FontExtensions.cs @@ -1,26 +1,15 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using Xamarin.Forms; -#if __MOBILE__ using UIKit; -namespace Xamarin.Forms.Platform.iOS -#else -using AppKit; -using UIFont = AppKit.NSFont; -namespace Xamarin.Forms.Platform.MacOS -#endif +namespace Xamarin.Forms.Platform.iOS { public static class FontExtensions { static readonly Dictionary<ToUIFontKey, UIFont> ToUiFont = new Dictionary<ToUIFontKey, UIFont>(); -#if __MOBILE__ - public static UIFont ToUIFont(this Font self) -#else - public static UIFont ToNSFont(this Font self) -#endif + public static UIFont ToUIFont(this Font self) { var size = (float)self.FontSize; if (self.UseNamedSize) @@ -52,7 +41,6 @@ namespace Xamarin.Forms.Platform.MacOS { try { -#if __MOBILE__ if (UIFont.FamilyNames.Contains(self.FontFamily)) { var descriptor = new UIFontDescriptor().CreateWithFamily(self.FontFamily); @@ -71,25 +59,6 @@ namespace Xamarin.Forms.Platform.MacOS } return UIFont.FromName(self.FontFamily, size); - -#else - - var descriptor = new NSFontDescriptor().FontDescriptorWithFamily(self.FontFamily); - - if (bold || italic) - { - var traits = (NSFontSymbolicTraits)0; - if (bold) - traits = traits | NSFontSymbolicTraits.BoldTrait; - if (italic) - traits = traits | NSFontSymbolicTraits.ItalicTrait; - - descriptor = descriptor.FontDescriptorWithSymbolicTraits(traits); - return NSFont.FromDescription(descriptor, size); - } - - return NSFont.FromFontName(self.FontFamily, size); -#endif } catch { @@ -99,54 +68,28 @@ namespace Xamarin.Forms.Platform.MacOS if (bold && italic) { var defaultFont = UIFont.SystemFontOfSize(size); -#if __MOBILE__ var descriptor = defaultFont.FontDescriptor.CreateWithTraits(UIFontDescriptorSymbolicTraits.Bold | UIFontDescriptorSymbolicTraits.Italic); return UIFont.FromDescriptor(descriptor, 0); } - if (italic) - return UIFont.ItalicSystemFontOfSize(size); -#else - var descriptor = defaultFont.FontDescriptor.FontDescriptorWithSymbolicTraits( - NSFontSymbolicTraits.BoldTrait | - NSFontSymbolicTraits.ItalicTrait); - - return NSFont.FromDescription(descriptor, 0); - } - if (italic) - { - Debug.WriteLine("Italic font requested, passing regular one"); - return NSFont.UserFontOfSize(size); - } -#endif - if (bold) return UIFont.BoldSystemFontOfSize(size); - + if (italic) + return UIFont.ItalicSystemFontOfSize(size); return UIFont.SystemFontOfSize(size); } internal static bool IsDefault(this Span self) { - return self.FontFamily == null && self.FontSize == Device.GetNamedSize(NamedSize.Default, typeof(Label), true) && - self.FontAttributes == FontAttributes.None; + return self.FontFamily == null && self.FontSize == Device.GetNamedSize(NamedSize.Default, typeof(Label), true) && self.FontAttributes == FontAttributes.None; } -#if __MOBILE__ internal static UIFont ToUIFont(this Label label) -#else - internal static UIFont ToNSFont(this Label label) -#endif { var values = label.GetValues(Label.FontFamilyProperty, Label.FontSizeProperty, Label.FontAttributesProperty); - return ToUIFont((string)values[0], (float)(double)values[1], (FontAttributes)values[2]) ?? - UIFont.SystemFontOfSize(UIFont.LabelFontSize); + return ToUIFont((string)values[0], (float)(double)values[1], (FontAttributes)values[2]) ?? UIFont.SystemFontOfSize(UIFont.LabelFontSize); } -#if __MOBILE__ internal static UIFont ToUIFont(this IFontElement element) -#else - internal static NSFont ToNSFont(this IFontElement element) -#endif { return ToUIFont(element.FontFamily, (float)element.FontSize, element.FontAttributes); } @@ -161,7 +104,6 @@ namespace Xamarin.Forms.Platform.MacOS try { UIFont result; -#if __MOBILE__ if (UIFont.FamilyNames.Contains(family)) { var descriptor = new UIFontDescriptor().CreateWithFamily(family); @@ -182,26 +124,6 @@ namespace Xamarin.Forms.Platform.MacOS } result = UIFont.FromName(family, size); -#else - - var descriptor = new NSFontDescriptor().FontDescriptorWithFamily(family); - - if (bold || italic) - { - var traits = (NSFontSymbolicTraits)0; - if (bold) - traits = traits | NSFontSymbolicTraits.BoldTrait; - if (italic) - traits = traits | NSFontSymbolicTraits.ItalicTrait; - - descriptor = descriptor.FontDescriptorWithSymbolicTraits(traits); - result = NSFont.FromDescription(descriptor, size); - if (result != null) - return result; - } - - result = NSFont.FromFontName(family, size); -#endif if (result != null) return result; } @@ -215,27 +137,13 @@ namespace Xamarin.Forms.Platform.MacOS { var defaultFont = UIFont.SystemFontOfSize(size); -#if __MOBILE__ var descriptor = defaultFont.FontDescriptor.CreateWithTraits(UIFontDescriptorSymbolicTraits.Bold | UIFontDescriptorSymbolicTraits.Italic); return UIFont.FromDescriptor(descriptor, 0); } - if (italic) - return UIFont.ItalicSystemFontOfSize(size); -#else - var descriptor = defaultFont.FontDescriptor.FontDescriptorWithSymbolicTraits( - NSFontSymbolicTraits.BoldTrait | - NSFontSymbolicTraits.ItalicTrait); - - return NSFont.FromDescription(descriptor, 0); - } - if (italic) - { - Debug.WriteLine("Italic font requested, passing regular one"); - return NSFont.UserFontOfSize(size); - } -#endif if (bold) return UIFont.BoldSystemFontOfSize(size); + if (italic) + return UIFont.ItalicSystemFontOfSize(size); return UIFont.SystemFontOfSize(size); } diff --git a/Xamarin.Forms.Platform.iOS/Renderers/FormattedStringExtensions.cs b/Xamarin.Forms.Platform.iOS/Renderers/FormattedStringExtensions.cs index 825a20bd..dce86b98 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/FormattedStringExtensions.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/FormattedStringExtensions.cs @@ -1,13 +1,7 @@ using Foundation; -#if __MOBILE__ using UIKit; -namespace Xamarin.Forms.Platform.iOS -#else -using AppKit; -using UIColor = AppKit.NSColor; -namespace Xamarin.Forms.Platform.MacOS -#endif +namespace Xamarin.Forms.Platform.iOS { public static class FormattedStringExtensions { @@ -25,16 +19,10 @@ namespace Xamarin.Forms.Platform.MacOS if (fgcolor.IsDefault) fgcolor = Color.Black; // as defined by apple docs -#if __MOBILE__ return new NSAttributedString(span.Text, font == Font.Default ? null : font.ToUIFont(), fgcolor.ToUIColor(), span.BackgroundColor.ToUIColor()); -#else - return new NSAttributedString(span.Text, font == Font.Default ? null : font.ToNSFont(), fgcolor.ToNSColor(), - span.BackgroundColor.ToNSColor()); -#endif } - public static NSAttributedString ToAttributed(this FormattedString formattedString, Font defaultFont, - Color defaultForegroundColor) + public static NSAttributedString ToAttributed(this FormattedString formattedString, Font defaultFont, Color defaultForegroundColor) { if (formattedString == null) return null; @@ -55,7 +43,6 @@ namespace Xamarin.Forms.Platform.MacOS if (span == null) return null; -#if __MOBILE__ UIFont targetFont; if (span.IsDefault()) targetFont = ((IFontElement)owner).ToUIFont(); @@ -69,25 +56,9 @@ namespace Xamarin.Forms.Platform.MacOS fgcolor = Color.Black; // as defined by apple docs return new NSAttributedString(span.Text, targetFont, fgcolor.ToUIColor(), span.BackgroundColor.ToUIColor()); -#else - NSFont targetFont; - if (span.IsDefault()) - targetFont = ((IFontElement)owner).ToNSFont(); - else - targetFont = span.ToNSFont(); - - var fgcolor = span.ForegroundColor; - if (fgcolor.IsDefault) - fgcolor = defaultForegroundColor; - if (fgcolor.IsDefault) - fgcolor = Color.Black; // as defined by apple docs - - return new NSAttributedString(span.Text, targetFont, fgcolor.ToNSColor(), span.BackgroundColor.ToNSColor()); -#endif } - internal static NSAttributedString ToAttributed(this FormattedString formattedString, Element owner, - Color defaultForegroundColor) + internal static NSAttributedString ToAttributed(this FormattedString formattedString, Element owner, Color defaultForegroundColor) { if (formattedString == null) return null; diff --git a/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs index 82ceda81..e4967c15 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs @@ -1,21 +1,12 @@ using System; using System.ComponentModel; +using UIKit; using RectangleF = CoreGraphics.CGRect; using SizeF = CoreGraphics.CGSize; -#if __MOBILE__ -using UIKit; -using NativeLabel = UIKit.UILabel; - namespace Xamarin.Forms.Platform.iOS -#else -using AppKit; -using NativeLabel = AppKit.NSTextField; - -namespace Xamarin.Forms.Platform.MacOS -#endif { - public class LabelRenderer : ViewRenderer<Label, NativeLabel> + public class LabelRenderer : ViewRenderer<Label, UILabel> { SizeRequest _perfectSize; @@ -60,16 +51,9 @@ namespace Xamarin.Forms.Platform.MacOS return result; } -#if __MOBILE__ public override void LayoutSubviews() { base.LayoutSubviews(); -#else - public override void Layout() - { - base.Layout(); -#endif - if (Control == null) return; @@ -101,12 +85,7 @@ namespace Xamarin.Forms.Platform.MacOS { if (Control == null) { - SetNativeControl(new NativeLabel(RectangleF.Empty)); -#if !__MOBILE__ - Control.Editable = false; - Control.Bezeled = false; - Control.DrawsBackground = false; -#endif + SetNativeControl(new UILabel(RectangleF.Empty) { BackgroundColor = UIColor.Clear }); } UpdateText(); @@ -124,7 +103,7 @@ namespace Xamarin.Forms.Platform.MacOS if (e.PropertyName == Label.HorizontalTextAlignmentProperty.PropertyName) UpdateAlignment(); else if (e.PropertyName == Label.VerticalTextAlignmentProperty.PropertyName) - UpdateLayout(); + LayoutSubviews(); else if (e.PropertyName == Label.TextColorProperty.PropertyName) UpdateText(); else if (e.PropertyName == Label.FontProperty.PropertyName) @@ -137,52 +116,23 @@ namespace Xamarin.Forms.Platform.MacOS UpdateLineBreakMode(); } -#if __MOBILE__ - protected override void SetAccessibilityLabel() - { - // If we have not specified an AccessibilityLabel and the AccessibiltyLabel is current bound to the Text, - // exit this method so we don't set the AccessibilityLabel value and break the binding. - // This may pose a problem for users who want to explicitly set the AccessibilityLabel to null, but this - // will prevent us from inadvertently breaking UI Tests that are using Query.Marked to get the dynamic Text - // of the Label. - - var elemValue = (string)Element?.GetValue(Accessibility.NameProperty); - if (string.IsNullOrWhiteSpace(elemValue) && Control?.AccessibilityLabel == Control?.Text) - return; - - base.SetAccessibilityLabel(); - } -#endif - protected override void SetBackgroundColor(Color color) { -#if __MOBILE__ if (color == Color.Default) BackgroundColor = UIColor.Clear; else BackgroundColor = color.ToUIColor(); -#else - if (color == Color.Default) - Layer.BackgroundColor = NSColor.Clear.CGColor; - else - Layer.BackgroundColor = color.ToCGColor(); -#endif - } void UpdateAlignment() { -#if __MOBILE__ Control.TextAlignment = Element.HorizontalTextAlignment.ToNativeTextAlignment(); -#else - Control.Alignment = Element.HorizontalTextAlignment.ToNativeTextAlignment(); -#endif } void UpdateLineBreakMode() { _perfectSizeValid = false; -#if __MOBILE__ + switch (Element.LineBreakMode) { case LineBreakMode.NoWrap: @@ -210,35 +160,6 @@ namespace Xamarin.Forms.Platform.MacOS Control.Lines = 1; break; } -#else - switch (Element.LineBreakMode) - { - case LineBreakMode.NoWrap: - Control.LineBreakMode = NSLineBreakMode.Clipping; - Control.MaximumNumberOfLines = 1; - break; - case LineBreakMode.WordWrap: - Control.LineBreakMode = NSLineBreakMode.ByWordWrapping; - Control.MaximumNumberOfLines = 0; - break; - case LineBreakMode.CharacterWrap: - Control.LineBreakMode = NSLineBreakMode.CharWrapping; - Control.MaximumNumberOfLines = 0; - break; - case LineBreakMode.HeadTruncation: - Control.LineBreakMode = NSLineBreakMode.TruncatingHead; - Control.MaximumNumberOfLines = 1; - break; - case LineBreakMode.MiddleTruncation: - Control.LineBreakMode = NSLineBreakMode.TruncatingMiddle; - Control.MaximumNumberOfLines = 1; - break; - case LineBreakMode.TailTruncation: - Control.LineBreakMode = NSLineBreakMode.TruncatingTail; - Control.MaximumNumberOfLines = 1; - break; - } -#endif } void UpdateText() @@ -246,12 +167,9 @@ namespace Xamarin.Forms.Platform.MacOS _perfectSizeValid = false; var values = Element.GetValues(Label.FormattedTextProperty, Label.TextProperty, Label.TextColorProperty); - var formatted = values[0] as FormattedString; + var formatted = (FormattedString)values[0]; if (formatted != null) - { -#if __MOBILE__ Control.AttributedText = formatted.ToAttributed(Element, (Color)values[2]); - } else { Control.Text = (string)values[1]; @@ -259,28 +177,8 @@ namespace Xamarin.Forms.Platform.MacOS Control.Font = Element.ToUIFont(); Control.TextColor = ((Color)values[2]).ToUIColor(ColorExtensions.Black); } -#else - Control.AttributedStringValue = formatted.ToAttributed(Element, (Color)values[2]); - } - else - { - Control.StringValue = (string)values[1] ?? ""; - // default value of color documented to be black in iOS docs - Control.Font = Element.ToNSFont(); - Control.TextColor = ((Color)values[2]).ToNSColor(ColorExtensions.Black); - } -#endif - UpdateLayout(); - } - - void UpdateLayout() - { -#if __MOBILE__ LayoutSubviews(); -#else - Layout(); -#endif } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs index fd0f15f6..3871c5cf 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs @@ -29,7 +29,6 @@ namespace Xamarin.Forms.Platform.iOS IListViewController Controller => Element; ITemplatedItemsView<Cell> TemplatedItemsView => Element; public override UIViewController ViewController => _tableViewController; - bool _disposed; public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint) { @@ -91,31 +90,28 @@ namespace Xamarin.Forms.Platform.iOS } } - void DisposeSubviews(UIView view) - { - foreach (UIView subView in view.Subviews) - DisposeSubviews(subView); - - view.RemoveFromSuperview(); - view.Dispose(); - } - protected override void Dispose(bool disposing) { - if (_disposed) - return; - - if (disposing) + // check inset tracker for null to + if (disposing && _insetTracker != null) { - if (_insetTracker != null) + _insetTracker.Dispose(); + _insetTracker = null; + + var viewsToLookAt = new Stack<UIView>(Subviews); + while (viewsToLookAt.Count > 0) { - _insetTracker.Dispose(); - _insetTracker = null; + var view = viewsToLookAt.Pop(); + var viewCellRenderer = view as ViewCellRenderer.ViewTableCell; + if (viewCellRenderer != null) + viewCellRenderer.Dispose(); + else + { + foreach (var child in view.Subviews) + viewsToLookAt.Push(child); + } } - foreach (UIView subview in Subviews) - DisposeSubviews(subview); - if (Element != null) { var templatedItems = TemplatedItemsView.TemplatedItems; @@ -123,28 +119,27 @@ namespace Xamarin.Forms.Platform.iOS templatedItems.GroupedCollectionChanged -= OnGroupedCollectionChanged; } - if (_dataSource != null) - { - _dataSource.Dispose(); - _dataSource = null; - } - if (_tableViewController != null) { _tableViewController.Dispose(); _tableViewController = null; } + } + if (disposing) + { if (_headerRenderer != null) { - var platform = _headerRenderer.Element?.Platform as Platform; - platform?.DisposeModelAndChildrenRenderers(_headerRenderer.Element); + var platform = _headerRenderer.Element.Platform as Platform; + if (platform != null) + platform.DisposeModelAndChildrenRenderers(_headerRenderer.Element); _headerRenderer = null; } if (_footerRenderer != null) { - var platform = _footerRenderer.Element?.Platform as Platform; - platform?.DisposeModelAndChildrenRenderers(_footerRenderer.Element); + var platform = _footerRenderer.Element.Platform as Platform; + if (platform != null) + platform.DisposeModelAndChildrenRenderers(_footerRenderer.Element); _footerRenderer = null; } @@ -159,8 +154,6 @@ namespace Xamarin.Forms.Platform.iOS Control?.TableFooterView?.Dispose(); } - _disposed = true; - base.Dispose(disposing); } @@ -421,8 +414,6 @@ namespace Xamarin.Forms.Platform.iOS else if (_footerRenderer != null) { Control.TableFooterView = null; - _footerRenderer.Element.MeasureInvalidated -= OnFooterMeasureInvalidated; - var platform = _footerRenderer.Element.Platform as Platform; if (platform != null) platform.DisposeModelAndChildrenRenderers(_footerRenderer.Element); @@ -467,8 +458,6 @@ namespace Xamarin.Forms.Platform.iOS else if (_headerRenderer != null) { Control.TableHeaderView = null; - _headerRenderer.Element.MeasureInvalidated -= OnHeaderMeasureInvalidated; - var platform = _headerRenderer.Element.Platform as Platform; if (platform != null) platform.DisposeModelAndChildrenRenderers(_headerRenderer.Element); @@ -609,7 +598,6 @@ namespace Xamarin.Forms.Platform.iOS internal class UnevenListViewDataSource : ListViewDataSource { IVisualElementRenderer _prototype; - bool _disposed; public UnevenListViewDataSource(ListView list, FormsUITableViewController uiTableViewController) : base(list, uiTableViewController) { @@ -669,47 +657,27 @@ namespace Xamarin.Forms.Platform.iOS { var target = viewCell.View; if (_prototype == null) + { _prototype = Platform.CreateRenderer(target); + Platform.SetRenderer(target, _prototype); + } else + { _prototype.SetElement(target); - - Platform.SetRenderer(target, _prototype); + Platform.SetRenderer(target, _prototype); + } var req = target.Measure(tableView.Frame.Width, double.PositiveInfinity, MeasureFlags.IncludeMargins); target.ClearValue(Platform.RendererProperty); - foreach (Element descendant in target.Descendants()) - { - IVisualElementRenderer renderer = Platform.GetRenderer(descendant as VisualElement); + foreach (var descendant in target.Descendants()) descendant.ClearValue(Platform.RendererProperty); - renderer?.Dispose(); - } return (nfloat)req.Request.Height; } - var renderHeight = cell.RenderHeight; return renderHeight > 0 ? (nfloat)renderHeight : DefaultRowHeight; } - - protected override void Dispose(bool disposing) - { - if (_disposed) - return; - - _disposed = true; - - if (disposing) - { - if (_prototype != null) - { - _prototype.Dispose(); - _prototype = null; - } - } - - base.Dispose(disposing); - } } internal class ListViewDataSource : UITableViewSource @@ -717,15 +685,14 @@ namespace Xamarin.Forms.Platform.iOS const int DefaultItemTemplateId = 1; static int s_dataTemplateIncrementer = 2; // lets start at not 0 because readonly nfloat _defaultSectionHeight; - Dictionary<DataTemplate, int> _templateToId = new Dictionary<DataTemplate, int>(); - UITableView _uiTableView; - FormsUITableViewController _uiTableViewController; - protected ListView List; + readonly Dictionary<DataTemplate, int> _templateToId = new Dictionary<DataTemplate, int>(); + readonly UITableView _uiTableView; + readonly FormsUITableViewController _uiTableViewController; + protected readonly ListView List; IListViewController Controller => List; protected ITemplatedItemsView<Cell> TemplatedItemsView => List; bool _isDragging; bool _selectionFromNative; - bool _disposed; public ListViewDataSource(ListViewDataSource source) { @@ -1045,29 +1012,6 @@ namespace Xamarin.Forms.Platform.iOS ((INotifyCollectionChanged)templatedList.ShortNames).CollectionChanged -= OnShortNamesCollectionChanged; } } - - protected override void Dispose(bool disposing) - { - if (_disposed) - return; - - if (disposing) - { - if (List != null) - { - List.ItemSelected -= OnItemSelected; - List = null; - } - - _templateToId = null; - _uiTableView = null; - _uiTableViewController = null; - } - - _disposed = true; - - base.Dispose(disposing); - } } } @@ -1083,12 +1027,11 @@ namespace Xamarin.Forms.Platform.iOS internal class FormsUITableViewController : UITableViewController { - ListView _list; + readonly ListView _list; IListViewController Controller => _list; UIRefreshControl _refresh; bool _refreshAdded; - bool _disposed; public FormsUITableViewController(ListView element) { @@ -1170,25 +1113,15 @@ namespace Xamarin.Forms.Platform.iOS protected override void Dispose(bool disposing) { - if (_disposed) - return; + base.Dispose(disposing); - if (disposing) + if (disposing && _refresh != null) { - if (_refresh != null) - { - _refresh.ValueChanged -= OnRefreshingChanged; - _refresh.EndRefreshing(); - _refresh.Dispose(); - _refresh = null; - } - - _list = null; + _refresh.ValueChanged -= OnRefreshingChanged; + _refresh.EndRefreshing(); + _refresh.Dispose(); + _refresh = null; } - - _disposed = true; - - base.Dispose(disposing); } void CheckContentSize() diff --git a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs index 1465b8dc..6b698f22 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs @@ -211,7 +211,7 @@ namespace Xamarin.Forms.Platform.iOS UpdateBarTextColor(); // If there is already stuff on the stack we need to push it - ((INavigationPageController)navPage).Pages.ForEach(async p => await PushPageAsync(p, false)); + ((INavigationPageController)navPage).StackCopy.Reverse().ForEach(async p => await PushPageAsync(p, false)); _tracker = new VisualElementTracker(this); @@ -617,7 +617,7 @@ namespace Xamarin.Forms.Platform.iOS if (containerController == null) return; var currentChild = containerController.Child; - var firstPage = ((INavigationPageController)Element).Pages.FirstOrDefault(); + var firstPage = ((INavigationPageController)Element).StackCopy.LastOrDefault(); if ((firstPage != pageBeingRemoved && currentChild != firstPage && NavigationPage.GetHasBackButton(currentChild)) || _parentMasterDetailPage == null) return; diff --git a/Xamarin.Forms.Platform.iOS/ResourcesProvider.cs b/Xamarin.Forms.Platform.iOS/ResourcesProvider.cs index f02655a0..3e5655c9 100644 --- a/Xamarin.Forms.Platform.iOS/ResourcesProvider.cs +++ b/Xamarin.Forms.Platform.iOS/ResourcesProvider.cs @@ -1,11 +1,6 @@ -#if __MOBILE__ using UIKit; namespace Xamarin.Forms.Platform.iOS -#else - -namespace Xamarin.Forms.Platform.MacOS -#endif { internal class ResourcesProvider : ISystemResourcesProvider { @@ -13,9 +8,7 @@ namespace Xamarin.Forms.Platform.MacOS public ResourcesProvider() { -#if __MOBILE__ UIApplication.Notifications.ObserveContentSizeCategoryChanged((sender, args) => UpdateStyles()); -#endif } public IResourceDictionary GetSystemResources() @@ -26,7 +19,6 @@ namespace Xamarin.Forms.Platform.MacOS return _dictionary; } -#if __MOBILE__ Style GenerateListItemDetailTextStyle() { var font = new UITableViewCell(UITableViewCellStyle.Subtitle, "Foobar").DetailTextLabel.Font; @@ -52,7 +44,7 @@ namespace Xamarin.Forms.Platform.MacOS void UpdateStyles() { - + _dictionary[Device.Styles.TitleStyleKey] = GenerateStyle(UIFont.PreferredHeadline); _dictionary[Device.Styles.SubtitleStyleKey] = GenerateStyle(UIFont.PreferredSubheadline); _dictionary[Device.Styles.BodyStyleKey] = GenerateStyle(UIFont.PreferredBody); @@ -61,11 +53,5 @@ namespace Xamarin.Forms.Platform.MacOS _dictionary[Device.Styles.ListItemTextStyleKey] = GenerateListItemTextStyle(); _dictionary[Device.Styles.ListItemDetailTextStyleKey] = GenerateListItemDetailTextStyle(); } -#else - void UpdateStyles() - { - } -#endif - } }
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.iOS/ViewInitializedEventArgs.cs b/Xamarin.Forms.Platform.iOS/ViewInitializedEventArgs.cs index 9ee0da88..73041163 100644 --- a/Xamarin.Forms.Platform.iOS/ViewInitializedEventArgs.cs +++ b/Xamarin.Forms.Platform.iOS/ViewInitializedEventArgs.cs @@ -1,16 +1,11 @@ using System; -#if __MOBILE__ -using TNativeView = UIKit.UIView; -#else -using TNativeView = AppKit.NSView; - -#endif +using UIKit; namespace Xamarin.Forms { public class ViewInitializedEventArgs : EventArgs { - public TNativeView NativeView { get; internal set; } + public UIView NativeView { get; internal set; } public VisualElement View { get; internal set; } } diff --git a/Xamarin.Forms.Platform.iOS/ViewRenderer.cs b/Xamarin.Forms.Platform.iOS/ViewRenderer.cs index 2cf9f754..6ecc307b 100644 --- a/Xamarin.Forms.Platform.iOS/ViewRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/ViewRenderer.cs @@ -1,39 +1,21 @@ using System; using System.ComponentModel; - +using UIKit; using RectangleF = CoreGraphics.CGRect; using SizeF = CoreGraphics.CGSize; -#if __MOBILE__ -using UIKit; -using NativeView = UIKit.UIView; -using NativeColor = UIKit.UIColor; -using NativeControl = UIKit.UIControl; - namespace Xamarin.Forms.Platform.iOS -#else -using NativeView = AppKit.NSView; -using NativeColor = CoreGraphics.CGColor; -using NativeControl = AppKit.NSControl; - -namespace Xamarin.Forms.Platform.MacOS -#endif { - public abstract class ViewRenderer : ViewRenderer<View, NativeView> + public abstract class ViewRenderer : ViewRenderer<View, UIView> { } - public abstract class ViewRenderer<TView, TNativeView> : VisualElementRenderer<TView> where TView : View where TNativeView : NativeView + public abstract class ViewRenderer<TView, TNativeView> : VisualElementRenderer<TView> where TView : View where TNativeView : UIView { -#if __MOBILE__ - string _defaultAccessibilityLabel; - string _defaultAccessibilityHint; - bool? _defaultIsAccessibilityElement; -#endif - NativeColor _defaultColor; + UIColor _defaultColor; public TNativeView Control { get; private set; } -#if __MOBILE__ + public override void LayoutSubviews() { base.LayoutSubviews(); @@ -48,19 +30,6 @@ namespace Xamarin.Forms.Platform.MacOS return Control.SizeThatFits(size); } -#else - public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint) - { - return (Control ?? NativeView).GetSizeRequest(widthConstraint, heightConstraint); - } - - public override void Layout() - { - if (Control != null) - Control.Frame = new RectangleF(0, 0, (nfloat)Element.Width, (nfloat)Element.Height); - base.Layout(); - } -#endif /// <summary> /// Determines whether the native control is disposed of when this renderer is disposed @@ -115,59 +84,7 @@ namespace Xamarin.Forms.Platform.MacOS base.OnRegisterEffect(effect); effect.Control = Control; } -#if __MOBILE__ - protected override void SetAccessibilityHint() - { - if (Control == null) - { - base.SetAccessibilityHint(); - return; - } - - if (Element == null) - return; - - if (_defaultAccessibilityHint == null) - _defaultAccessibilityHint = Control.AccessibilityHint; - - Control.AccessibilityHint = (string)Element.GetValue(Accessibility.HintProperty) ?? _defaultAccessibilityHint; - - } - - protected override void SetAccessibilityLabel() - { - if (Control == null) - { - base.SetAccessibilityLabel(); - return; - } - - if (Element == null) - return; - - if (_defaultAccessibilityLabel == null) - _defaultAccessibilityLabel = Control.AccessibilityLabel; - - Control.AccessibilityLabel = (string)Element.GetValue(Accessibility.NameProperty) ?? _defaultAccessibilityLabel; - } - protected override void SetIsAccessibilityElement() - { - if (Control == null) - { - base.SetIsAccessibilityElement(); - return; - } - - if (Element == null) - return; - - if (!_defaultIsAccessibilityElement.HasValue) - _defaultIsAccessibilityElement = Control.IsAccessibilityElement; - - Control.IsAccessibilityElement = (bool)((bool?)Element.GetValue(Accessibility.IsInAccessibleTreeProperty) ?? _defaultIsAccessibilityElement); - } -#endif protected override void SetAutomationId(string id) { if (Control == null) @@ -183,24 +100,16 @@ namespace Xamarin.Forms.Platform.MacOS { if (Control == null) return; -#if __MOBILE__ + if (color == Color.Default) Control.BackgroundColor = _defaultColor; else Control.BackgroundColor = color.ToUIColor(); -#else - Control.Layer.BackgroundColor = color == Color.Default ? _defaultColor : color.ToCGColor(); -#endif } protected void SetNativeControl(TNativeView uiview) { -#if __MOBILE__ _defaultColor = uiview.BackgroundColor; -#else - uiview.WantsLayer = true; - _defaultColor = uiview.Layer.BackgroundColor; -#endif Control = uiview; if (Element.BackgroundColor != Color.Default) @@ -211,19 +120,17 @@ namespace Xamarin.Forms.Platform.MacOS AddSubview(uiview); } -#if __MOBILE__ - internal override void SendVisualElementInitialized(VisualElement element, NativeView nativeView) + internal override void SendVisualElementInitialized(VisualElement element, UIView nativeView) { base.SendVisualElementInitialized(element, Control); } -#endif void UpdateIsEnabled() { if (Element == null || Control == null) return; - var uiControl = Control as NativeControl; + var uiControl = Control as UIControl; if (uiControl == null) return; uiControl.Enabled = Element.IsEnabled; diff --git a/Xamarin.Forms.Platform.iOS/VisualElementPackager.cs b/Xamarin.Forms.Platform.iOS/VisualElementPackager.cs index fa91cf6a..1670176d 100644 --- a/Xamarin.Forms.Platform.iOS/VisualElementPackager.cs +++ b/Xamarin.Forms.Platform.iOS/VisualElementPackager.cs @@ -1,11 +1,6 @@ using System; -#if __MOBILE__ namespace Xamarin.Forms.Platform.iOS -#else - -namespace Xamarin.Forms.Platform.MacOS -#endif { public class VisualElementPackager : IDisposable { @@ -18,7 +13,7 @@ namespace Xamarin.Forms.Platform.MacOS public VisualElementPackager(IVisualElementRenderer renderer) { if (renderer == null) - throw new ArgumentNullException(nameof(renderer)); + throw new ArgumentNullException("renderer"); Renderer = renderer; renderer.ElementChanged += OnRendererElementChanged; @@ -105,9 +100,8 @@ namespace Xamarin.Forms.Platform.MacOS continue; var nativeControl = childRenderer.NativeView; -#if __MOBILE__ + Renderer.NativeView.BringSubviewToFront(nativeControl); -#endif nativeControl.Layer.ZPosition = z * 1000; } } diff --git a/Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs b/Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs index 57c9ab12..155f8b60 100644 --- a/Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs @@ -1,25 +1,13 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using UIKit; +using Xamarin.Forms.PlatformConfiguration.iOSSpecific; using RectangleF = CoreGraphics.CGRect; using SizeF = CoreGraphics.CGSize; -#if __MOBILE__ -using Xamarin.Forms.PlatformConfiguration.iOSSpecific; -using UIKit; -using NativeView = UIKit.UIView; -using NativeViewController = UIKit.UIViewController; -using NativeColor = UIKit.UIColor; namespace Xamarin.Forms.Platform.iOS -#else -using AppKit; -using NativeView = AppKit.NSView; -using NativeViewController = AppKit.NSViewController; -using NativeColor = AppKit.NSColor; - -namespace Xamarin.Forms.Platform.MacOS -#endif { [Flags] public enum VisualElementRendererFlags @@ -29,18 +17,13 @@ namespace Xamarin.Forms.Platform.MacOS AutoPackage = 1 << 2 } - public class VisualElementRenderer<TElement> : NativeView, IVisualElementRenderer, IEffectControlProvider where TElement : VisualElement + public class VisualElementRenderer<TElement> : UIView, IVisualElementRenderer, IEffectControlProvider where TElement : VisualElement { - readonly NativeColor _defaultColor = NativeColor.Clear; + readonly UIColor _defaultColor = UIColor.Clear; readonly List<EventHandler<VisualElementChangedEventArgs>> _elementChangedHandlers = new List<EventHandler<VisualElementChangedEventArgs>>(); readonly PropertyChangedEventHandler _propertyChangedHandler; -#if __MOBILE__ - string _defaultAccessibilityLabel; - string _defaultAccessibilityHint; - bool? _defaultIsAccessibilityElement; -#endif EventTracker _events; VisualElementRendererFlags _flags = VisualElementRendererFlags.AutoPackage | VisualElementRendererFlags.AutoTrack; @@ -48,30 +31,21 @@ namespace Xamarin.Forms.Platform.MacOS VisualElementPackager _packager; VisualElementTracker _tracker; -#if __MOBILE__ UIVisualEffectView _blur; BlurEffectStyle _previousBlur; -#endif protected VisualElementRenderer() : base(RectangleF.Empty) { _propertyChangedHandler = OnElementPropertyChanged; -#if __MOBILE__ - BackgroundColor = _defaultColor; -#else - WantsLayer = true; - Layer.BackgroundColor = _defaultColor.CGColor; -#endif + BackgroundColor = UIColor.Clear; } -#if __MOBILE__ // prevent possible crashes in overrides - public sealed override NativeColor BackgroundColor + public sealed override UIColor BackgroundColor { get { return base.BackgroundColor; } set { base.BackgroundColor = value; } } -#endif public TElement Element { get; private set; } @@ -99,7 +73,7 @@ namespace Xamarin.Forms.Platform.MacOS } } - public static void RegisterEffect(Effect effect, NativeView container, NativeView control = null) + public static void RegisterEffect(Effect effect, UIView container, UIView control = null) { var platformEffect = effect as PlatformEffect; if (platformEffect == null) @@ -132,7 +106,10 @@ namespace Xamarin.Forms.Platform.MacOS return NativeView.GetSizeRequest(widthConstraint, heightConstraint); } - public NativeView NativeView => this; + public UIView NativeView + { + get { return this; } + } void IVisualElementRenderer.SetElement(VisualElement element) { @@ -141,10 +118,13 @@ namespace Xamarin.Forms.Platform.MacOS public void SetElementSize(Size size) { - Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion(Element, new Rectangle(Element.X, Element.Y, size.Width, size.Height)); + Layout.LayoutChildIntoBoundingRegion(Element, new Rectangle(Element.X, Element.Y, size.Width, size.Height)); } - public virtual NativeViewController ViewController => null; + public virtual UIViewController ViewController + { + get { return null; } + } public event EventHandler<ElementChangedEventArgs<TElement>> ElementChanged; @@ -182,7 +162,6 @@ namespace Xamarin.Forms.Platform.MacOS } element.PropertyChanged += _propertyChangedHandler; - } OnElementChanged(new ElementChangedEventArgs<TElement>(oldElement, element)); @@ -194,14 +173,8 @@ namespace Xamarin.Forms.Platform.MacOS if (Element != null && !string.IsNullOrEmpty(Element.AutomationId)) SetAutomationId(Element.AutomationId); -#if __MOBILE__ - SetAccessibilityLabel(); - SetAccessibilityHint(); - SetIsAccessibilityElement(); -#endif } -#if __MOBILE__ public override SizeF SizeThatFits(SizeF size) { return new SizeF(0, 0); @@ -217,16 +190,6 @@ namespace Xamarin.Forms.Platform.MacOS Superview.Add(_blur); } } -#else - public override void MouseDown(NSEvent theEvent) - { - bool inViewCell = IsOnViewCell(Element); - - if (Element.InputTransparent || inViewCell) - base.MouseDown(theEvent); - } -#endif - protected override void Dispose(bool disposing) { if ((_flags & VisualElementRendererFlags.Disposed) != 0) @@ -264,29 +227,22 @@ namespace Xamarin.Forms.Platform.MacOS for (var i = 0; i < _elementChangedHandlers.Count; i++) _elementChangedHandlers[i](this, args); - ElementChanged?.Invoke(this, e); -#if __MOBILE__ + var changed = ElementChanged; + if (changed != null) + changed(this, e); + if (e.NewElement != null) SetBlur((BlurEffectStyle)e.NewElement.GetValue(PlatformConfiguration.iOSSpecific.VisualElement.BlurEffectProperty)); -#endif } protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName) SetBackgroundColor(Element.BackgroundColor); - else if (e.PropertyName == Xamarin.Forms.Layout.IsClippedToBoundsProperty.PropertyName) + else if (e.PropertyName == Layout.IsClippedToBoundsProperty.PropertyName) UpdateClipToBounds(); -#if __MOBILE__ else if (e.PropertyName == PlatformConfiguration.iOSSpecific.VisualElement.BlurEffectProperty.PropertyName) SetBlur((BlurEffectStyle)Element.GetValue(PlatformConfiguration.iOSSpecific.VisualElement.BlurEffectProperty)); - else if (e.PropertyName == Accessibility.HintProperty.PropertyName) - SetAccessibilityHint(); - else if (e.PropertyName == Accessibility.NameProperty.PropertyName) - SetAccessibilityLabel(); - else if (e.PropertyName == Accessibility.IsInAccessibleTreeProperty.PropertyName) - SetIsAccessibilityElement(); -#endif } protected virtual void OnRegisterEffect(PlatformEffect effect) @@ -294,40 +250,6 @@ namespace Xamarin.Forms.Platform.MacOS effect.Container = this; } -#if __MOBILE__ - protected virtual void SetAccessibilityHint() - { - if (Element == null) - return; - - if (_defaultAccessibilityHint == null) - _defaultAccessibilityHint = AccessibilityHint; - - AccessibilityHint = (string)Element.GetValue(Accessibility.HintProperty) ?? _defaultAccessibilityHint; - } - - protected virtual void SetAccessibilityLabel() - { - if (Element == null) - return; - - if (_defaultAccessibilityLabel == null) - _defaultAccessibilityLabel = AccessibilityLabel; - - AccessibilityLabel = (string)Element.GetValue(Accessibility.NameProperty) ?? _defaultAccessibilityLabel; - } - - protected virtual void SetIsAccessibilityElement() - { - if (Element == null) - return; - - if (!_defaultIsAccessibilityElement.HasValue) - _defaultIsAccessibilityElement = IsAccessibilityElement; - - IsAccessibilityElement = (bool)((bool?)Element.GetValue(Accessibility.IsInAccessibleTreeProperty) ?? _defaultIsAccessibilityElement); - } -#endif protected virtual void SetAutomationId(string id) { AccessibilityIdentifier = id; @@ -336,20 +258,11 @@ namespace Xamarin.Forms.Platform.MacOS protected virtual void SetBackgroundColor(Color color) { if (color == Color.Default) -#if __MOBILE__ - BackgroundColor = _defaultColor; else BackgroundColor = color.ToUIColor(); - -#else - Layer.BackgroundColor = _defaultColor.CGColor; - else - Layer.BackgroundColor = color.ToCGColor(); -#endif } -#if __MOBILE__ protected virtual void SetBlur(BlurEffectStyle blur) { if (_previousBlur == blur) @@ -387,35 +300,21 @@ namespace Xamarin.Forms.Platform.MacOS _blur = new UIVisualEffectView(blurEffect); LayoutSubviews(); } -#endif protected virtual void UpdateNativeWidget() { } - internal virtual void SendVisualElementInitialized(VisualElement element, NativeView nativeView) + internal virtual void SendVisualElementInitialized(VisualElement element, UIView nativeView) { element.SendViewInitialized(nativeView); } void UpdateClipToBounds() { -#if __MOBILE__ var clippableLayout = Element as Layout; if (clippableLayout != null) ClipsToBounds = clippableLayout.IsClippedToBounds; -#endif - } - - static bool IsOnViewCell(Element element) - { - - if (element.Parent == null) - return false; - else if (element.Parent is ViewCell) - return true; - else - return IsOnViewCell(element.Parent); } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.iOS/VisualElementTracker.cs b/Xamarin.Forms.Platform.iOS/VisualElementTracker.cs index 29840e2d..5b41ca84 100644 --- a/Xamarin.Forms.Platform.iOS/VisualElementTracker.cs +++ b/Xamarin.Forms.Platform.iOS/VisualElementTracker.cs @@ -3,13 +3,8 @@ using System.ComponentModel; using System.Drawing; using System.Threading; using CoreAnimation; -#if __MOBILE__ namespace Xamarin.Forms.Platform.iOS -#else - -namespace Xamarin.Forms.Platform.MacOS -#endif { public class VisualElementTracker : IDisposable { @@ -23,9 +18,7 @@ namespace Xamarin.Forms.Platform.MacOS // Track these by hand because the calls down into iOS are too expensive bool _isInteractive; Rectangle _lastBounds; -#if !__MOBILE__ - Rectangle _lastParentBounds; -#endif + CALayer _layer; int _updateCount; @@ -114,17 +107,12 @@ namespace Xamarin.Forms.Platform.MacOS var shouldInteract = !view.InputTransparent && view.IsEnabled; if (_isInteractive != shouldInteract) { -#if __MOBILE__ uiview.UserInteractionEnabled = shouldInteract; -#endif _isInteractive = shouldInteract; } var boundsChanged = _lastBounds != view.Bounds; -#if !__MOBILE__ - var viewParent = view.RealParent as VisualElement; - var parentBoundsChanged = _lastParentBounds != (viewParent == null ? Rectangle.Zero : viewParent.Bounds); -#endif + var thread = !boundsChanged && !caLayer.Frame.IsEmpty; var anchorX = (float)view.AnchorX; @@ -148,17 +136,13 @@ namespace Xamarin.Forms.Platform.MacOS { if (updateTarget != _updateCount) return; -#if __MOBILE__ + var visualElement = view; -#endif var parent = view.RealParent; var shouldRelayoutSublayers = false; if (isVisible && caLayer.Hidden) { -#if !__MOBILE__ - uiview.Hidden = false; -#endif caLayer.Hidden = false; if (!caLayer.Frame.IsEmpty) shouldRelayoutSublayers = true; @@ -166,9 +150,6 @@ namespace Xamarin.Forms.Platform.MacOS if (!isVisible && !caLayer.Hidden) { -#if !__MOBILE__ - uiview.Hidden = true; -#endif caLayer.Hidden = true; shouldRelayoutSublayers = true; } @@ -176,26 +157,11 @@ namespace Xamarin.Forms.Platform.MacOS // ripe for optimization var transform = CATransform3D.Identity; -#if __MOBILE__ - bool shouldUpdate = (!(visualElement is Page) || visualElement is ContentPage) && width > 0 && height > 0 && parent != null && boundsChanged; -#else - // We don't care if it's a page or not since bounds of the window can change - // TODO: Find why it doesn't work to check if the parentsBounds changed and remove true; - parentBoundsChanged = true; - bool shouldUpdate = width > 0 && height > 0 && parent != null && (boundsChanged || parentBoundsChanged); -#endif // Dont ever attempt to actually change the layout of a Page unless it is a ContentPage // iOS is a really big fan of you not actually modifying the View's of the UIViewControllers - if (shouldUpdate) + if ((!(visualElement is Page) || visualElement is ContentPage) && width > 0 && height > 0 && parent != null && boundsChanged) { -#if __MOBILE__ var target = new RectangleF(x, y, width, height); -#else - var visualParent = parent as VisualElement; - float newY = visualParent == null ? y : Math.Max(0, (float)(visualParent.Height - y - view.Height)); - var target = new RectangleF(x, newY, width, height); -#endif - // must reset transform prior to setting frame... caLayer.Transform = transform; uiview.Frame = target; @@ -204,17 +170,11 @@ namespace Xamarin.Forms.Platform.MacOS } else if (width <= 0 || height <= 0) { - //TODO: FInd why it doesn't work -#if __MOBILE__ caLayer.Hidden = true; -#endif return; } -#if __MOBILE__ + caLayer.AnchorPoint = new PointF(anchorX, anchorY); -#else - caLayer.AnchorPoint = new PointF(anchorX - 0.5f, anchorY - 0.5f); -#endif caLayer.Opacity = opacity; const double epsilon = 0.001; @@ -249,9 +209,6 @@ namespace Xamarin.Forms.Platform.MacOS update(); _lastBounds = view.Bounds; -#if !__MOBILE__ - _lastParentBounds = viewParent?.Bounds ?? Rectangle.Zero; -#endif } void SetElement(VisualElement oldElement, VisualElement newElement) @@ -282,18 +239,14 @@ namespace Xamarin.Forms.Platform.MacOS if (_layer == null) { -#if !__MOBILE__ - Renderer.NativeView.WantsLayer = true; -#endif _layer = Renderer.NativeView.Layer; -#if __MOBILE__ _isInteractive = Renderer.NativeView.UserInteractionEnabled; -#endif } OnUpdateNativeControl(_layer); - NativeControlUpdated?.Invoke(this, EventArgs.Empty); + if (NativeControlUpdated != null) + NativeControlUpdated(this, EventArgs.Empty); } } }
\ No newline at end of file |