Skip to content

Commit cdf461c

Browse files
Merge branch 'main' into perf/chart-control-optimizations
2 parents e41c059 + fc007af commit cdf461c

61 files changed

Lines changed: 1901 additions & 224 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

maui/src/Accordion/AccordionItemView.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,21 @@ internal bool CanCollapseItemOnSingleAndMultipleExpandMode()
7171
return false;
7272
}
7373

74-
var expandedItems = Accordion.Items.Where(x => x._accordionItemView != null && x._accordionItemView.IsExpanded).ToList();
74+
var expandedCount = 0;
75+
foreach (var item in Accordion.Items)
76+
{
77+
if (item._accordionItemView != null && item._accordionItemView.IsExpanded)
78+
{
79+
expandedCount++;
80+
if (expandedCount > 1)
81+
{
82+
break;
83+
}
84+
}
85+
}
86+
7587
return (Accordion.ExpandMode == AccordionExpandMode.Single ||
76-
Accordion.ExpandMode == AccordionExpandMode.Multiple) && expandedItems.Count == 1;
88+
Accordion.ExpandMode == AccordionExpandMode.Multiple) && expandedCount == 1;
7789
}
7890

7991
#endregion

maui/src/Accordion/SfAccordion.cs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,22 @@ internal void UpdateIsExpandValueBasedOnIndex(int index, bool isExpanded)
540540
/// </summary>
541541
internal void UpdateSelection()
542542
{
543-
var selectedItems = Items.Where(x => x._accordionItemView != null && x._accordionItemView.IsSelected).ToList();
544-
if (selectedItems.Count == 1 && Items[selectedItems[0]._itemIndex] is AccordionItem items && items._accordionItemView is AccordionItemView accordionItem)
543+
AccordionItem? selectedItem = null;
544+
int selectedCount = 0;
545+
foreach (var item in Items)
546+
{
547+
if (item._accordionItemView != null && item._accordionItemView.IsSelected)
548+
{
549+
selectedItem ??= item;
550+
selectedCount++;
551+
if (selectedCount > 1)
552+
{
553+
break;
554+
}
555+
}
556+
}
557+
558+
if (selectedCount == 1 && selectedItem != null && Items[selectedItem._itemIndex] is AccordionItem accordionItemEntry && accordionItemEntry._accordionItemView is AccordionItemView accordionItem)
545559
{
546560
accordionItem.IsSelected = false;
547561
}
@@ -560,7 +574,15 @@ internal void UpdateAccordionItemsBasedOnExpandModes(bool isExpandModeChanged)
560574
return;
561575
}
562576

