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

[iOS] Fix crash with TimePicker on iOS14 #12158

Merged
merged 6 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;

#if UITEST
using Xamarin.Forms.Core.UITests;
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.ManualReview)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 11963, "Time Picker is broken in Xamarin.Forms as of iOS 14 Public Beta 6", PlatformAffected.iOS)]
public class Issue11963 : TestContentPage
{
protected override void Init()
{
var timePicker = new TimePicker();

Content = new StackLayout
{
Spacing = 20,
VerticalOptions = LayoutOptions.Center,
Children = { timePicker }
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1483,6 +1483,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue11764.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11573.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11496.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11963.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">
Expand Down Expand Up @@ -1754,7 +1755,7 @@
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue11653.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue11737.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
Expand Down
11 changes: 11 additions & 0 deletions Xamarin.Forms.Platform.iOS/Forms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static class Forms
static bool? s_isiOS10OrNewer;
static bool? s_isiOS11OrNewer;
static bool? s_isiOS13OrNewer;
static bool? s_isiOS14OrNewer;
static bool? s_respondsTosetNeedsUpdateOfHomeIndicatorAutoHidden;

internal static bool IsiOS9OrNewer
Expand Down Expand Up @@ -81,6 +82,16 @@ internal static bool IsiOS13OrNewer
}
}

internal static bool IsiOS14OrNewer
{
get
{
if (!s_isiOS14OrNewer.HasValue)
s_isiOS14OrNewer = UIDevice.CurrentDevice.CheckSystemVersion(14, 0);
return s_isiOS14OrNewer.Value;
}
}

internal static bool RespondsToSetNeedsUpdateOfHomeIndicatorAutoHidden
{
get
Expand Down
7 changes: 6 additions & 1 deletion Xamarin.Forms.Platform.iOS/Renderers/TimePickerRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ protected override void OnElementChanged(ElementChangedEventArgs<TimePicker> e)
entry.EditingDidEnd += OnEnded;

_picker = new UIDatePicker { Mode = UIDatePickerMode.Time, TimeZone = new NSTimeZone("UTC") };

#if __XCODE11__
if (Forms.IsiOS14OrNewer)
{
_picker.PreferredDatePickerStyle = UIKit.UIDatePickerStyle.Wheels;
}
#endif
var width = UIScreen.MainScreen.Bounds.Width;
var toolbar = new UIToolbar(new RectangleF(0, 0, width, 44)) { BarStyle = UIBarStyle.Default, Translucent = true };
var spacer = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);
Expand Down