diff options
author | Jason Smith <jason.smith@xamarin.com> | 2016-12-09 10:17:27 -0800 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-12-09 10:17:27 -0800 |
commit | 899e2bd591bf33cf99c1db95666f1313ff80565b (patch) | |
tree | 5f8712401e45895c8aaf79ce8674f76c7f387967 /Xamarin.Forms.Platform.iOS/Renderers | |
parent | c4b1c88f506ebf76a2a40f005b45ec9b24e46e1a (diff) | |
download | xamarin-forms-899e2bd591bf33cf99c1db95666f1313ff80565b.tar.gz xamarin-forms-899e2bd591bf33cf99c1db95666f1313ff80565b.tar.bz2 xamarin-forms-899e2bd591bf33cf99c1db95666f1313ff80565b.zip |
Revert "Deprecate iOS 8 and earlier (#626)"
This reverts commit c4b1c88f506ebf76a2a40f005b45ec9b24e46e1a.
Diffstat (limited to 'Xamarin.Forms.Platform.iOS/Renderers')
13 files changed, 161 insertions, 40 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs index 9942623f..8d043bac 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs @@ -82,6 +82,8 @@ namespace Xamarin.Forms.Platform.iOS 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(); } @@ -91,6 +93,18 @@ namespace Xamarin.Forms.Platform.iOS ((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; @@ -101,6 +115,8 @@ namespace Xamarin.Forms.Platform.iOS uiButton.Layer.BorderWidth = Math.Max(0f, (float)button.BorderWidth); uiButton.Layer.CornerRadius = button.BorderRadius; + + UpdateBackgroundVisibility(); } void UpdateFont() @@ -126,7 +142,10 @@ namespace Xamarin.Forms.Platform.iOS UIButton button = Control; if (button != null && uiimage != null) { - button.SetImage(uiimage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal); + if (Forms.IsiOS7OrNewer) + button.SetImage(uiimage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal); + else + button.SetImage(uiimage, UIControlState.Normal); button.ImageView.ContentMode = UIViewContentMode.ScaleAspectFit; @@ -165,7 +184,9 @@ namespace Xamarin.Forms.Platform.iOS Control.SetTitleColor(Element.TextColor.ToUIColor(), UIControlState.Normal); Control.SetTitleColor(Element.TextColor.ToUIColor(), UIControlState.Highlighted); Control.SetTitleColor(_buttonTextColorDefaultDisabled, UIControlState.Disabled); - Control.TintColor = Element.TextColor.ToUIColor(); + + if (Forms.IsiOS7OrNewer) + Control.TintColor = Element.TextColor.ToUIColor(); } } diff --git a/Xamarin.Forms.Platform.iOS/Renderers/CarouselPageRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/CarouselPageRenderer.cs index f1364de7..58587e83 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/CarouselPageRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/CarouselPageRenderer.cs @@ -22,6 +22,8 @@ namespace Xamarin.Forms.Platform.iOS public CarouselPageRenderer() { + if (!Forms.IsiOS7OrNewer) + WantsFullScreenLayout = true; } IElementController ElementController => Element as IElementController; diff --git a/Xamarin.Forms.Platform.iOS/Renderers/EditorRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/EditorRenderer.cs index 96e8933b..8819ba33 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/EditorRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/EditorRenderer.cs @@ -13,7 +13,12 @@ namespace Xamarin.Forms.Platform.iOS public override SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint) { - return base.GetDesiredSize(Math.Min(widthConstraint, 2000), Math.Min(heightConstraint, 2000)); + 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) diff --git a/Xamarin.Forms.Platform.iOS/Renderers/FontExtensions.cs b/Xamarin.Forms.Platform.iOS/Renderers/FontExtensions.cs index 6a6eb636..ae16c662 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/FontExtensions.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/FontExtensions.cs @@ -41,7 +41,7 @@ namespace Xamarin.Forms.Platform.iOS { try { - if (UIFont.FamilyNames.Contains(self.FontFamily)) + if (UIFont.FamilyNames.Contains(self.FontFamily) && Forms.IsiOS7OrNewer) { var descriptor = new UIFontDescriptor().CreateWithFamily(self.FontFamily); @@ -67,6 +67,12 @@ namespace Xamarin.Forms.Platform.iOS } 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); @@ -104,7 +110,7 @@ namespace Xamarin.Forms.Platform.iOS try { UIFont result; - if (UIFont.FamilyNames.Contains(family)) + if (UIFont.FamilyNames.Contains(family) && Forms.IsiOS7OrNewer) { var descriptor = new UIFontDescriptor().CreateWithFamily(family); @@ -136,6 +142,13 @@ namespace Xamarin.Forms.Platform.iOS if (bold && italic) { 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); } diff --git a/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs index db57570d..39136327 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/ListViewRenderer.cs @@ -184,7 +184,8 @@ namespace Xamarin.Forms.Platform.iOS { _tableViewController = new FormsUITableViewController(e.NewElement); SetNativeControl(_tableViewController.TableView); - Control.CellLayoutMarginsFollowReadableWidth = false; + if (Forms.IsiOS9OrNewer) + Control.CellLayoutMarginsFollowReadableWidth = false; _insetTracker = new KeyboardInsetTracker(_tableViewController.TableView, () => Control.Window, insets => Control.ContentInset = Control.ScrollIndicatorInsets = insets, point => { @@ -369,7 +370,8 @@ namespace Xamarin.Forms.Platform.iOS } else { - Control.EstimatedRowHeight = 0; + if (Forms.IsiOS7OrNewer) + Control.EstimatedRowHeight = 0; _estimatedRowHeight = true; } } @@ -558,9 +560,10 @@ namespace Xamarin.Forms.Platform.iOS void UpdateRowHeight() { var rowHeight = Element.RowHeight; - if (Element.HasUnevenRows && rowHeight == -1) + if (Element.HasUnevenRows && rowHeight == -1 && Forms.IsiOS7OrNewer) { - Control.RowHeight = UITableView.AutomaticDimension; + if (Forms.IsiOS8OrNewer) + Control.RowHeight = UITableView.AutomaticDimension; } else Control.RowHeight = rowHeight <= 0 ? DefaultRowHeight : rowHeight; @@ -610,7 +613,9 @@ namespace Xamarin.Forms.Platform.iOS 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) - return UITableView.AutomaticDimension; + if (Forms.IsiOS8OrNewer) + return UITableView.AutomaticDimension; + return CalculateHeightForCell(tableView, cell); } var renderHeight = cell.RenderHeight; @@ -676,7 +681,7 @@ namespace Xamarin.Forms.Platform.iOS { _uiTableViewController = uiTableViewController; _uiTableView = uiTableViewController.TableView; - _defaultSectionHeight = DefaultRowHeight; + _defaultSectionHeight = Forms.IsiOS8OrNewer ? DefaultRowHeight : _uiTableView.SectionHeaderHeight; List = list; List.ItemSelected += OnItemSelected; UpdateShortNameListener(); @@ -1002,7 +1007,8 @@ namespace Xamarin.Forms.Platform.iOS public FormsUITableViewController(ListView element) { - TableView.CellLayoutMarginsFollowReadableWidth = false; + if (Forms.IsiOS9OrNewer) + TableView.CellLayoutMarginsFollowReadableWidth = false; _refresh = new UIRefreshControl(); _refresh.ValueChanged += OnRefreshingChanged; _list = element; diff --git a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs index 60ae1853..adf32192 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs @@ -182,7 +182,13 @@ namespace Xamarin.Forms.Platform.iOS { base.ViewDidLoad(); - UpdateTranslucent(); + if (Forms.IsiOS7OrNewer) + { + + UpdateTranslucent(); + } + else + WantsFullScreenLayout = false; _secondaryToolbar = new SecondaryToolbar { Frame = new RectangleF(0, 0, 320, 44) }; View.Add(_secondaryToolbar); @@ -448,6 +454,11 @@ namespace Xamarin.Forms.Platform.iOS void UpdateTranslucent() { + if (!Forms.IsiOS7OrNewer) + { + return; + } + NavigationBar.Translucent = ((NavigationPage)Element).OnThisPlatform().IsNavigationBarTranslucent(); } @@ -560,9 +571,18 @@ namespace Xamarin.Forms.Platform.iOS { var barBackgroundColor = ((NavigationPage)Element).BarBackgroundColor; // Set navigation bar background color - NavigationBar.BarTintColor = barBackgroundColor == Color.Default - ? UINavigationBar.Appearance.BarTintColor - : barBackgroundColor.ToUIColor(); + if (Forms.IsiOS7OrNewer) + { + NavigationBar.BarTintColor = barBackgroundColor == Color.Default + ? UINavigationBar.Appearance.BarTintColor + : barBackgroundColor.ToUIColor(); + } + else + { + NavigationBar.TintColor = barBackgroundColor == Color.Default + ? UINavigationBar.Appearance.TintColor + : barBackgroundColor.ToUIColor(); + } } void UpdateBarTextColor() @@ -596,9 +616,12 @@ namespace Xamarin.Forms.Platform.iOS var statusBarColorMode = (Element as NavigationPage).OnThisPlatform().GetStatusBarTextColorMode(); // set Tint color (i. e. Back Button arrow and Text) - NavigationBar.TintColor = barTextColor == Color.Default || statusBarColorMode == StatusBarTextColorMode.DoNotAdjust + if (Forms.IsiOS7OrNewer) + { + NavigationBar.TintColor = barTextColor == Color.Default || statusBarColorMode == StatusBarTextColorMode.DoNotAdjust ? UINavigationBar.Appearance.TintColor : barTextColor.ToUIColor(); + } if (statusBarColorMode == StatusBarTextColorMode.DoNotAdjust || barTextColor.Luminosity <= 0.5) { @@ -656,13 +679,18 @@ namespace Xamarin.Forms.Platform.iOS #pragma warning disable 0618 //retaining legacy call to obsolete code var tintColor = ((NavigationPage)Element).Tint; #pragma warning restore 0618 - NavigationBar.BarTintColor = tintColor == Color.Default - ? UINavigationBar.Appearance.BarTintColor - : tintColor.ToUIColor(); - if (tintColor == Color.Default) - NavigationBar.TintColor = UINavigationBar.Appearance.TintColor; + 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; + } else - NavigationBar.TintColor = tintColor.Luminosity > 0.5 ? UIColor.Black : UIColor.White; + NavigationBar.TintColor = tintColor == Color.Default ? null : tintColor.ToUIColor(); } void UpdateToolBarVisible() @@ -748,7 +776,9 @@ namespace Xamarin.Forms.Platform.iOS public ParentingViewController(NavigationRenderer navigation) { - AutomaticallyAdjustsScrollViewInsets = false; + if (Forms.IsiOS7OrNewer) + AutomaticallyAdjustsScrollViewInsets = false; + _navigation = new WeakReference<NavigationRenderer>(navigation); } diff --git a/Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs index e2455d78..1f7408b7 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/PageRenderer.cs @@ -19,6 +19,8 @@ namespace Xamarin.Forms.Platform.iOS public PageRenderer() { + if (!Forms.IsiOS7OrNewer) + WantsFullScreenLayout = true; } void IEffectControlProvider.RegisterEffect(Effect effect) diff --git a/Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs index 501312cd..627bec7f 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/PhoneMasterDetailRenderer.cs @@ -28,6 +28,8 @@ namespace Xamarin.Forms.Platform.iOS public PhoneMasterDetailRenderer() { + if (!Forms.IsiOS7OrNewer) + WantsFullScreenLayout = true; } IMasterDetailPageController MasterDetailPageController => Element as IMasterDetailPageController; diff --git a/Xamarin.Forms.Platform.iOS/Renderers/SearchBarRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/SearchBarRenderer.cs index a9af856f..8c54702f 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/SearchBarRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/SearchBarRenderer.cs @@ -106,9 +106,17 @@ namespace Xamarin.Forms.Platform.iOS return; if (_defaultTintColor == null) - _defaultTintColor = Control.BarTintColor; + { + if (Forms.IsiOS7OrNewer) + _defaultTintColor = Control.BarTintColor; + else + _defaultTintColor = Control.TintColor; + } - Control.BarTintColor = color.ToUIColor(_defaultTintColor); + if (Forms.IsiOS7OrNewer) + Control.BarTintColor = color.ToUIColor(_defaultTintColor); + else + Control.TintColor = color.ToUIColor(_defaultTintColor); if (color.A < 1) Control.SetBackgroundImage(new UIImage(), UIBarPosition.Any, UIBarMetrics.Default); diff --git a/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs index f7ca834c..c6c07370 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs @@ -134,6 +134,14 @@ namespace Xamarin.Forms.Platform.iOS _loaded = true; } + public override void ViewDidLoad() + { + base.ViewDidLoad(); + + if (!Forms.IsiOS7OrNewer) + WantsFullScreenLayout = false; + } + protected override void Dispose(bool disposing) { if (disposing) @@ -306,14 +314,25 @@ namespace Xamarin.Forms.Platform.iOS if (!_defaultBarColorSet) { - _defaultBarColor = TabBar.BarTintColor; + if (Forms.IsiOS7OrNewer) + _defaultBarColor = TabBar.BarTintColor; + else + _defaultBarColor = TabBar.TintColor; + _defaultBarColorSet = true; } if (!isDefaultColor) _barBackgroundColorWasSet = true; - TabBar.BarTintColor = isDefaultColor ? _defaultBarColor : barBackgroundColor.ToUIColor(); + if (Forms.IsiOS7OrNewer) + { + TabBar.BarTintColor = isDefaultColor ? _defaultBarColor : barBackgroundColor.ToUIColor(); + } + else + { + TabBar.TintColor = isDefaultColor ? _defaultBarColor : barBackgroundColor.ToUIColor(); + } } void UpdateBarTextColor() @@ -348,7 +367,12 @@ namespace Xamarin.Forms.Platform.iOS item.SetTitleTextAttributes(attributes, UIControlState.Normal); } - TabBar.TintColor = isDefaultColor ? _defaultBarTextColor : barTextColor.ToUIColor(); + // set TintColor for selected icon + // setting the unselected icon tint is not supported by iOS + if (Forms.IsiOS7OrNewer) + { + TabBar.TintColor = isDefaultColor ? _defaultBarTextColor : barTextColor.ToUIColor(); + } } void UpdateChildrenOrderIndex(UIViewController[] viewControllers) diff --git a/Xamarin.Forms.Platform.iOS/Renderers/TableViewModelRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/TableViewModelRenderer.cs index 2a754586..4a9f694d 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/TableViewModelRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/TableViewModelRenderer.cs @@ -137,11 +137,10 @@ namespace Xamarin.Forms.Platform.iOS var cell = View.Model.GetCell(indexPath.Section, indexPath.Row); var h = cell.Height; - if (View.RowHeight == -1 && h == -1 && cell is ViewCell) + if (View.RowHeight == -1 && h == -1 && cell is ViewCell && Forms.IsiOS8OrNewer) { return UITableView.AutomaticDimension; - else if (h == -1) + } else if (h == -1) return tableView.RowHeight; - return (nfloat)h; } } diff --git a/Xamarin.Forms.Platform.iOS/Renderers/TableViewRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/TableViewRenderer.cs index 0009acea..725ef51f 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/TableViewRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/TableViewRenderer.cs @@ -73,7 +73,8 @@ namespace Xamarin.Forms.Platform.iOS _originalBackgroundView = tv.BackgroundView; SetNativeControl(tv); - tv.CellLayoutMarginsFollowReadableWidth = false; + if (Forms.IsiOS9OrNewer) + tv.CellLayoutMarginsFollowReadableWidth = false; _insetTracker = new KeyboardInsetTracker(tv, () => Control.Window, insets => Control.ContentInset = Control.ScrollIndicatorInsets = insets, point => { @@ -133,9 +134,10 @@ namespace Xamarin.Forms.Platform.iOS void UpdateRowHeight() { var rowHeight = Element.RowHeight; - if (Element.HasUnevenRows && rowHeight == -1) - Control.RowHeight = UITableView.AutomaticDimension; - else + if (Element.HasUnevenRows && rowHeight == -1 && Forms.IsiOS7OrNewer) { + if (Forms.IsiOS8OrNewer) + Control.RowHeight = UITableView.AutomaticDimension; + } else Control.RowHeight = rowHeight <= 0 ? DefaultRowHeight : rowHeight; } @@ -145,7 +147,8 @@ namespace Xamarin.Forms.Platform.iOS if (Element.HasUnevenRows && rowHeight == -1) { Control.EstimatedRowHeight = DefaultRowHeight; } else { - Control.EstimatedRowHeight = 0; + if (Forms.IsiOS7OrNewer) + Control.EstimatedRowHeight = 0; } } } diff --git a/Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs index 9f0dff00..e72b243b 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs @@ -223,8 +223,11 @@ namespace Xamarin.Forms.Platform.iOS if (!MasterDetailPageController.ShouldShowSplitMode && _masterVisible) { MasterDetailPageController.CanChangeIsPresented = true; - PreferredDisplayMode = UISplitViewControllerDisplayMode.PrimaryHidden; - PreferredDisplayMode = UISplitViewControllerDisplayMode.Automatic; + if (Forms.IsiOS8OrNewer) + { + PreferredDisplayMode = UISplitViewControllerDisplayMode.PrimaryHidden; + PreferredDisplayMode = UISplitViewControllerDisplayMode.Automatic; + } } MasterDetailPageController.UpdateMasterBehavior(); @@ -304,7 +307,10 @@ namespace Xamarin.Forms.Platform.iOS void PerformButtonSelector() { - DisplayModeButtonItem.Target.PerformSelector(DisplayModeButtonItem.Action, DisplayModeButtonItem, 0); + if (Forms.IsiOS8OrNewer) + DisplayModeButtonItem.Target.PerformSelector(DisplayModeButtonItem.Action, DisplayModeButtonItem, 0); + else + PresentButton.Target.PerformSelector(PresentButton.Action, PresentButton, 0); } void ToggleMaster() |