Skip to content

Implement Picker control#81

Merged
jonathanpeppers merged 12 commits intomainfrom
copilot/implement-picker-tests
Feb 14, 2026
Merged

Implement Picker control#81
jonathanpeppers merged 12 commits intomainfrom
copilot/implement-picker-tests

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 14, 2026

Adds dropdown/selection control using native platform widgets: UIPickerView (iOS) and Spinner (Android).

Implementation

Core (Core/Picker.cs)

  • Items: ObservableCollection<string> - data source
  • SelectedIndex: int - current selection (-1 for none)
  • SelectedItem: string? - computed from index, null-safe
  • Title: string - prompt text (Android only)
  • TextColor: Color? - item text color

iOS (Platforms/iOS/Picker.cs)

  • Custom UIPickerViewModel with WeakReference<Picker> to prevent retain cycles
  • Single-component picker with dynamic row count from Items collection

Android (Platforms/Android/Picker.cs)

  • ArrayAdapter<string> backed by Items collection
  • Circular event prevention: updates only when e.Position != _selectedIndex

Usage

var picker = new Picker
{
    Title = "Select an option",
    Items = new ObservableCollection<string> { "Red", "Green", "Blue" }
};

picker.PropertyChanged += (s, e) => 
{
    if (e.PropertyName == nameof(picker.SelectedIndex))
        Debug.WriteLine($"Selected: {picker.SelectedItem}");
};

Tests & Sample

  • 9 unit tests covering property notifications, collection ops, null safety
  • PickerScenario demonstrates color selection with live UI updates
  • Updated comparison doc: 6→7 implemented controls

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement Picker and add test scenarios Implement Picker control Feb 14, 2026
@jonathanpeppers jonathanpeppers marked this pull request as ready for review February 14, 2026 03:10
Copilot AI review requested due to automatic review settings February 14, 2026 03:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new cross-platform Picker control to Spice (core + iOS + Android), along with unit tests, a scenario sample, and documentation updates reflecting the new control.

Changes:

  • Introduces Picker core API (Items, SelectedIndex, SelectedItem, Title, TextColor).
  • Adds native implementations using UIPickerView (iOS) and Spinner (Android).
  • Adds unit tests + a scenario demo, and updates the MAUI controls comparison doc.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tests/Spice.Tests/PickerTests.cs Adds unit tests for Picker core behaviors and property notifications.
src/Spice/Core/Picker.cs Defines the core Picker API and selection model.
src/Spice/Platforms/iOS/Picker.cs Implements iOS native wiring via UIPickerView + model.
src/Spice/Platforms/Android/Picker.cs Implements Android native wiring via Spinner + ArrayAdapter.
samples/Spice.Scenarios/Scenarios/PickerScenario.cs Adds a scenario demonstrating picker-driven color selection.
samples/Spice.Scenarios/App.cs Adds a navigation button to launch the new picker scenario.
docs/MAUI-CONTROLS-COMPARISON.md Marks Picker as implemented and updates counts/mappings.

Comment thread src/Spice/Core/Picker.cs
Comment thread src/Spice/Platforms/Android/Picker.cs
Comment thread src/Spice/Platforms/Android/Picker.cs Outdated
Comment thread src/Spice/Platforms/iOS/Picker.cs Outdated
Comment thread src/Spice/Platforms/iOS/Picker.cs Outdated
Comment thread src/Spice/Platforms/iOS/Picker.cs
Comment thread samples/Spice.Scenarios/Scenarios/PickerScenario.cs Outdated
jonathanpeppers and others added 9 commits February 13, 2026 23:49
…ker-tests

# Conflicts:
#	docs/MAUI-CONTROLS-COMPARISON.md
#	samples/Spice.Scenarios/App.cs
- Fix missing using directives (ObservableCollection, Specialized) in iOS/Android
- Fix Colors reference in tests (add Microsoft.Maui.Graphics using)
- Fix App.cs: separate Picker and Slider into individual Button instances
- Fix Color constructor: use Color.FromRgb(200, 200, 0) for Yellow
- Raise PropertyChanged for SelectedItem when SelectedIndex/Items change
- Subscribe to Items.CollectionChanged for live Add/Remove/Clear updates
- Clamp SelectedIndex to valid range (Spinner/UIPickerView require selection)
- Implement GetAttributedTitle on iOS to honor TextColor

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
# Conflicts:
#	samples/Spice.Scenarios/App.cs
- Remove null checks on OnItemsChanged params (non-nullable per generator)
- Replace AddAll with foreach loop to avoid ICollection/Object[] ambiguity

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The CommunityToolkit.Mvvm source generator declares oldValue as nullable.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The generated setter fires OnPropertyChanged(SelectedIndex) after
the partial method that raises OnPropertyChanged(SelectedItem).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers jonathanpeppers enabled auto-merge (squash) February 14, 2026 23:04
@jonathanpeppers jonathanpeppers merged commit 3a78ff7 into main Feb 14, 2026
1 check passed
@jonathanpeppers jonathanpeppers deleted the copilot/implement-picker-tests branch February 14, 2026 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants