Skip to content

Commit aeab265

Browse files
Merge pull request #39 from BrundhaVelusamy/main
Resolved the Content Resize Issue in MAUI TabView When Output Window is Resized.
2 parents 7069fc6 + 4ae06f7 commit aeab265

File tree

2 files changed

+63
-13
lines changed

2 files changed

+63
-13
lines changed

maui/src/TabView/Control/HorizontalContent/SfHorizontalContent.cs

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ internal partial class SfHorizontalContent : SfTabViewExt, ITouchListener, ITapG
3535
bool _isPreviousItemVisible;
3636
bool _isNextItemVisible;
3737
SelectionChangingEventArgs? _selectionChangingEventArgs;
38+
bool _isSelectionProcessed;
3839
#if WINDOWS
3940
bool _isItemRemoved;
4041
#endif
@@ -246,16 +247,14 @@ protected override Microsoft.Maui.Graphics.Size ArrangeContent(Microsoft.Maui.Gr
246247
/// <returns>It returns the size</returns>
247248
protected override Size MeasureContent(double widthConstraint, double heightConstraint)
248249
{
249-
if (widthConstraint > 0 && widthConstraint != double.PositiveInfinity && MinimumWidthRequest != widthConstraint)
250+
if (widthConstraint > 0 && widthConstraint != double.PositiveInfinity)
250251
{
251-
MinimumWidthRequest = widthConstraint;
252252
ContentWidth = widthConstraint;
253253
UpdateTabItemContentSize();
254254
UpdateTabItemContentPosition();
255255
}
256-
if (heightConstraint > 0 && heightConstraint != double.PositiveInfinity && MinimumHeightRequest != heightConstraint)
256+
if (heightConstraint > 0 && heightConstraint != double.PositiveInfinity)
257257
{
258-
MinimumHeightRequest = heightConstraint;
259258
UpdateTabItemContentSize();
260259
UpdateTabItemContentPosition();
261260
}
@@ -373,6 +372,7 @@ void ClearTabContent(SfTabItem tabItem, int index)
373372

374373
void UpdateSelectedIndex()
375374
{
375+
_isSelectionProcessed = true;
376376
UpdateTabItemContentPosition();
377377
}
378378

@@ -576,12 +576,30 @@ void UpdateTabItemContentPositionWithTemplate()
576576
{
577577
xPosition = ContentWidth * SelectedIndex;
578578
#if WINDOWS
579-
_horizontalStackLayout?.TranslateTo(-xPosition, 0, (uint)ContentTransitionDuration, Easing.Linear);
580-
#else
581-
if (((this as IVisualElementController).EffectiveFlowDirection & EffectiveFlowDirection.RightToLeft) != EffectiveFlowDirection.RightToLeft)
579+
if (_isSelectionProcessed)
580+
{
582581
_horizontalStackLayout?.TranslateTo(-xPosition, 0, (uint)ContentTransitionDuration, Easing.Linear);
582+
_isSelectionProcessed = false;
583+
}
583584
else
584-
_horizontalStackLayout?.TranslateTo(xPosition, 0, (uint)ContentTransitionDuration, Easing.Linear);
585+
{
586+
if (_horizontalStackLayout is not null)
587+
{
588+
_horizontalStackLayout.TranslationX = -xPosition;
589+
}
590+
}
591+
#else
592+
double targetX = ((this as IVisualElementController).EffectiveFlowDirection & EffectiveFlowDirection.RightToLeft) is not EffectiveFlowDirection.RightToLeft ? -xPosition : xPosition;
593+
if (_isSelectionProcessed)
594+
{
595+
_horizontalStackLayout?.TranslateTo(targetX, 0, (uint)ContentTransitionDuration, Easing.Linear);
596+
_isSelectionProcessed = false;
597+
}
598+
else
599+
{
600+
if (_horizontalStackLayout is not null)
601+
_horizontalStackLayout.TranslationX = targetX;
602+
}
585603
#endif
586604
}
587605
}
@@ -601,13 +619,31 @@ void UpdateTabItemContentPositionWithoutTemplate()
601619
}
602620
else
603621
{
604-
_horizontalStackLayout?.TranslateTo(-xPosition, 0, (uint)ContentTransitionDuration, Easing.Linear);
622+
if (_isSelectionProcessed)
623+
{
624+
_horizontalStackLayout?.TranslateTo(-xPosition, 0, (uint)ContentTransitionDuration, Easing.Linear);
625+
_isSelectionProcessed = false;
626+
}
627+
else
628+
{
629+
if (_horizontalStackLayout is not null)
630+
{
631+
_horizontalStackLayout.TranslationX = -xPosition;
632+
}
633+
}
605634
}
606635
#else
607-
if (((this as IVisualElementController).EffectiveFlowDirection & EffectiveFlowDirection.RightToLeft) != EffectiveFlowDirection.RightToLeft)
608-
_horizontalStackLayout?.TranslateTo(-xPosition, 0, (uint)ContentTransitionDuration, Easing.Linear);
636+
double targetX = ((this as IVisualElementController).EffectiveFlowDirection & EffectiveFlowDirection.RightToLeft) is not EffectiveFlowDirection.RightToLeft ? -xPosition : xPosition;
637+
if (_isSelectionProcessed)
638+
{
639+
_horizontalStackLayout?.TranslateTo(targetX, 0, (uint)ContentTransitionDuration, Easing.Linear);
640+
_isSelectionProcessed = false;
641+
}
609642
else
610-
_horizontalStackLayout?.TranslateTo(xPosition, 0, (uint)ContentTransitionDuration, Easing.Linear);
643+
{
644+
if (_horizontalStackLayout is not null)
645+
_horizontalStackLayout.TranslationX = targetX;
646+
}
611647
#endif
612648
}
613649

