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

Block keyboard for iOS 15 time picker #14690

Merged
merged 2 commits into from
Oct 5, 2021
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
11 changes: 11 additions & 0 deletions Xamarin.Forms.Platform.iOS/Forms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static class Forms
static bool? s_isiOS12OrNewer;
static bool? s_isiOS13OrNewer;
static bool? s_isiOS14OrNewer;
static bool? s_isiOS15OrNewer;
static bool? s_respondsTosetNeedsUpdateOfHomeIndicatorAutoHidden;

internal static bool IsiOS9OrNewer
Expand Down Expand Up @@ -103,6 +104,16 @@ internal static bool IsiOS14OrNewer
}
}

internal static bool IsiOS15OrNewer
{
get
{
if (!s_isiOS15OrNewer.HasValue)
s_isiOS15OrNewer = UIDevice.CurrentDevice.CheckSystemVersion(15, 0);
return s_isiOS15OrNewer.Value;
}
}


internal static bool RespondsToSetNeedsUpdateOfHomeIndicatorAutoHidden
{
Expand Down
16 changes: 16 additions & 0 deletions Xamarin.Forms.Platform.iOS/Renderers/TimePickerRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ protected override void Dispose(bool disposing)
{
_picker.RemoveFromSuperview();
_picker.ValueChanged -= OnValueChanged;

if (Forms.IsiOS15OrNewer)
{
_picker.EditingDidBegin -= PickerEditingDidBegin;
}

_picker.Dispose();
_picker = null;
}
Expand Down Expand Up @@ -91,6 +97,11 @@ protected override void OnElementChanged(ElementChangedEventArgs<TimePicker> e)
_picker.PreferredDatePickerStyle = UIKit.UIDatePickerStyle.Wheels;
}

if (Forms.IsiOS15OrNewer)
{
_picker.EditingDidBegin += PickerEditingDidBegin;
}

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 Expand Up @@ -162,6 +173,11 @@ void OnStarted(object sender, EventArgs eventArgs)
ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, true);
}

void PickerEditingDidBegin(object sender, EventArgs eventArgs)
{
_picker.ResignFirstResponder();
}

void OnValueChanged(object sender, EventArgs e)
{
if (Element.OnThisPlatform().UpdateMode() == UpdateMode.Immediately)
Expand Down