Skip to content

Commit 89c4743

Browse files
committed
Layout and GlobalStyle Fix
1 parent 2d34815 commit 89c4743

File tree

3 files changed

+61
-24
lines changed

3 files changed

+61
-24
lines changed

maui/src/Accordion/AccordionItem.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ static void OnIsExpandedPropertyChanged(BindableObject bindable, object oldValue
467467
accordionItem.Content.IsVisible = true;
468468
}
469469

470-
if (accordionItem._accordion != null && accordionItem._accordionItemView != null && accordionItem._accordionItemView.IsExpanded != accordionItem.IsExpanded)
470+
if (accordionItem._accordion != null && accordionItem.accordion.IsViewLoaded && accordionItem._accordionItemView != null && accordionItem._accordionItemView.IsExpanded != accordionItem.IsExpanded)
471471
{
472472
accordionItem.OnIsExpandedChanging((bool)newValue);
473473
}
@@ -484,7 +484,7 @@ static void OnIsExpandedPropertyChanged(BindableObject bindable, object oldValue
484484
/// <param name="newValue">The new value of header property. </param>
485485
static void OnHeaderPropertyChanged(BindableObject bindable, object oldValue, object newValue)
486486
{
487-
if (bindable is AccordionItem accordionItem && accordionItem._accordionItemView != null)
487+
if (bindable is AccordionItem accordionItem && accordionItem._accordion != null && accordionItem._accordion.IsViewLoaded && accordionItem._accordionItemView != null)
488488
{
489489
accordionItem._accordionItemView.Header = (View)newValue;
490490
}
@@ -502,14 +502,17 @@ static void OnContentPropertyChanged(BindableObject bindable, object oldValue, o
502502
var content = newValue as View;
503503
if (bindable is AccordionItem accordionItem)
504504
{
505-
if (content != null)
505+
if (accordionItem._accordion != null && accordionItem._accordion.IsViewLoaded)
506506
{
507-
content.IsVisible = accordionItem.IsExpanded;
508-
}
507+
if (content != null)
508+
{
509+
content.IsVisible = accordionItem.IsExpanded;
510+
}
509511

510-
if (accordionItem._accordionItemView != null)
511-
{
512-
accordionItem._accordionItemView.Content = content;
512+
if (accordionItem._accordionItemView != null)
513+
{
514+
accordionItem._accordionItemView.Content = content;
515+
}
513516
}
514517
}
515518
}
@@ -522,7 +525,7 @@ static void OnContentPropertyChanged(BindableObject bindable, object oldValue, o
522525
/// <param name="newValue">The new value of header background property. </param>
523526
static void OnHeaderBackgroundPropertyChanged(BindableObject bindable, object oldValue, object newValue)
524527
{
525-
if (bindable is AccordionItem accordionItem && accordionItem._accordionItemView != null)
528+
if (bindable is AccordionItem accordionItem && accordionItem._accordion != null && accordionItem._accordion.IsViewLoaded && accordionItem._accordionItemView != null)
526529
{
527530
accordionItem._accordionItemView.HeaderBackground = (Brush)newValue;
528531
}
@@ -536,7 +539,7 @@ static void OnHeaderBackgroundPropertyChanged(BindableObject bindable, object ol
536539
/// <param name="newValue">The new value of header icon color property. </param>
537540
static void OnHeaderIconColorPropertyChanged(BindableObject bindable, object oldValue, object newValue)
538541
{
539-
if (bindable is AccordionItem accordionItem && accordionItem._accordionItemView != null)
542+
if (bindable is AccordionItem accordionItem && accordionItem._accordion != null && accordionItem._accordion.IsViewLoaded && accordionItem._accordionItemView != null)
540543
{
541544
accordionItem._accordionItemView.HeaderIconColor = (Color)newValue;
542545
}

maui/src/Expander/SfExpander.cs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,8 +1517,21 @@ 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+
#if !WINDOWS
1525+
var scaledScreenSize = new Size(DeviceDisplay.MainDisplayInfo.Width / DeviceDisplay.MainDisplayInfo.Density, DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density);
1526+
#else
1527+
var scaledScreenSize = new Size(300, 300);
1528+
#endif
1529+
double scaledWidth = Math.Min(scaledScreenSize.Width, scaledScreenSize.Height);
1530+
width = scaledWidth;
1531+
}
1532+
15201533
_expanderHeight = _headerMeasuredSize.Height + _contentMeasuredSize.Height + (_headerMeasuredSize.Height > 0 ? Padding.Bottom : 0);
1521-
return new Size(widthConstraint, _expanderHeight);
1534+
return new Size(width, _expanderHeight);
15221535
}
15231536

15241537

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

16811694
// When the Content is changed at runtime, need to update its visibility based on IsExpanded property.
1682-
if (bindable is SfExpander expander)
1695+
if (bindable is SfExpander expander && expander.IsViewLoaded)
16831696
{
16841697
expander.OnHeaderChanged(newHeader, oldHeader);
16851698
}
@@ -1694,7 +1707,7 @@ static void OnHeaderPropertyChanged(BindableObject bindable, object oldValue, ob
16941707
static void OnHeaderIconPositionPropertyChanged(BindableObject bindable, object oldValue, object newValue)
16951708
{
16961709
// When the Content is changed at runtime, need to update its visibility based on IsExpanded property.
1697-
if (bindable is SfExpander expander)
1710+
if (bindable is SfExpander expander && expander.IsViewLoaded)
16981711
{
16991712
expander.OnHeaderIconPositionChanged((ExpanderIconPosition)newValue, (ExpanderIconPosition)oldValue);
17001713
}
@@ -1749,7 +1762,7 @@ static void OnHeaderBackgroundPropertyChanged(BindableObject bindable, object ol
17491762
static void OnHeaderIconColorPropertyChanged(BindableObject bindable, object oldValue, object newValue)
17501763
{
17511764
// When the Content is changed at runtime, need to update its visibility based on IsExpanded property.
1752-
if (bindable is SfExpander expander)
1765+
if (bindable is SfExpander expander && expander.IsViewLoaded)
17531766
{
17541767
expander.OnIconColorChanged((Color)oldValue, (Color)newValue);
17551768
}
@@ -1767,12 +1780,14 @@ private static void OnAnimationDurationPropertyChanged(BindableObject bindable,
17671780
if (expander != null && (double)newValue == 0 && expander._expanderAnimation != null)
17681781
{
17691782
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();
1783+
if (animation.AnimationManager != null)
1784+
{
1785+
// While setting Animation Duration as 0, the animation won't be stopped. So, removing it.
1786+
// Since we are removing the animation, AnimationCompleted was not getting call. So, manually calling it.
1787+
animation.AnimationManager.Remove(animation);
1788+
expander.AnimationCompleted();
1789+
expander.InvalidateForceLayout();
1790+
}
17761791
}
17771792
}
17781793

maui/src/PullToRefresh/SfPullToRefresh.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,8 +1869,27 @@ protected override Size MeasureContent(double widthConstraint, double heightCons
18691869
(PullableContent as IView).Measure(widthConstraint, heightConstraint);
18701870
}
18711871

1872-
MeasureSfProgressCircleView(widthConstraint, heightConstraint);
1873-
_previousMeasuredSize = new Size(widthConstraint, heightConstraint);
1872+
double width = double.IsFinite(widthConstraint) ? widthConstraint : 0;
1873+
double height = double.IsFinite(heightConstraint) ? heightConstraint : 0;
1874+
double screenWidth = 300;
1875+
double screenHeight = 300;
1876+
#if !WINDOWS
1877+
screenWidth = DeviceDisplay.MainDisplayInfo.Width / DeviceDisplay.MainDisplayInfo.Density;
1878+
screenHeight = DeviceDisplay.MainDisplayInfo.Height / DeviceDisplay.MainDisplayInfo.Density;
1879+
width = screenWidth;
1880+
height = screenHeight;
1881+
#else
1882+
if (width == 0)
1883+
{
1884+
width = screenWidth;
1885+
}
1886+
if (height == 0)
1887+
{
1888+
height = screenHeight;
1889+
}
1890+
#endif
1891+
MeasureSfProgressCircleView(width, height);
1892+
_previousMeasuredSize = new Size(width, height);
18741893
}
18751894

18761895
return _previousMeasuredSize;
@@ -2057,7 +2076,7 @@ static void OnRefreshingViewTemplatePropertyChanged(BindableObject bindable, obj
20572076
static void OnRefreshViewHeightChanged(BindableObject bindable, object oldValue, object newValue)
20582077
{
20592078
SfPullToRefresh? pullToRefresh = bindable as SfPullToRefresh;
2060-
if (pullToRefresh is not null)
2079+
if (pullToRefresh is not null && pullToRefresh.ProgressCircleView is not null)
20612080
{
20622081
pullToRefresh.ProgressCircleView.UpdateDrawProperties();
20632082
if ((pullToRefresh.IsPulling || pullToRefresh.ActualIsRefreshing) && pullToRefresh.ProgressCircleView.Content is null)
@@ -2078,7 +2097,7 @@ static void OnRefreshViewHeightChanged(BindableObject bindable, object oldValue,
20782097
static void OnRefreshViewWidthChanged(BindableObject bindable, object oldValue, object newValue)
20792098
{
20802099
SfPullToRefresh? pullToRefresh = bindable as SfPullToRefresh;
2081-
if (pullToRefresh is not null)
2100+
if (pullToRefresh is not null && pullToRefresh.ProgressCircleView is not null)
20822101
{
20832102
pullToRefresh.ProgressCircleView.UpdateDrawProperties();
20842103
if ((pullToRefresh.IsPulling || pullToRefresh.ActualIsRefreshing) && pullToRefresh.ProgressCircleView.Content is null)

0 commit comments

Comments
 (0)