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

Commit

Permalink
[Android] Fix focus/unfocus behavior on both Picker renderers (#264)
Browse files Browse the repository at this point in the history
On AppCompat, focus and unfocus would not trigger when using the
Picker. On pre-Lollipop, unfocus would not trigger, but only when
tapping outside of the dialog.
  • Loading branch information
pauldipietro authored and samhouts committed Jul 26, 2016
1 parent d04a4a3 commit ea01c07
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Xamarin.Forms.Platform.Android/AppCompat/PickerRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,15 @@ void OnClick()
builder.SetItems(items, (s, e) => ((IElementController)model).SetValueFromRenderer(Picker.SelectedIndexProperty, e.Which));

builder.SetNegativeButton(global::Android.Resource.String.Cancel, (o, args) => { });

((IElementController)Element).SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, true);

_dialog = builder.Create();
}
_dialog.SetCanceledOnTouchOutside(true);
_dialog.DismissEvent += (sender, args) =>
{
((IElementController)Element).SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false);
_dialog.Dispose();
_dialog = null;
};
Expand Down
7 changes: 6 additions & 1 deletion Xamarin.Forms.Platform.Android/Renderers/PickerRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ void OnClick()
_dialog = null;
});

(_dialog = builder.Create()).Show();
_dialog = builder.Create();
_dialog.DismissEvent += (sender, args) =>
{
ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false);
};
_dialog.Show();
}

void RowsCollectionChanged(object sender, EventArgs e)
Expand Down

0 comments on commit ea01c07

Please sign in to comment.