Skip to content

Commit 4327242

Browse files
committed
Add RTL fix changes
1 parent c794f89 commit 4327242

File tree

4 files changed

+129
-8
lines changed

4 files changed

+129
-8
lines changed

maui/src/Calendar/CalendarVerticalStackLayout.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ internal CalendarVerticalStackLayout(double headerHeight, bool showFooterLayout,
4343
_headerHeight = headerHeight;
4444
_footerHeight = footerHeight;
4545
_showFooterLayout = showFooterLayout;
46-
//// TODO: In windows, child layouts get the parent flow direction hence while arranging child elements the framework automatically reverses the direction.
46+
//// TODO: Child layouts get the parent flow direction hence while arranging child elements the framework automatically reverses the direction.
4747
//// In other platforms, child elements' flow direction is not set and always has left flow direction so we have to manually arrange child elements.
48-
//// In the Windows platform, the draw view is still needed to configure manually and not take the parent direction.
48+
//// The draw view is still needed to configure manually and not take the parent direction.
4949
//// Due to this inconsistent behavior in windows, set flow direction to LTR for the inner layout of the calendar, so we manually arrange and draw child elements for all the platforms as common.
50-
//// In the Windows platform, the draw view does not arrange based on the flow direction. https://github.com/dotnet/maui/issues/6978
50+
//// The draw view does not arrange based on the flow direction. https://github.com/dotnet/maui/issues/6978
5151
FlowDirection = Microsoft.Maui.FlowDirection.LeftToRight;
5252
}
5353

maui/src/Calendar/Model/SfCalendar.cs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,22 @@ public partial class SfCalendar
562562
defaultValueCreator: bindable => null,
563563
propertyChanged: OnMonthViewHeaderTemplateChanged);
564564

565+
#if WINDOWS
566+
/// <summary>
567+
/// Identifies the <see cref="FlowDirectionProperty"/> dependency property.
568+
/// </summary>
569+
/// <value>
570+
/// The identifier for <see cref="FlowDirectionProperty"/> dependency property.
571+
/// </value>
572+
public static readonly new BindableProperty FlowDirectionProperty =
573+
BindableProperty.Create(
574+
nameof(FlowDirection),
575+
typeof(FlowDirection),
576+
typeof(SfCalendar),
577+
FlowDirection.LeftToRight,
578+
propertyChanged: OnFlowDirectionChanged);
579+
#endif
580+
565581
#endregion
566582

567583
#region Internal Bindable Properties
@@ -2101,6 +2117,20 @@ public DataTemplate MonthViewHeaderTemplate
21012117
set { SetValue(MonthViewHeaderTemplateProperty, value); }
21022118
}
21032119

2120+
//// TODO: Workaround for RTL (Right-to-Left) layout issue - The coordinate points are not calculated correctly in RTL layouts,
2121+
//// causing incorrect positioning. This flag helps to apply RTL-specific adjustments.
2122+
#if WINDOWS
2123+
/// <summary>
2124+
/// Gets or sets the flow direction for month view.
2125+
/// </summary>
2126+
/// <value> The default value of <see cref="SfCalendar.FlowDirection"/> is <see cref="FlowDirection.LeftToRight"/>.</value>
2127+
public new FlowDirection FlowDirection
2128+
{
2129+
get { return (FlowDirection)GetValue(FlowDirectionProperty); }
2130+
set { SetValue(FlowDirectionProperty, value); }
2131+
}
2132+
#endif
2133+
21042134
#endregion
21052135

21062136
#region Internal Properties
@@ -2286,6 +2316,36 @@ protected override void OnBindingContextChanged()
22862316
}
22872317
}
22882318

2319+
/// <summary>
2320+
/// Triggers when the calendar property changed.
2321+
/// </summary>
2322+
/// <param name="propertyName">The property name.</param>
2323+
protected override void OnPropertyChanged(string? propertyName = null)
2324+
{
2325+
if (propertyName == "FlowDirection")
2326+
{
2327+
if (FlowDirection == FlowDirection.RightToLeft)
2328+
{
2329+
if (Identifier == CalendarIdentifier.Korean || Identifier == CalendarIdentifier.Taiwan || Identifier == CalendarIdentifier.ThaiBuddhist)
2330+
{
2331+
_isRTLLayout = false;
2332+
}
2333+
else
2334+
{
2335+
_isRTLLayout = true;
2336+
}
2337+
}
2338+
else if (FlowDirection == FlowDirection.LeftToRight || FlowDirection == FlowDirection.MatchParent)
2339+
{
2340+
_isRTLLayout = this.IsRTL(Identifier);
2341+
UpdateFlowDirection();
2342+
_customScrollLayout?.UpdateVisibleDateOnView();
2343+
}
2344+
}
2345+
2346+
base.OnPropertyChanged(propertyName);
2347+
}
2348+
22892349
#endregion
22902350

