Skip to content

Application got crash when load the PullToRefresh and Expander controls within different layouts. #224

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions maui/src/Accordion/AccordionItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,10 @@ public Color HeaderIconColor
/// </summary>
internal int _itemIndex { get; set; }

#endregion

#region Private Properties

/// <summary>
/// Gets or sets the instance of the accordion.
/// </summary>
SfAccordion? _accordion { get; set; }
internal SfAccordion? _accordion { get; set; }

#endregion

Expand Down Expand Up @@ -462,7 +458,7 @@ static void OnIsExpandedPropertyChanged(BindableObject bindable, object oldValue
// Content does not get collapsed when item is being collapsed in PCL view.
if (bindable is AccordionItem accordionItem)
{
if (accordionItem._accordion != null && accordionItem._accordionItemView != null && accordionItem._accordionItemView.IsExpanded != accordionItem.IsExpanded)
if (accordionItem._accordion != null && accordionItem._accordion.IsViewLoaded && accordionItem._accordionItemView != null && accordionItem._accordionItemView.IsExpanded != accordionItem.IsExpanded)
{
accordionItem.OnIsExpandedChanging((bool)newValue);
}
Expand All @@ -479,7 +475,7 @@ static void OnIsExpandedPropertyChanged(BindableObject bindable, object oldValue
/// <param name="newValue">The new value of header property. </param>
static void OnHeaderPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is AccordionItem accordionItem && accordionItem._accordionItemView != null)
if (bindable is AccordionItem accordionItem && accordionItem._accordion != null && accordionItem._accordion.IsViewLoaded && accordionItem._accordionItemView != null)
{
accordionItem._accordionItemView.Header = (View)newValue;
}
Expand All @@ -494,18 +490,14 @@ static void OnHeaderPropertyChanged(BindableObject bindable, object oldValue, ob
static void OnContentPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
// When the Content is changed at runtime, need to update its visibility based on IsExpanded property.
var content = newValue as View;
if (bindable is AccordionItem accordionItem)
if (bindable is AccordionItem accordionItem && newValue is View content && accordionItem._accordion != null && accordionItem._accordion.IsViewLoaded)
{
if (content != null)
{
content.IsVisible = accordionItem.IsExpanded;
}

content.IsVisible = accordionItem.IsExpanded;
if (accordionItem._accordionItemView != null)
{
accordionItem._accordionItemView.Content = content;
}

}
}

Expand All @@ -517,7 +509,7 @@ static void OnContentPropertyChanged(BindableObject bindable, object oldValue, o
/// <param name="newValue">The new value of header background property. </param>
static void OnHeaderBackgroundPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is AccordionItem accordionItem && accordionItem._accordionItemView != null)
if (bindable is AccordionItem accordionItem && accordionItem._accordion != null && accordionItem._accordion.IsViewLoaded && accordionItem._accordionItemView != null)
{
accordionItem._accordionItemView.HeaderBackground = (Brush)newValue;
}
Expand All @@ -531,7 +523,7 @@ static void OnHeaderBackgroundPropertyChanged(BindableObject bindable, object ol
/// <param name="newValue">The new value of header icon color property. </param>
static void OnHeaderIconColorPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is AccordionItem accordionItem && accordionItem._accordionItemView != null)
if (bindable is AccordionItem accordionItem && accordionItem._accordion != null && accordionItem._accordion.IsViewLoaded && accordionItem._accordionItemView != null)
{
accordionItem._accordionItemView.HeaderIconColor = (Color)newValue;
}
Expand Down
2 changes: 1 addition & 1 deletion maui/src/Accordion/SfAccordion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -992,8 +992,8 @@ void OnAccordionLoaded(object? sender, System.EventArgs e)
{
if (!IsViewLoaded)
{
AddAccordionItemsIntoView();
IsViewLoaded = true;
AddAccordionItemsIntoView();
}
}

Expand Down
37 changes: 26 additions & 11 deletions maui/src/Expander/SfExpander.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1517,8 +1517,21 @@ protected override Size MeasureContent(double widthConstraint, double heightCons
}
}

double width = double.IsFinite(widthConstraint) ? widthConstraint : 0;
// To update width when loaded expander inside HorizontalStackLayout and AbsoluteLayout.
if (width == 0)
{
#if !WINDOWS
var scaledScreenSize = new Size(DeviceDisplay.MainDisplayInfo.Width / DeviceDisplay.MainDisplayInfo.Density, DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density);
#else
var scaledScreenSize = new Size(300, 300);
#endif
double scaledWidth = Math.Min(scaledScreenSize.Width, scaledScreenSize.Height);
width = scaledWidth;
}

_expanderHeight = _headerMeasuredSize.Height + _contentMeasuredSize.Height + (_headerMeasuredSize.Height > 0 ? Padding.Bottom : 0);
return new Size(widthConstraint, _expanderHeight);
return new Size(width, _expanderHeight);
}


