Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Deprecate versions of iOS older than 8 (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Smith authored and rmarinho committed Dec 14, 2016
1 parent eca25db commit 9535315
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 247 deletions.
10 changes: 2 additions & 8 deletions Xamarin.Forms.Platform.iOS/ContextActionCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ public void Update(UITableView tableView, Cell cell, UITableViewCell nativeCell)
_scroller = new UIScrollView(new RectangleF(0, 0, width, height));
_scroller.ScrollsToTop = false;
_scroller.ShowsHorizontalScrollIndicator = false;

if (Forms.IsiOS8OrNewer)
_scroller.PreservesSuperviewLayoutMargins = true;

_scroller.PreservesSuperviewLayoutMargins = true;

ContentView.AddSubview(_scroller);
}
Expand Down Expand Up @@ -299,11 +298,6 @@ void ActivateMore()
}

var frame = _moreButton.Frame;
if (!Forms.IsiOS8OrNewer)
{
var container = _moreButton.Superview;
frame = new RectangleF(container.Frame.X, 0, frame.Width, frame.Height);
}

var x = frame.X - _scroller.ContentOffset.X;

Expand Down
24 changes: 0 additions & 24 deletions Xamarin.Forms.Platform.iOS/Forms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ public static class Forms
//Preserve GetCallingAssembly
static readonly bool nevertrue = false;

static bool? s_isiOS7OrNewer;

static bool? s_isiOS8OrNewer;

static bool? s_isiOS9OrNewer;

static Forms()
Expand All @@ -38,26 +34,6 @@ static Forms()

public static bool IsInitialized { get; private set; }

internal static bool IsiOS7OrNewer
{
get
{
if (!s_isiOS7OrNewer.HasValue)
s_isiOS7OrNewer = UIDevice.CurrentDevice.CheckSystemVersion(7, 0);
return s_isiOS7OrNewer.Value;
}
}

internal static bool IsiOS8OrNewer
{
get
{
if (!s_isiOS8OrNewer.HasValue)
s_isiOS8OrNewer = UIDevice.CurrentDevice.CheckSystemVersion(8, 0);
return s_isiOS8OrNewer.Value;
}
}

internal static bool IsiOS9OrNewer
{
get
Expand Down
49 changes: 2 additions & 47 deletions Xamarin.Forms.Platform.iOS/Platform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,7 @@ internal Platform()
{
if (!PageIsChildOfPlatform(sender))
return;
if (Forms.IsiOS8OrNewer)
{
PresentAlert(arguments);
}
else
{
PresentPre8Alert(arguments);
}
PresentAlert(arguments);
});

MessagingCenter.Subscribe(this, Page.ActionSheetSignalName, (Page sender, ActionSheetArguments arguments) =>
Expand All @@ -64,16 +56,8 @@ internal Platform()
var pageRoot = sender;
while (!Application.IsApplicationOrNull(pageRoot.RealParent))
pageRoot = (Page)pageRoot.RealParent;
var pageRenderer = GetRenderer(pageRoot);
if (Forms.IsiOS8OrNewer)
{
PresentActionSheet(arguments);
}
else
{
PresentPre8ActionSheet(arguments, pageRenderer);
}
PresentActionSheet(arguments);
});
}

Expand Down Expand Up @@ -491,35 +475,6 @@ async Task PresentModal(Page modal, bool animated)
await Task.Delay(5);
}

void PresentPre8Alert(AlertArguments arguments)
{
UIAlertView alertView;
if (arguments.Accept != null)
alertView = new UIAlertView(arguments.Title, arguments.Message, null, arguments.Cancel, arguments.Accept);
else
alertView = new UIAlertView(arguments.Title, arguments.Message, null, arguments.Cancel);

alertView.Dismissed += (o, args) => arguments.SetResult(args.ButtonIndex != 0);
alertView.Show();
}

