-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* PickerHandlers * Nullability fixes * Updated Picker device tests * New things in the tests! * Removed unnecessary Android Api level validation * Added Picker Items null validation in iOS PickerHandler * Moved Picker Handler tests between different classes * Renamed NativePicker to MauiPicker * Removed unused code from iOS PickerExtensions * Fix build error * Fix build error * Remove duplicate class Co-authored-by: Matthew Leibowitz <mattleibow@live.com> Co-authored-by: E.Z. Hart <hartez@gmail.com>
- Loading branch information
1 parent
b6f3c17
commit f1298b4
Showing
24 changed files
with
799 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Microsoft.Maui.Controls | ||
{ | ||
public partial class Picker : IPicker | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.Maui | ||
{ | ||
public interface IPicker : IView | ||
{ | ||
string Title { get; } | ||
IList<string> Items { get; } | ||
IList ItemsSource { get; } | ||
int SelectedIndex { get; set; } | ||
object? SelectedItem { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using System; | ||
using System.Collections.Specialized; | ||
using System.Linq; | ||
using Android.App; | ||
using AResource = Android.Resource; | ||
|
||
namespace Microsoft.Maui.Handlers | ||
{ | ||
public partial class PickerHandler : AbstractViewHandler<IPicker, MauiPicker> | ||
{ | ||
AlertDialog? _dialog; | ||
|
||
protected override MauiPicker CreateNativeView() => | ||
new MauiPicker(Context); | ||
|
||
protected override void ConnectHandler(MauiPicker nativeView) | ||
{ | ||
nativeView.FocusChange += OnFocusChange; | ||
nativeView.Click += OnClick; | ||
|
||
if (VirtualView != null && VirtualView.Items is INotifyCollectionChanged notifyCollection) | ||
notifyCollection.CollectionChanged += OnCollectionChanged; | ||
|
||
base.ConnectHandler(nativeView); | ||
} | ||
|
||
protected override void DisconnectHandler(MauiPicker nativeView) | ||
{ | ||
nativeView.FocusChange -= OnFocusChange; | ||
nativeView.Click -= OnClick; | ||
|
||
if (VirtualView != null && VirtualView.Items is INotifyCollectionChanged notifyCollection) | ||
notifyCollection.CollectionChanged -= OnCollectionChanged; | ||
|
||
base.DisconnectHandler(nativeView); | ||
} | ||
public static void MapTitle(PickerHandler handler, IPicker picker) | ||
{ | ||
handler.TypedNativeView?.UpdateTitle(picker); | ||
} | ||
|
||
public static void MapSelectedIndex(PickerHandler handler, IPicker picker) | ||
{ | ||
handler.TypedNativeView?.UpdateSelectedIndex(picker); | ||
} | ||
|
||
void OnFocusChange(object? sender, global::Android.Views.View.FocusChangeEventArgs e) | ||
{ | ||
if (TypedNativeView == null) | ||
return; | ||
|
||
if (e.HasFocus) | ||
{ | ||
if (TypedNativeView.Clickable) | ||
TypedNativeView.CallOnClick(); | ||
else | ||
OnClick(TypedNativeView, EventArgs.Empty); | ||
} | ||
else if (_dialog != null) | ||
{ | ||
_dialog.Hide(); | ||
TypedNativeView.ClearFocus(); | ||
_dialog = null; | ||
} | ||
} | ||
|
||
void OnClick(object? sender, EventArgs e) | ||
{ | ||
if (_dialog == null && VirtualView != null) | ||
{ | ||
using (var builder = new AlertDialog.Builder(Context)) | ||
{ | ||
builder.SetTitle(VirtualView.Title ?? string.Empty); | ||
|
||
string[] items = VirtualView.Items.ToArray(); | ||
|
||
builder.SetItems(items, (s, e) => | ||
{ | ||
var selectedIndex = e.Which; | ||
VirtualView.SelectedIndex = selectedIndex; | ||
TypedNativeView?.UpdatePicker(VirtualView); | ||
}); | ||
|
||
builder.SetNegativeButton(AResource.String.Cancel, (o, args) => { }); | ||
|
||
_dialog = builder.Create(); | ||
} | ||
|
||
if (_dialog == null) | ||
return; | ||
|
||
_dialog.SetCanceledOnTouchOutside(true); | ||
|
||
_dialog.DismissEvent += (sender, args) => | ||
{ | ||
_dialog.Dispose(); | ||
_dialog = null; | ||
}; | ||
|
||
_dialog.Show(); | ||
} | ||
} | ||
|
||
void OnCollectionChanged(object? sender, EventArgs e) | ||
{ | ||
if (VirtualView == null || TypedNativeView == null) | ||
return; | ||
|
||
TypedNativeView.UpdatePicker(VirtualView); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
|
||
namespace Microsoft.Maui.Handlers | ||
{ | ||
public partial class PickerHandler : AbstractViewHandler<IPicker, object> | ||
{ | ||
protected override object CreateNativeView() => throw new NotImplementedException(); | ||
|
||
public static void MapTitle(PickerHandler handler, IPicker view) { } | ||
public static void MapSelectedIndex(PickerHandler handler, IPicker view) { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace Microsoft.Maui.Handlers | ||
{ | ||
public partial class PickerHandler | ||
{ | ||
public static PropertyMapper<IPicker, PickerHandler> PickerMapper = new PropertyMapper<IPicker, PickerHandler>(ViewHandler.ViewMapper) | ||
{ | ||
[nameof(IPicker.Title)] = MapTitle, | ||
[nameof(IPicker.SelectedIndex)] = MapSelectedIndex | ||
}; | ||
|
||
public PickerHandler() : base(PickerMapper) | ||
{ | ||
|
||
} | ||
|
||
public PickerHandler(PropertyMapper mapper) : base(mapper) | ||
{ | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.