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

Commit

Permalink
Block keyboard for iOS 15 time picker (#14690)
Browse files Browse the repository at this point in the history
* Block keyboard for iOS 15 time picker

* Update TimePickerRenderer.cs
  • Loading branch information
jfversluis committed Oct 5, 2021
1 parent 6d751f7 commit e5139b5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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

0 comments on commit e5139b5

Please sign in to comment.