void PresentPre8ActionSheet(ActionSheetArguments arguments, IVisualElementRenderer pageRenderer)
{
var actionSheet = new UIActionSheet(arguments.Title, null, arguments.Cancel, arguments.Destruction,
arguments.Buttons.ToArray());

actionSheet.ShowInView(pageRenderer.NativeView);

actionSheet.Clicked += (o, args) =>
{
string title = null;
if (args.ButtonIndex != -1)
title = actionSheet.ButtonTitle(args.ButtonIndex);
arguments.Result.TrySetResult(title);
};
}

internal class DefaultRenderer : VisualElementRenderer<VisualElement>
{
}
Expand Down
26 changes: 3 additions & 23 deletions Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
UpdateFont();
else if (e.PropertyName == Button.BorderWidthProperty.PropertyName || e.PropertyName == Button.BorderRadiusProperty.PropertyName || e.PropertyName == Button.BorderColorProperty.PropertyName)
UpdateBorder();
else if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName)
UpdateBackgroundVisibility();
else if (e.PropertyName == Button.ImageProperty.PropertyName)
UpdateImage();
}
Expand All @@ -93,18 +91,6 @@ void OnButtonTouchUpInside(object sender, EventArgs eventArgs)
((IButtonController)Element)?.SendClicked();
}

void UpdateBackgroundVisibility()
{
if (Forms.IsiOS7OrNewer)
return;

var model = Element;
var shouldDrawImage = model.BackgroundColor == Color.Default;

foreach (var control in Control.Subviews.Where(sv => !(sv is UILabel)))
control.Alpha = shouldDrawImage ? 1.0f : 0.0f;
}

void UpdateBorder()
{
var uiButton = Control;
Expand All @@ -115,8 +101,6 @@ void UpdateBorder()

uiButton.Layer.BorderWidth = Math.Max(0f, (float)button.BorderWidth);
uiButton.Layer.CornerRadius = button.BorderRadius;

UpdateBackgroundVisibility();
}

void UpdateFont()
Expand All @@ -142,10 +126,7 @@ async void UpdateImage()
UIButton button = Control;
if (button != null && uiimage != null)
{
if (Forms.IsiOS7OrNewer)
button.SetImage(uiimage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal);
else
button.SetImage(uiimage, UIControlState.Normal);
button.SetImage(uiimage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal);

button.ImageView.ContentMode = UIViewContentMode.ScaleAspectFit;

Expand Down Expand Up @@ -184,9 +165,8 @@ void UpdateTextColor()
Control.SetTitleColor(Element.TextColor.ToUIColor(), UIControlState.Normal);
Control.SetTitleColor(Element.TextColor.ToUIColor(), UIControlState.Highlighted);
Control.SetTitleColor(_buttonTextColorDefaultDisabled, UIControlState.Disabled);

if (Forms.IsiOS7OrNewer)
Control.TintColor = Element.TextColor.ToUIColor();

Control.TintColor = Element.TextColor.ToUIColor();
}
}

Expand Down
2 changes: 0 additions & 2 deletions Xamarin.Forms.Platform.iOS/Renderers/CarouselPageRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public class CarouselPageRenderer : UIViewController, IVisualElementRenderer

public CarouselPageRenderer()
{
if (!Forms.IsiOS7OrNewer)
WantsFullScreenLayout = true;
}

IElementController ElementController => Element as IElementController;
Expand Down
10 changes: 0 additions & 10 deletions Xamarin.Forms.Platform.iOS/Renderers/EditorRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ public class EditorRenderer : ViewRenderer<Editor, UITextView>

IElementController ElementController => Element as IElementController;

public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
{
if (!Forms.IsiOS7OrNewer)
{
// Avoid crash iOS 6. iOS 6, I hate you. Why you no like Infinite size?
return base.GetDesiredSize(Math.Min(widthConstraint, 2000), Math.Min(heightConstraint, 2000));
}
return base.GetDesiredSize(widthConstraint, heightConstraint);
}