Expand Down Expand Up @@ -1679,7 +1692,7 @@ static void OnHeaderPropertyChanged(BindableObject bindable, object oldValue, ob
var oldHeader = oldValue as View;

// When the Content is changed at runtime, need to update its visibility based on IsExpanded property.
if (bindable is SfExpander expander)
if (bindable is SfExpander expander && expander.IsViewLoaded)
{
expander.OnHeaderChanged(newHeader, oldHeader);
}
Expand All @@ -1694,7 +1707,7 @@ static void OnHeaderPropertyChanged(BindableObject bindable, object oldValue, ob
static void OnHeaderIconPositionPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
// When the Content is changed at runtime, need to update its visibility based on IsExpanded property.
if (bindable is SfExpander expander)
if (bindable is SfExpander expander && expander.IsViewLoaded)
{
expander.OnHeaderIconPositionChanged((ExpanderIconPosition)newValue, (ExpanderIconPosition)oldValue);
}
Expand Down Expand Up @@ -1749,7 +1762,7 @@ static void OnHeaderBackgroundPropertyChanged(BindableObject bindable, object ol
static void OnHeaderIconColorPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
// When the Content is changed at runtime, need to update its visibility based on IsExpanded property.
if (bindable is SfExpander expander)
if (bindable is SfExpander expander && expander.IsViewLoaded)
{
expander.OnIconColorChanged((Color)oldValue, (Color)newValue);
}
Expand All @@ -1764,15 +1777,17 @@ static void OnHeaderIconColorPropertyChanged(BindableObject bindable, object old
private static void OnAnimationDurationPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
var expander = bindable as SfExpander;
if (expander != null && (double)newValue == 0 && expander._expanderAnimation != null)
if (expander != null && (double)newValue == 0 && expander._expanderAnimation != null && expander.IsViewLoaded)
{
var animation = expander._expanderAnimation;
if(animation.AnimationManager != null)
// While setting Animation Duration as 0, the animation won't be stopped. So, removing it.
// Since we are removing the animation, AnimationCompleted was not getting call. So, manually calling it.
animation.AnimationManager.Remove(animation);
expander.AnimationCompleted();
expander.InvalidateForceLayout();
if (animation.AnimationManager != null)
{
// While setting Animation Duration as 0, the animation won't be stopped. So, removing it.
// Since we are removing the animation, AnimationCompleted was not getting call. So, manually calling it.
animation.AnimationManager.Remove(animation);
expander.AnimationCompleted();
expander.InvalidateForceLayout();
}
}
}

Expand Down
34 changes: 30 additions & 4 deletions maui/src/PullToRefresh/SfPullToRefresh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,13 @@ public SfPullToRefresh()
Children.Add(_progressCircleView);
ClipToBounds = true;
ThemeElement.InitializeThemeResources(this, "SfPullToRefreshTheme");

// Ensures the refreshing animation starts if IsRefreshing was set via global styles.
if (this.IsRefreshing && !this.ActualIsRefreshing)
{
this.StartRefreshing();
}

this.IsLayoutControl = true;
}

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

MeasureSfProgressCircleView(widthConstraint, heightConstraint);
_previousMeasuredSize = new Size(widthConstraint, heightConstraint);
double width = double.IsFinite(widthConstraint) ? widthConstraint : 0;
double height = double.IsFinite(heightConstraint) ? heightConstraint : 0;
double screenWidth = 300;
double screenHeight = 300;
#if !WINDOWS
screenWidth = DeviceDisplay.MainDisplayInfo.Width / DeviceDisplay.MainDisplayInfo.Density;
screenHeight = DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density;
width = screenWidth;
height = screenHeight;
#else
if (width == 0)
{
width = screenWidth;
}
if (height == 0)
{
height = screenHeight;
}
#endif
MeasureSfProgressCircleView(width, height);
_previousMeasuredSize = new Size(width, height);
}

return _previousMeasuredSize;
Expand Down Expand Up @@ -2057,7 +2083,7 @@ static void OnRefreshingViewTemplatePropertyChanged(BindableObject bindable, obj
static void OnRefreshViewHeightChanged(BindableObject bindable, object oldValue, object newValue)
{
SfPullToRefresh? pullToRefresh = bindable as SfPullToRefresh;
if (pullToRefresh is not null)
if (pullToRefresh is not null && pullToRefresh.ProgressCircleView is not null)
{
pullToRefresh.ProgressCircleView.UpdateDrawProperties();
if ((pullToRefresh.IsPulling || pullToRefresh.ActualIsRefreshing) && pullToRefresh.ProgressCircleView.Content is null)
Expand All @@ -2078,7 +2104,7 @@ static void OnRefreshViewHeightChanged(BindableObject bindable, object oldValue,
static void OnRefreshViewWidthChanged(BindableObject bindable, object oldValue, object newValue)
{
SfPullToRefresh? pullToRefresh = bindable as SfPullToRefresh;
if (pullToRefresh is not null)
if (pullToRefresh is not null && pullToRefresh.ProgressCircleView is not null)
{
pullToRefresh.ProgressCircleView.UpdateDrawProperties();
if ((pullToRefresh.IsPulling || pullToRefresh.ActualIsRefreshing) && pullToRefresh.ProgressCircleView.Content is null)
Expand Down
Loading