-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Picker Handlers #433
Merged
Merged
Picker Handlers #433
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5e44a5b
PickerHandlers
jsuarezruiz 91134e3
Nullability fixes
jsuarezruiz 2f388da
Updated Picker device tests
jsuarezruiz 701d880
New things in the tests!
mattleibow a2552f2
Removed unnecessary Android Api level validation
jsuarezruiz 33c1a5c
Added Picker Items null validation in iOS PickerHandler
jsuarezruiz 94474ec
Moved Picker Handler tests between different classes
jsuarezruiz aea38d3
Renamed NativePicker to MauiPicker
jsuarezruiz 5b35b54
Removed unused code from iOS PickerExtensions
jsuarezruiz 7190c2c
Fix build error
jsuarezruiz 706ec8a
Fix build error
jsuarezruiz ff80410
Remove duplicate class
hartez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this have been |
||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we unsubscribing when the Items/ItemsSource property changes? Like the whole list is assigned a new object? |
||
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these two concepts mean anything at the core layer? This feels a bit binding-y. Also, how will Comet do this? Are we maybe forcing something?