22912351
#region Property Changed Methods
@@ -3077,6 +3137,7 @@ static void OnCalendarIdentifierChanged(BindableObject bindable, object oldValue
30773137
SfCalendar? calendar = bindable as SfCalendar;
30783138
if (calendar == null || calendar._customScrollLayout == null)
30793139
{
3140+
calendar?.UpdateLayoutFlowDirection();
30803141
return;
30813142
}
30823143

@@ -3173,6 +3234,27 @@ static void OnMonthViewHeaderTemplateChanged(BindableObject bindable, object old
31733234
calendar._monthViewHeader?.CreateViewHeaderTemplate();
31743235
}
31753236

3237+
#if WINDOWS
3238+
/// <summary>
3239+
/// Method invoke when flow direction property changed.
3240+
/// </summary>
3241+
/// <param name="bindable">The flow direction object.</param>
3242+
/// <param name="oldValue">The old value.</param>
3243+
/// <param name="newValue">The new value.</param>
3244+
static void OnFlowDirectionChanged(BindableObject bindable, object oldValue, object newValue)
3245+
{
3246+
SfCalendar? calendar = bindable as SfCalendar;
3247+
if (calendar == null || calendar._customScrollLayout == null)
3248+
{
3249+
calendar?.UpdateLayoutFlowDirection();
3250+
return;
3251+
}
3252+
3253+
calendar.UpdateFlowDirection();
3254+
calendar._customScrollLayout.UpdateVisibleDateOnView();
3255+
}
3256+
#endif
3257+
31763258
/// <summary>
31773259
/// Method to update the focus while view is changed on keyboard interaction.
31783260
/// </summary>

maui/src/Calendar/SfCalendar.cs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public SfCalendar()
135135
/// <summary>
136136
/// Gets a value indicating whether the layout is RTL or not.
137137
/// </summary>
138-
bool IHeaderCommon.IsRTLLayout => this.IsRTL(Identifier);
138+
bool IHeaderCommon.IsRTLLayout => _isRTLLayout;
139139

140140
#endregion
141141

@@ -159,7 +159,7 @@ public void Backward()
159159

160160
if (NavigationDirection == CalendarNavigationDirection.Horizontal)
161161
{
162-
if (this.IsRTL(Identifier))
162+
if (_isRTLLayout)
163163
{
164164
_customScrollLayout.AnimateMoveToNextView();
165165
}
@@ -192,7 +192,7 @@ public void Forward()
192192

193193
if (NavigationDirection == CalendarNavigationDirection.Horizontal)
194194
{
195-
if (this.IsRTL(Identifier))
195+
if (_isRTLLayout)
196196
{
197197
_customScrollLayout.AnimateMoveToPreviousView();
198198
}
@@ -1509,13 +1509,48 @@ void WireMonthViewEvents(CalendarMonthView calendarMonthView)
15091509
/// </summary>
15101510
void UpdateFlowDirection()
15111511
{
1512-
_isRTLLayout = this.IsRTL(Identifier);
1512+
if (_customScrollLayout == null)
1513+
{
1514+
return;
1515+
}
1516+
1517+
UpdateLayoutFlowDirection();
15131518
_layout.UpdateFlowDirection();
15141519
//// To update the header text flow direction.
15151520
_headerLayout?.UpdateHeaderTextFlowDirection();
15161521
_footerLayout?.UpdateFooterFlowDirection();
15171522
}
15181523

1524+
/// <summary>
1525+
/// Method to update the layout flow direction.
1526+
/// </summary>
1527+
void UpdateLayoutFlowDirection()
1528+
{
1529+
// Set isRTLLayout based on CalendarIdentifier
1530+
switch (Identifier)
1531+
{
1532+
case CalendarIdentifier.Hijri:
1533+
case CalendarIdentifier.Persian:
1534+
case CalendarIdentifier.UmAlQura:
1535+
_isRTLLayout = true;
1536+
break;
1537+
1538+
case CalendarIdentifier.Korean:
1539+
case CalendarIdentifier.Taiwan:
1540+
case CalendarIdentifier.ThaiBuddhist:
1541+
_isRTLLayout = false;
1542+
break;
1543+
1544+
case CalendarIdentifier.Gregorian:
1545+
_isRTLLayout = FlowDirection == FlowDirection.RightToLeft ? true : this.IsRTL(this.Identifier);
1546+
break;
1547+
1548+
default:
1549+
_isRTLLayout = false;
1550+
break;
1551+
}
1552+
}
1553+
15191554
/// <summary>
15201555
/// Method to update the range selection.
15211556
/// </summary>

maui/src/Calendar/Views/FooterView/FooterLayout.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,12 @@ internal void UpdateBackground()
185185
/// </summary>
186186
internal void UpdateFooterFlowDirection()
187187
{
188-
FlowDirection = _footerViewInfo.IsRTLLayout ? Microsoft.Maui.FlowDirection.RightToLeft : Microsoft.Maui.FlowDirection.LeftToRight;
188+
#if ANDROID
189+
MeasureContent(Width, Height);
190+
ArrangeContent(Bounds);
191+
#else
189192
InvalidateMeasure();
193+
#endif
190194
}
191195

192196
/// <summary>

0 commit comments

Comments
 (0)