protected override void Dispose(bool disposing)
{
if (disposing)
Expand Down
16 changes: 2 additions & 14 deletions Xamarin.Forms.Platform.iOS/Renderers/FontExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static UIFont ToUIFont(this Font self)
{
try
{
if (UIFont.FamilyNames.Contains(self.FontFamily) && Forms.IsiOS7OrNewer)
if (UIFont.FamilyNames.Contains(self.FontFamily))
{
var descriptor = new UIFontDescriptor().CreateWithFamily(self.FontFamily);

Expand All @@ -67,12 +67,6 @@ public static UIFont ToUIFont(this Font self)
}
if (bold && italic)
{
if (!Forms.IsiOS7OrNewer)
{
// not sure how to make a font both bold and italic in iOS 6, default to bold
return UIFont.BoldSystemFontOfSize(size);
}

var defaultFont = UIFont.SystemFontOfSize(size);
var descriptor = defaultFont.FontDescriptor.CreateWithTraits(UIFontDescriptorSymbolicTraits.Bold | UIFontDescriptorSymbolicTraits.Italic);
return UIFont.FromDescriptor(descriptor, 0);
Expand Down Expand Up @@ -110,7 +104,7 @@ static UIFont _ToUIFont(string family, float size, FontAttributes attributes)
try
{
UIFont result;
if (UIFont.FamilyNames.Contains(family) && Forms.IsiOS7OrNewer)
if (UIFont.FamilyNames.Contains(family))
{
var descriptor = new UIFontDescriptor().CreateWithFamily(family);

Expand Down Expand Up @@ -143,12 +137,6 @@ static UIFont _ToUIFont(string family, float size, FontAttributes attributes)
{
var defaultFont = UIFont.SystemFontOfSize(size);

if (!Forms.IsiOS7OrNewer)
{
// not sure how to make a font both bold and italic in iOS 6, default to bold
return UIFont.BoldSystemFontOfSize(size);
}

var descriptor = defaultFont.FontDescriptor.CreateWithTraits(UIFontDescriptorSymbolicTraits.Bold | UIFontDescriptorSymbolicTraits.Italic);
return UIFont.FromDescriptor(descriptor, 0);
}
Expand Down
10 changes: 3 additions & 7 deletions Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,7 @@ void UpdateEstimatedRowHeight()
}
else
{
if (Forms.IsiOS7OrNewer)
Control.EstimatedRowHeight = 0;
Control.EstimatedRowHeight = 0;
_estimatedRowHeight = true;
}
}
Expand Down Expand Up @@ -644,10 +643,7 @@ public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexP

if (List.RowHeight == -1 && cell.Height == -1 && cell is ViewCell)
{
// only doing ViewCell because its the only one that matters (the others dont adjust ANYWAY)
if (Forms.IsiOS8OrNewer)
return UITableView.AutomaticDimension;
return CalculateHeightForCell(tableView, cell);
return UITableView.AutomaticDimension;
}

var renderHeight = cell.RenderHeight;
Expand Down Expand Up @@ -713,7 +709,7 @@ public ListViewDataSource(ListView list, FormsUITableViewController uiTableViewC
{
_uiTableViewController = uiTableViewController;
_uiTableView = uiTableViewController.TableView;
_defaultSectionHeight = Forms.IsiOS8OrNewer ? DefaultRowHeight : _uiTableView.SectionHeaderHeight;
_defaultSectionHeight = DefaultRowHeight;
List = list;
List.ItemSelected += OnItemSelected;
UpdateShortNameListener();
Expand Down
57 changes: 14 additions & 43 deletions Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,7 @@ public override void ViewDidLoad()
{
base.ViewDidLoad();

if (Forms.IsiOS7OrNewer)
{

UpdateTranslucent();
}
else
WantsFullScreenLayout = false;
UpdateTranslucent();

_secondaryToolbar = new SecondaryToolbar { Frame = new RectangleF(0, 0, 320, 44) };
View.Add(_secondaryToolbar);
Expand Down Expand Up @@ -454,11 +448,6 @@ void UpdateCurrentPagePreferredStatusBarUpdateAnimation()

void UpdateTranslucent()
{
if (!Forms.IsiOS7OrNewer)
{
return;
}

NavigationBar.Translucent = ((NavigationPage)Element).OnThisPlatform().IsNavigationBarTranslucent();
}

Expand Down Expand Up @@ -571,18 +560,9 @@ void UpdateBarBackgroundColor()
{
var barBackgroundColor = ((NavigationPage)Element).BarBackgroundColor;
// Set navigation bar background color
if (Forms.IsiOS7OrNewer)
{
NavigationBar.BarTintColor = barBackgroundColor == Color.Default
? UINavigationBar.Appearance.BarTintColor
: barBackgroundColor.ToUIColor();
}
else
{
NavigationBar.TintColor = barBackgroundColor == Color.Default
? UINavigationBar.Appearance.TintColor
: barBackgroundColor.ToUIColor();
}
NavigationBar.BarTintColor = barBackgroundColor == Color.Default
? UINavigationBar.Appearance.BarTintColor
: barBackgroundColor.ToUIColor();
}

void UpdateBarTextColor()
Expand Down Expand Up @@ -616,12 +596,9 @@ void UpdateBarTextColor()
var statusBarColorMode = (Element as NavigationPage).OnThisPlatform().GetStatusBarTextColorMode();

// set Tint color (i. e. Back Button arrow and Text)
if (Forms.IsiOS7OrNewer)
{
NavigationBar.TintColor = barTextColor == Color.Default || statusBarColorMode == StatusBarTextColorMode.DoNotAdjust
? UINavigationBar.Appearance.TintColor
: barTextColor.ToUIColor();
}
NavigationBar.TintColor = barTextColor == Color.Default || statusBarColorMode == StatusBarTextColorMode.DoNotAdjust
? UINavigationBar.Appearance.TintColor
: barTextColor.ToUIColor();

if (statusBarColorMode == StatusBarTextColorMode.DoNotAdjust || barTextColor.Luminosity <= 0.5)
{
Expand Down Expand Up @@ -679,18 +656,13 @@ void UpdateTint()
#pragma warning disable 0618 //retaining legacy call to obsolete code
var tintColor = ((NavigationPage)Element).Tint;
#pragma warning restore 0618
if (Forms.IsiOS7OrNewer)
{
NavigationBar.BarTintColor = tintColor == Color.Default
? UINavigationBar.Appearance.BarTintColor
: tintColor.ToUIColor();
if (tintColor == Color.Default)
NavigationBar.TintColor = UINavigationBar.Appearance.TintColor;
else
NavigationBar.TintColor = tintColor.Luminosity > 0.5 ? UIColor.Black : UIColor.White;
}
NavigationBar.BarTintColor = tintColor == Color.Default
? UINavigationBar.Appearance.BarTintColor
: tintColor.ToUIColor();
if (tintColor == Color.Default)
NavigationBar.TintColor = UINavigationBar.Appearance.TintColor;
else
NavigationBar.TintColor = tintColor == Color.Default ? null : tintColor.ToUIColor();
NavigationBar.TintColor = tintColor.Luminosity > 0.5 ? UIColor.Black : UIColor.White;
}

void UpdateToolBarVisible()
Expand Down Expand Up @@ -776,8 +748,7 @@ class ParentingViewController : UIViewController

public ParentingViewController(NavigationRenderer navigation)
{
if (Forms.IsiOS7OrNewer)
AutomaticallyAdjustsScrollViewInsets = false;
AutomaticallyAdjustsScrollViewInsets = false;

_navigation = new WeakReference<NavigationRenderer>(navigation);
}
Expand Down
Loading

0 comments on commit 9535315

Please sign in to comment.