Skip to content

Commit 28922df

Browse files
Merge pull request #224 from syncfusion/LayoutIssue
Application got crash when load the PullToRefresh and Expander controls within different layouts.
2 parents 031c8fe + 693bcbe commit 28922df

File tree

7 files changed

+530
-35
lines changed

7 files changed

+530
-35
lines changed

maui/src/Accordion/AccordionItem.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,10 @@ public Color HeaderIconColor
317317
/// </summary>
318318
internal int _itemIndex { get; set; }
319319

320-
#endregion
321-
322-
#region Private Properties
323-
324320
/// <summary>
325321
/// Gets or sets the instance of the accordion.
326322
/// </summary>
327-
SfAccordion? _accordion { get; set; }
323+
internal SfAccordion? _accordion { get; set; }
328324

329325
#endregion
330326

@@ -462,7 +458,7 @@ static void OnIsExpandedPropertyChanged(BindableObject bindable, object oldValue
462458
// Content does not get collapsed when item is being collapsed in PCL view.
463459
if (bindable is AccordionItem accordionItem)
464460
{
465-
if (accordionItem._accordion != null && accordionItem._accordionItemView != null && accordionItem._accordionItemView.IsExpanded != accordionItem.IsExpanded)
461+
if (accordionItem._accordion != null && accordionItem._accordion.IsViewLoaded && accordionItem._accordionItemView != null && accordionItem._accordionItemView.IsExpanded != accordionItem.IsExpanded)
466462
{
467463
accordionItem.OnIsExpandedChanging((bool)newValue);
468464
}
@@ -479,7 +475,7 @@ static void OnIsExpandedPropertyChanged(BindableObject bindable, object oldValue
479475
/// <param name="newValue">The new value of header property. </param>
480476
static void OnHeaderPropertyChanged(BindableObject bindable, object oldValue, object newValue)
481477
{
482-
if (bindable is AccordionItem accordionItem && accordionItem._accordionItemView != null)
478+
if (bindable is AccordionItem accordionItem && accordionItem._accordion != null && accordionItem._accordion.IsViewLoaded && accordionItem._accordionItemView != null)
483479
{
484480
accordionItem._accordionItemView.Header = (View)newValue;
485481
}
@@ -494,18 +490,14 @@ static void OnHeaderPropertyChanged(BindableObject bindable, object oldValue, ob
494490
static void OnContentPropertyChanged(BindableObject bindable, object oldValue, object newValue)
495491
{
496492
// When the Content is changed at runtime, need to update its visibility based on IsExpanded property.
497-
var content = newValue as View;
498-
if (bindable is AccordionItem accordionItem)
493+
if (bindable is AccordionItem accordionItem && newValue is View content && accordionItem._accordion != null && accordionItem._accordion.IsViewLoaded)
499494
{
500-
if (content != null)
501-
{
502-
content.IsVisible = accordionItem.IsExpanded;
503-
}
504-
495+
content.IsVisible = accordionItem.IsExpanded;
505496
if (accordionItem._accordionItemView != null)
506497
{
507498
accordionItem._accordionItemView.Content = content;
508499
}
500+
509501
}
510502
}
511503

@@ -517,7 +509,7 @@ static void OnContentPropertyChanged(BindableObject bindable, object oldValue, o
517509
/// <param name="newValue">The new value of header background property. </param>
518510
static void OnHeaderBackgroundPropertyChanged(BindableObject bindable, object oldValue, object newValue)
519511
{
520-
if (bindable is AccordionItem accordionItem && accordionItem._accordionItemView != null)
512+
if (bindable is AccordionItem accordionItem && accordionItem._accordion != null && accordionItem._accordion.IsViewLoaded && accordionItem._accordionItemView != null)
521513
{
522514
accordionItem._accordionItemView.HeaderBackground = (Brush)newValue;
523515
}
@@ -531,7 +523,7 @@ static void OnHeaderBackgroundPropertyChanged(BindableObject bindable, object ol
531523
/// <param name="newValue">The new value of header icon color property. </param>
532524
static void OnHeaderIconColorPropertyChanged(BindableObject bindable, object oldValue, object newValue)
533525
{
534-
if (bindable is AccordionItem accordionItem && accordionItem._accordionItemView != null)
526+
if (bindable is AccordionItem accordionItem && accordionItem._accordion != null && accordionItem._accordion.IsViewLoaded && accordionItem._accordionItemView != null)
535527
{
536528
accordionItem._accordionItemView.HeaderIconColor = (Color)newValue;
537529
}

maui/src/Accordion/SfAccordion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,8 +992,8 @@ void OnAccordionLoaded(object? sender, System.EventArgs e)
992992
{
993993
if (!IsViewLoaded)
994994
{
995-
AddAccordionItemsIntoView();
996995
IsViewLoaded = true;
996+
AddAccordionItemsIntoView();
997997
}
998998
}
999999

maui/src/Expander/SfExpander.cs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,8 +1517,22 @@ protected override Size MeasureContent(double widthConstraint, double heightCons
15171517
}
15181518
}
15191519

1520+
double width = double.IsFinite(widthConstraint) ? widthConstraint : 0;
1521+
// To update width when loaded expander inside HorizontalStackLayout and AbsoluteLayout.
1522+
if (width == 0)
1523+
{
1524+
var scaledScreenSize =
1525+
#if WINDOWS
1526+
new Size(300, 300);
1527+
#else
1528+
new Size(DeviceDisplay.MainDisplayInfo.Width / DeviceDisplay.MainDisplayInfo.Density, DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density);
1529+
#endif
1530+
double scaledWidth = Math.Min(scaledScreenSize.Width, scaledScreenSize.Height);
1531+
width = scaledWidth;
1532+
}
1533+
15201534
_expanderHeight = _headerMeasuredSize.Height + _contentMeasuredSize.Height + (_headerMeasuredSize.Height > 0 ? Padding.Bottom : 0);
1521-
return new Size(widthConstraint, _expanderHeight);
1535+
return new Size(width, _expanderHeight);
15221536
}
15231537

15241538

@@ -1679,7 +1693,7 @@ static void OnHeaderPropertyChanged(BindableObject bindable, object oldValue, ob
16791693
var oldHeader = oldValue as View;
16801694

16811695
// When the Content is changed at runtime, need to update its visibility based on IsExpanded property.
1682-
if (bindable is SfExpander expander)
1696+
if (bindable is SfExpander expander && expander.IsViewLoaded)
16831697
{
16841698
expander.OnHeaderChanged(newHeader, oldHeader);
16851699
}
@@ -1694,7 +1708,7 @@ static void OnHeaderPropertyChanged(BindableObject bindable, object oldValue, ob
16941708
static void OnHeaderIconPositionPropertyChanged(BindableObject bindable, object oldValue, object newValue)
16951709
{
16961710
// When the Content is changed at runtime, need to update its visibility based on IsExpanded property.
1697-
if (bindable is SfExpander expander)
1711+
if (bindable is SfExpander expander && expander.IsViewLoaded)
16981712
{
16991713
expander.OnHeaderIconPositionChanged((ExpanderIconPosition)newValue, (ExpanderIconPosition)oldValue);
17001714
}
@@ -1749,7 +1763,7 @@ static void OnHeaderBackgroundPropertyChanged(BindableObject bindable, object ol
17491763
static void OnHeaderIconColorPropertyChanged(BindableObject bindable, object oldValue, object newValue)
17501764
{
17511765
// When the Content is changed at runtime, need to update its visibility based on IsExpanded property.
1752-
if (bindable is SfExpander expander)
1766+
if (bindable is SfExpander expander && expander.IsViewLoaded)
17531767
{
17541768
expander.OnIconColorChanged((Color)oldValue, (Color)newValue);
17551769
}
@@ -1764,15 +1778,17 @@ static void OnHeaderIconColorPropertyChanged(BindableObject bindable, object old
17641778
private static void OnAnimationDurationPropertyChanged(BindableObject bindable, object oldValue, object newValue)
17651779
{
17661780
var expander = bindable as SfExpander;
1767-
if (expander != null && (double)newValue == 0 && expander._expanderAnimation != null)
1781+
if (expander != null && (double)newValue == 0 && expander._expanderAnimation != null && expander.IsViewLoaded)
17681782
{
17691783
var animation = expander._expanderAnimation;
1770-
if(animation.AnimationManager != null)
1771-
// While setting Animation Duration as 0, the animation won't be stopped. So, removing it.
1772-
// Since we are removing the animation, AnimationCompleted was not getting call. So, manually calling it.
1773-
animation.AnimationManager.Remove(animation);
1774-
expander.AnimationCompleted();
1775-
expander.InvalidateForceLayout();
1784+
if (animation.AnimationManager != null)
1785+
{
1786+
// While setting Animation Duration as 0, the animation won't be stopped. So, removing it.
1787+
// Since we are removing the animation, AnimationCompleted was not getting call. So, manually calling it.
1788+
animation.AnimationManager.Remove(animation);
1789+
expander.AnimationCompleted();
1790+
expander.InvalidateForceLayout();
1791+
}
17761792
}
17771793
}
17781794

maui/src/PullToRefresh/SfPullToRefresh.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,13 @@ public SfPullToRefresh()
360360
Children.Add(_progressCircleView);
361361
ClipToBounds = true;
362362
ThemeElement.InitializeThemeResources(this, "SfPullToRefreshTheme");
363+
364+
// Ensures the refreshing animation starts if IsRefreshing was set via global styles.
365+
if (this.IsRefreshing && !this.ActualIsRefreshing)
366+
{
367+
this.StartRefreshing();
368+
}
369+
363370
this.IsLayoutControl = true;
364371
}
365372

@@ -1869,8 +1876,27 @@ protected override Size MeasureContent(double widthConstraint, double heightCons
18691876
(PullableContent as IView).Measure(widthConstraint, heightConstraint);
18701877
}
18711878

1872-
MeasureSfProgressCircleView(widthConstraint, heightConstraint);
1873-
_previousMeasuredSize = new Size(widthConstraint, heightConstraint);
1879+
double width = double.IsFinite(widthConstraint) ? widthConstraint : 0;
1880+
double height = double.IsFinite(heightConstraint) ? heightConstraint : 0;
1881+
double screenWidth = 300;
1882+
double screenHeight = 300;
1883+
#if !WINDOWS
1884+
screenWidth = DeviceDisplay.MainDisplayInfo.Width / DeviceDisplay.MainDisplayInfo.Density;
1885+
screenHeight = DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density;
1886+
width = screenWidth;
1887+
height = screenHeight;
1888+
#else
1889+
if (width == 0)
1890+
{
1891+
width = screenWidth;
1892+
}
1893+
if (height == 0)
1894+
{
1895+
height = screenHeight;
1896+
}
1897+
#endif
1898+
MeasureSfProgressCircleView(width, height);
1899+
_previousMeasuredSize = new Size(width, height);
18741900
}
18751901

18761902
return _previousMeasuredSize;
@@ -2057,7 +2083,7 @@ static void OnRefreshingViewTemplatePropertyChanged(BindableObject bindable, obj
20572083
static void OnRefreshViewHeightChanged(BindableObject bindable, object oldValue, object newValue)
20582084
{
20592085
SfPullToRefresh? pullToRefresh = bindable as SfPullToRefresh;
2060-
if (pullToRefresh is not null)
2086+
if (pullToRefresh is not null && pullToRefresh.ProgressCircleView is not null)
20612087
{
20622088
pullToRefresh.ProgressCircleView.UpdateDrawProperties();
20632089
if ((pullToRefresh.IsPulling || pullToRefresh.ActualIsRefreshing) && pullToRefresh.ProgressCircleView.Content is null)
@@ -2078,7 +2104,7 @@ static void OnRefreshViewHeightChanged(BindableObject bindable, object oldValue,
20782104
static void OnRefreshViewWidthChanged(BindableObject bindable, object oldValue, object newValue)
20792105
{
20802106
SfPullToRefresh? pullToRefresh = bindable as SfPullToRefresh;
2081-
if (pullToRefresh is not null)
2107+
if (pullToRefresh is not null && pullToRefresh.ProgressCircleView is not null)
20822108
{
20832109
pullToRefresh.ProgressCircleView.UpdateDrawProperties();
20842110
if ((pullToRefresh.IsPulling || pullToRefresh.ActualIsRefreshing) && pullToRefresh.ProgressCircleView.Content is null)

0 commit comments

Comments
 (0)