maui/src/TabView/Control/SfTabBar.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ internal class SfTabBar : SfStackLayout, ITapGestureListener
3939
readonly double _arrowButtonSize = 32;
4040
double _removedItemWidth = 0;
4141
bool _itemRemoved = false;
42+
bool _isSelectionProcessed;
4243

4344
// State-tracking fields
4445

@@ -719,6 +720,7 @@ internal void UpdateSelectedIndex(int newIndex, int oldIndex)
719720
{
720721
if (newIndex != -1)
721722
{
723+
_isSelectionProcessed = true;
722724
UpdateSelectedTabItemIsSelected(newIndex, oldIndex);
723725
UpdateTabIndicatorWidth();
724726
if (_tabSelectionChangedEventArgs != null)
@@ -2308,6 +2310,7 @@ void AnimateTabSelectionIndicator(Animation parentAnimation, uint animationDurat
23082310

23092311
_previousIndicatorWidth = _currentIndicatorWidth;
23102312
});
2313+
_isSelectionProcessed = false;
23112314
}
23122315
else
23132316
{
@@ -2326,7 +2329,18 @@ void AnimateTabSelectionIndicator(Animation parentAnimation, uint animationDurat
23262329
}
23272330
else
23282331
{
2329-
_tabSelectionIndicator.TranslateTo(targetX, 0, animationDuration, Easing.Linear);
2332+
if (_isSelectionProcessed)
2333+
{
2334+
_tabSelectionIndicator.TranslateTo(targetX, 0, animationDuration, Easing.Linear);
2335+
_isSelectionProcessed = false;
2336+
}
2337+
else
2338+
{
2339+
if (_tabSelectionIndicator is not null)
2340+
{
2341+
_tabSelectionIndicator.TranslationX = targetX;
2342+
}
2343+
}
23302344
}
23312345
UpdateFillSelectedTabItem();
23322346
UpdateScrollViewPosition(SelectedIndex);

0 commit comments

Comments
 (0)