Commit 684044a
authored
IndicatorView: Fix MaximumVisible not respected when using custom IndicatorTemplate (#31469)
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!
### Issue Details
- When using IndicatorView with a custom IndicatorTemplate, the
MaximumVisible property is not respected.
### Root Cause
- When IndicatorView uses a custom IndicatorTemplate, the BindableLayout
path is used to render indicators. In
IndicatorStackLayout.BindIndicatorItems(), the full ItemsSource was
passed directly to BindableLayout.SetItemsSource() without applying the
MaximumVisible limit.
- The MaximumVisible cap was only enforced in the native (non-template)
code path.
### Description of Change
- Modified BindIndicatorItems() in IndicatorStackLayout to call a new
GetFilteredItemsSource() helper before binding. The helper returns a
filtered List<object> capped at MaximumVisible items when the source has
more items than the limit; otherwise, it returns the original
ItemsSource unchanged.
- This fix applies on both initial render and when MaximumVisible
changes dynamically, because
IndicatorView.MaximumVisibleProperty.propertyChanged calls
ResetIndicators() → BindIndicatorItems().
### Key Technical Details
**IndicatorStackLayout.GetFilteredItemsSource():**
1. Returns null if ItemsSource is null or MaximumVisible <= 0
2. Returns the original ItemsSource if totalCount <= MaximumVisible (no
filtering needed)
3. Otherwise enumerates up to MaximumVisible items into a new list of
objects and returns it.
**Code path (with IndicatorTemplate):**
BindIndicatorItems() → GetFilteredItemsSource() →
BindableLayout.SetItemsSource(filtered)
**Code path (without IndicatorTemplate):**
Not affected — native rendering handles MaximumVisible separately.
### Issues Fixed
Fixes #31145
### Validated the behaviour in the following platforms
- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac
### Output
| Platform | Before Fix | After Fix |
|----------|----------|----------|
| Android | <video
src="https://github.com/user-attachments/assets/b077642e-d634-42a3-8d61-8374ac599b43">
| <video
src="https://github.com/user-attachments/assets/cd4b29b1-4087-41cc-a7f3-67396accfe6b">
|
| iOS | <video
src="https://github.com/user-attachments/assets/297cfde8-bffe-4fcb-a08b-a43362c944ff">
| <video
src="https://github.com/user-attachments/assets/8062d14e-ba38-4015-83dd-ca01e218ebfd">
|
| Windows | <video
src="https://github.com/user-attachments/assets/69aad00d-1f51-47fc-b92f-a8b4fe2741ac">
| <video
src="https://github.com/user-attachments/assets/73eacf53-7d6d-4e87-a606-558ba3482158">
|
| Mac | <video
src="https://github.com/user-attachments/assets/49720bbc-ce67-49d6-95a0-6a8018b5d4fa">
| <video
src="https://github.com/user-attachments/assets/8e494e0c-c795-4b62-894a-ddfdc4e4c27b">
|1 parent f53c886 commit 684044a
7 files changed
Lines changed: 119 additions & 1 deletion
File tree
- src/Controls
- src/Core/IndicatorView
- tests
- TestCases.Android.Tests/snapshots/android
- TestCases.HostApp/Issues
- TestCases.Mac.Tests/snapshots/mac
- TestCases.WinUI.Tests/snapshots/windows
- TestCases.iOS.Tests/snapshots/ios
Lines changed: 39 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
1 | 4 | | |
| 5 | + | |
2 | 6 | | |
3 | 7 | | |
4 | 8 | | |
| |||
161 | 165 | | |
162 | 166 | | |
163 | 167 | | |
164 | | - | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
165 | 172 | | |
166 | 173 | | |
167 | 174 | | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
168 | 206 | | |
169 | 207 | | |
170 | 208 | | |
| |||
Lines changed: 57 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
Lines changed: 23 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
0 commit comments