Closed dimonovdd closed 3 years ago
We can also add getCurrentView
parameter. This will add flexibility and the project will not have unnecessary dependencies.
public void Show(string title, string doneButtonTitle, string cancelButtonTitle,
UIDatePickerMode datePickerMode,
Action<DateTime> callback,
DateTime defaultDate, DateTime? maximumDate = null,
DateTime? minimumDate = null,
Action? cancelCallback = null,
Func<UIView> getCurrentView = null)
{
//...
UIView view = getCurrentView == null
? UIApplication.SharedApplication.Windows.Last()
: getCurrentView.Invoke();
view.AddSubview(this);
view.BringSubviewToFront(this);
view.EndEditing(true);
//...
}
At the moment, this solution is used (Permalink):
The most correct approach is to use
GetCurrentUIViewController
method from Xamarin.Essentials library (Source Code).