563-
var expandedItems = Items.Where(x => x._accordionItemView != null && x._accordionItemView.IsExpanded).ToList();
577+
var expandedItems = new List<AccordionItem>();
578+
foreach (var item in Items)
579+
{
580+
if (item._accordionItemView != null && item._accordionItemView.IsExpanded)
581+
{
582+
expandedItems.Add(item);
583+
}
584+
}
585+
564586
switch (ExpandMode)
565587
{
566588
case AccordionExpandMode.Single:
@@ -1575,7 +1597,15 @@ void IKeyboardListener.OnPreviewKeyDown(Syncfusion.Maui.Toolkit.Internals.KeyEve
15751597
/// <param name="e">The <see cref="KeyEventArgs"/> containing the event data for the key that was pressed.</param>
15761598
void IKeyboardListener.OnKeyDown(KeyEventArgs e)
15771599
{
1578-
var selectedItem = Items.FirstOrDefault(x => x._accordionItemView != null && x._accordionItemView.IsSelected);
1600+
AccordionItem? selectedItem = null;
1601+
foreach (var item in Items)
1602+
{
1603+
if (item._accordionItemView != null && item._accordionItemView.IsSelected)
1604+
{
1605+
selectedItem = item;
1606+
break;
1607+
}
1608+
}
15791609
if (e.Key == KeyboardKey.Down || (e.Key == KeyboardKey.Tab && !e.IsShiftKeyPressed))
15801610
{
15811611
OnDownKeyPressed(selectedItem);

maui/src/BottomSheet/SfBottomSheet.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,14 +1574,10 @@ void UpdateContentAccessibility(VisualElement element, bool exclude)
15741574
/// <param name="exclude">True to exclude from accessibility, false to include.</param>
15751575
void UpdateSingleElement(VisualElement visualChild,bool exclude)
15761576
{
1577-
if (!_originalAccessibilityProperties.ContainsKey(visualChild))
1578-
{
1579-
// Store original values only if not already stored
1580-
_originalAccessibilityProperties[visualChild] = (
1581-
SemanticProperties.GetDescription(visualChild),
1582-
SemanticProperties.GetHint(visualChild)
1583-
);
1584-
}
1577+
_originalAccessibilityProperties.TryAdd(visualChild, (
1578+
SemanticProperties.GetDescription(visualChild),
1579+
SemanticProperties.GetHint(visualChild)
1580+
));
15851581

15861582
if (exclude)
15871583
{
@@ -1619,10 +1615,9 @@ void UpdateSingleElement(VisualElement visualChild,bool exclude)
16191615
var nativeContent = Content?.Handler?.PlatformView as Android.Views.View;
16201616
if (nativeContent is Android.Views.View rootView)
16211617
{
1622-
if (Content != null && !_androidContentDescriptions.ContainsKey(Content))
1618+
if (Content != null)
16231619
{
1624-
_androidContentDescriptions[Content] =
1625-
rootView.ContentDescription;
1620+
_androidContentDescriptions.TryAdd(Content, rootView.ContentDescription);
16261621
}
16271622

16281623
if (exclude) // when you want to hide content

maui/src/Calendar/Helper/CalendarViewHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2483,7 +2483,7 @@ internal static CalendarTextStyle GetOutOfRangeDatesTextStyle()
24832483
internal static List<DateTime> GetCurrentMonthDates(List<DateTime> visibleDates)
24842484
{
24852485
int currentMonth = visibleDates[visibleDates.Count / 2].Month;
2486-
List<DateTime> currentMonthDates = new List<DateTime>();
2486+
List<DateTime> currentMonthDates = new List<DateTime>(visibleDates.Count);
24872487
foreach (DateTime date in visibleDates)
24882488
{
24892489
if (date.Month != currentMonth)

maui/src/Calendar/Model/EventArgs/ViewChangedEventArgs.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@ namespace Syncfusion.Maui.Toolkit.Calendar
77
/// </summary>
88
public class CalendarViewChangedEventArgs : EventArgs
99
{
10+
#region Fields
11+
12+
static readonly ReadOnlyCollection<DateTime> s_emptyDates = new List<DateTime>(0).AsReadOnly();
13+
14+
#endregion
15+
1016
#region Properties
1117

1218
/// <summary>
1319
/// Gets the visible dates that visible on current view.
1420
/// </summary>
15-
public ReadOnlyCollection<DateTime> NewVisibleDates { get; internal set; } = new List<DateTime>().AsReadOnly();
21+
public ReadOnlyCollection<DateTime> NewVisibleDates { get; internal set; } = s_emptyDates;
1622

1723
/// <summary>
1824
/// Gets the visible dates that visible on previous view.
1925
/// </summary>
20-
public ReadOnlyCollection<DateTime> OldVisibleDates { get; internal set; } = new List<DateTime>().AsReadOnly();
26+
public ReadOnlyCollection<DateTime> OldVisibleDates { get; internal set; } = s_emptyDates;
2127

2228
/// <summary>
2329
/// Gets the new calendar view.

maui/src/Calendar/Views/CalendarView/MonthView/MonthView.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,24 @@ internal void SetFocusOnViewChanged()
880880

881881
#region Private Methods
882882

883+
/// <summary>
884+
/// Finds the special date icon details for a given date using a loop to avoid delegate allocation.
885+
/// </summary>
886+
/// <param name="dateTime">The date to look up.</param>
887+
/// <returns>The matching CalendarIconDetails or null.</returns>
888+
CalendarIconDetails? GetSpecialDateIcon(DateTime dateTime)
889+
{
890+
for (int i = 0; i < _specialDates.Count; i++)
891+
{
892+
if (CalendarViewHelper.IsSameDate(_calendarViewInfo.View, _specialDates[i].Date, dateTime, _calendarViewInfo.Identifier))
893+
{
894+
return _specialDates[i];
895+
}
896+
}
897+
898+
return null;
899+
}
900+
883901
/// <summary>
884902
/// Method to find the range is present in current view or not.
885903
/// </summary>
@@ -1635,7 +1653,7 @@ void DrawMonthCells(ICanvas canvas, bool isRTL, float weekNumberWidth, float mon
16351653
// The current date is today date and not a range then need to considered the today text style.
16361654
bool isTodayDate = todayDate.Date.Equals(dateTime.Date);
16371655
//// Stores the special dates icon details for drawing.
1638-
CalendarIconDetails? calendarSpecialDayIconDetails = _specialDates.FirstOrDefault(details => CalendarViewHelper.IsSameDate(_calendarViewInfo.View, details.Date, dateTime, _calendarViewInfo.Identifier));
1656+
CalendarIconDetails? calendarSpecialDayIconDetails = GetSpecialDateIcon(dateTime);
16391657
CalendarTextStyle textStyle = GetMonthCellStyle(dateTime, isTodayDate, isLeadingAndTrailingDates, isBlackoutDate, isDisabledDate, _calendarViewInfo.ShowOutOfRangeDates, calendarSpecialDayIconDetails != null, ref fillColor, cellBackground, trailingLeadingDateBackground, weekendsBackground, todayBackground, disabledDatesBackground, specialDatesBackground, cultureCalendar);
16401658
//// If background color is not transparent then the background color for month cell is applied.
16411659
if (fillColor != Colors.Transparent)
@@ -3080,7 +3098,7 @@ private void OnDateSemanticsNodeClicked(SemanticsNode node)
30803098

30813099
string blackOutDate = CalendarViewHelper.IsDateInDateCollection(dateTime, _disabledDates) ? SfCalendarResources.GetLocalizedString("Blackout Date") : string.Empty;
30823100
string disabledDate = CalendarViewHelper.IsDisabledDate(dateTime, _calendarViewInfo.View, _calendarViewInfo.EnablePastDates, _calendarViewInfo.MinimumDate, _calendarViewInfo.MaximumDate, _calendarViewInfo.SelectionMode, _calendarViewInfo.RangeSelectionDirection, _selectedRange, _calendarViewInfo.AllowViewNavigation, _calendarViewInfo.Identifier) ? SfCalendarResources.GetLocalizedString("Disabled Date") : string.Empty;
3083-
CalendarIconDetails? calendarSpecialDayIconDetails = _specialDates.FirstOrDefault(details => CalendarViewHelper.IsSameDate(_calendarViewInfo.View, details.Date, dateTime, _calendarViewInfo.Identifier));
3101+
CalendarIconDetails? calendarSpecialDayIconDetails = GetSpecialDateIcon(dateTime);
30843102
string specialDate = calendarSpecialDayIconDetails == null ? string.Empty : SfCalendarResources.GetLocalizedString("Special Date");
30853103
string dateType = string.IsNullOrEmpty(specialDate) ? !string.IsNullOrEmpty(blackOutDate) ? blackOutDate : disabledDate : specialDate;
30863104
string dateText = isGregorianCalendar ? dateTime.ToString("dddd, dd/MMMM/yyyy") + dateType : dateTime.ToString("dddd, dd/MMMM/yyyy", cultureInfo) + dateType;

maui/src/Carousel/Handlers/CarouselHandler.Windows.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ private static void MapSelectedIndex(CarouselHandler handler, ICarousel virtualV
7171
{
7272
if (virtualView.ItemsSource != null)
7373
{
74-
if (virtualView.SelectedIndex >= virtualView.ItemsSource.Count() && virtualView.ItemsSource.Any())
74+
int itemCount = virtualView.ItemsSource.Count();
75+
if (virtualView.SelectedIndex >= itemCount && itemCount > 0)
7576
{
76-
handler.PlatformView.SelectedIndex = virtualView.ItemsSource.Count() - 1;
77+
handler.PlatformView.SelectedIndex = itemCount - 1;
7778
}
7879
else if (virtualView.SelectedIndex < 0)
7980
{

maui/src/Carousel/Handlers/CarouselHandler.iOS.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ private static void MapSelectedIndex(CarouselHandler handler, ICarousel virtualV
7474

7575
if (virtualView.ItemsSource != null)
7676
{
77-
if (virtualView.SelectedIndex >= virtualView.ItemsSource.Count() && virtualView.ItemsSource.Any())
77+
int itemCount = virtualView.ItemsSource.Count();
78+
if (virtualView.SelectedIndex >= itemCount && itemCount > 0)
7879
{
79-
handler.PlatformView.SelectedIndex = virtualView.ItemsSource.Count() - 1;
80+
handler.PlatformView.SelectedIndex = itemCount - 1;
8081
}
8182
else
8283
{

maui/src/Carousel/Platform/Android/PlatformCarousel.Android.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3480,9 +3480,10 @@ internal void UpdateSelectedIndex(ICarousel mauiView)
34803480
{
34813481
if (mauiView.ItemsSource != null)
34823482
{
3483-
if (mauiView.SelectedIndex >= mauiView.ItemsSource.Count() && mauiView.ItemsSource.Any())
3483+
int itemCount = mauiView.ItemsSource.Count();
3484+
if (mauiView.SelectedIndex >= itemCount && itemCount > 0)
34843485
{
3485-
SelectedIndex = mauiView.ItemsSource.Count() - 1;
3486+
SelectedIndex = itemCount - 1;
34863487
}
34873488
else if (mauiView.SelectedIndex < 0)
34883489
{

maui/src/Carousel/Platform/iOS/PlatformCarousel.iOS.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,12 @@ public bool IsEnabled
879879
void EnableOrDisableInteraction()
880880
{
881881
UserInteractionEnabled = IsInteractionEnable();
882-
Subviews.ToList().ForEach(subView => subView.UserInteractionEnabled = IsInteractionEnable());
882+
bool interactionEnabled = IsInteractionEnable();
883+
foreach (var subView in Subviews)
884+
{
885+
subView.UserInteractionEnabled = interactionEnabled;
886+
}
887+
883888
OnEnableInteractionPropertyChanged();
884889
}
885890

0 commit comments

Comments
 (0)