Skip to content
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
72 changes: 25 additions & 47 deletions maui/src/Popup/Helpers/PopupExtension/PopupExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ internal static SfPopup? TopMostOpenPopup
{
get
{
return OpenPopups.Count > 0 ? OpenPopups[OpenPopups.Count - 1] : null;
int count = OpenPopups.Count;
return count > 0 ? OpenPopups[count - 1] : null;
}
}

Expand All @@ -32,61 +33,38 @@ internal static SfPopup? TopMostOpenPopup
internal static Page? GetMainPage(bool shouldReturnOnlyMainPage = false)
{
var windowPage = PopupExtension.GetMainWindowPage();
if (windowPage is not null)
if (windowPage is null)
{
if (windowPage is not null)
return null;
}

// An exception is thrown when showing the popup in the OnAppearing() method of a modally pushed page.
if (windowPage.Navigation is not null && windowPage.Navigation.ModalStack is not null)
{
var modalPage = windowPage.Navigation.ModalStack.LastOrDefault();
if (modalPage is not null)
{
// An exception is thrown when showing the popup in the OnAppearing() method of a modally pushed page.
if (windowPage.Navigation is not null && windowPage.Navigation.ModalStack is not null)
// Calling Navigation.PushModalAsync(new NavigationPage(new ModalPage())) does not return the NavigationPage of the current page.
if (modalPage is NavigationPage navPage)
{
var modalPage = windowPage.Navigation.ModalStack.LastOrDefault();
if (modalPage is not null)
{
// Calling Navigation.PushModalAsync(new NavigationPage(new ModalPage())) does not return the NavigationPage of the current page.
if (modalPage is NavigationPage navPage)
{
if (navPage.CurrentPage is null)
{
return new Page();
}
else
{
return navPage.CurrentPage;
}
}

return modalPage;
}
return navPage.CurrentPage ?? windowPage;
}

if (windowPage is NavigationPage navigationPage && !shouldReturnOnlyMainPage)
{
// When navigation current page is null, returned new page.
if (navigationPage.CurrentPage == null)
{
return new Page();
}

return navigationPage.CurrentPage;
}
else if (windowPage is Shell shellPage)
{
// 837430 : when shell current page is null, NullReferenceException is thrown in ios in release mode.
if (shellPage.CurrentPage == null)
{
return new Page();
}

return shellPage.CurrentPage;
}
return modalPage;
}
}

return windowPage;
if (windowPage is NavigationPage navigationPage && !shouldReturnOnlyMainPage)
{
return navigationPage.CurrentPage ?? windowPage;
}
else
else if (windowPage is Shell shellPage)
{
return new Page();
// 837430 : when shell current page is null, NullReferenceException is thrown in ios in release mode.
return shellPage.CurrentPage ?? windowPage;
}

return windowPage;
}

/// <summary>
Expand All @@ -101,7 +79,7 @@ internal static SfPopup? TopMostOpenPopup
return application.Windows[0].Page;
}

return new Page();
return null;
}

#if !IOS
Expand Down
3 changes: 2 additions & 1 deletion maui/src/Popup/Helpers/PopupExtension/PopupExtension.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ internal static int GetSafeAreaHeight(string position)
#if NET10_0
if (GetSafeAreaEdges())
#else
if (Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page.GetUseSafeArea(GetMainPage()))
var safeAreaPage = GetMainPage();
if (safeAreaPage is not null && Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page.GetUseSafeArea(safeAreaPage))
#endif
{
var platformWindow = WindowOverlayHelper._window?.ToPlatform() as UIWindow;
Expand Down
6 changes: 4 additions & 2 deletions maui/src/Popup/PopupFooter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public PopupFooter()
#if NET10_0
this.IgnoreSafeArea = !PopupExtension.GetSafeAreaEdges();
#else
this.IgnoreSafeArea = !Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page.GetUseSafeArea(PopupExtension.GetMainPage());
var mainPage = PopupExtension.GetMainPage();
this.IgnoreSafeArea = mainPage is null || !Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page.GetUseSafeArea(mainPage);
#endif
#endif
}
Expand All @@ -92,7 +93,8 @@ public PopupFooter(PopupView popupView)
#if IOS
// The value for the IgnoreSafeArea property is being set by retrieving the safe area value from the main page.
#pragma warning disable CS0618 // Suppressing CS0618 warning because Page.GetUseSafeArea is marked obsolete in .NET 10.
IgnoreSafeArea = !Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page.GetUseSafeArea(PopupExtension.GetMainPage());
var mainPageForSafeArea = PopupExtension.GetMainPage();
IgnoreSafeArea = mainPageForSafeArea is null || !Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page.GetUseSafeArea(mainPageForSafeArea);
#pragma warning restore CS0618
#endif
_popupView = popupView;
Expand Down
6 changes: 4 additions & 2 deletions maui/src/Popup/PopupHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public PopupHeader()
#if NET10_0
this.IgnoreSafeArea = !PopupExtension.GetSafeAreaEdges();
#else
this.IgnoreSafeArea = !Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page.GetUseSafeArea(PopupExtension.GetMainPage());
var mainPage = PopupExtension.GetMainPage();
this.IgnoreSafeArea = mainPage is null || !Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page.GetUseSafeArea(mainPage);
#endif
#endif
Initialize();
Expand All @@ -77,7 +78,8 @@ public PopupHeader(PopupView popup)
#if IOS
// When Page SafeArea is false, close icon overlaps header,because HeaderView arranging with safeArea.
#pragma warning disable CS0618 // Suppressing CS0618 warning because Page.GetUseSafeArea is marked obsolete in .NET 10.
IgnoreSafeArea = !Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page.GetUseSafeArea(PopupExtension.GetMainPage());
var mainPageForSafeArea = PopupExtension.GetMainPage();
IgnoreSafeArea = mainPageForSafeArea is null || !Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page.GetUseSafeArea(mainPageForSafeArea);
#pragma warning restore CS0618
#endif
_popupView = popup;
Expand Down
6 changes: 4 additions & 2 deletions maui/src/Popup/PopupMessageView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public PopupMessageView()
#if NET10_0
this.IgnoreSafeArea = !PopupExtension.GetSafeAreaEdges();
#else
this.IgnoreSafeArea = !Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page.GetUseSafeArea(PopupExtension.GetMainPage());
var mainPage = PopupExtension.GetMainPage();
this.IgnoreSafeArea = mainPage is null || !Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page.GetUseSafeArea(mainPage);
#endif
#endif
}
Expand All @@ -69,7 +70,8 @@ public PopupMessageView(PopupView popupView)
#if IOS
// The value for the IgnoreSafeArea property is being set by retrieving the safe area value from the main page.
#pragma warning disable CS0618 // Suppressing CS0618 warning because Page.GetUseSafeArea is marked obsolete in .NET 10.
IgnoreSafeArea = !Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page.GetUseSafeArea(PopupExtension.GetMainPage());
var mainPageForSafeArea = PopupExtension.GetMainPage();
IgnoreSafeArea = mainPageForSafeArea is null || !Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific.Page.GetUseSafeArea(mainPageForSafeArea);
#pragma warning restore CS0618
#endif
_popupView = popupView;
Expand Down
33 changes: 21 additions & 12 deletions maui/src/Shimmer/ShimmerDrawable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ internal partial class ShimmerDrawable : SfDrawableView
const float PersonaRectangleHeightFactor = 0.33f;
const float PersonaRowSpacingFactor = 0.1f;

// Cached Point values to avoid per-call allocations in CreateWavePaint.
static readonly Point s_pointOrigin = new(0, 0);
static readonly Point s_pointRight = new(1, 0);
static readonly Point s_pointBottom = new(0, 1);
static readonly Point s_pointDiagonal = new(1, 1);

#endregion

#region Constructor
Expand Down Expand Up @@ -161,24 +167,24 @@ internal void CreateWavePaint()
switch (Shimmer?.WaveDirection)
{
case ShimmerWaveDirection.LeftToRight:
_gradient.StartPoint = new Point(0, 0);
_gradient.EndPoint = new Point(1, 0);
_gradient.StartPoint = s_pointOrigin;
_gradient.EndPoint = s_pointRight;
break;
case ShimmerWaveDirection.TopToBottom:
_gradient.StartPoint = new Point(0, 0);
_gradient.EndPoint = new Point(0, 1);
_gradient.StartPoint = s_pointOrigin;
_gradient.EndPoint = s_pointBottom;
break;
case ShimmerWaveDirection.RightToLeft:
_gradient.StartPoint = new Point(1, 0);
_gradient.EndPoint = new Point(0, 0);
_gradient.StartPoint = s_pointRight;
_gradient.EndPoint = s_pointOrigin;
break;
case ShimmerWaveDirection.BottomToTop:
_gradient.StartPoint = new Point(0, 1);
_gradient.EndPoint = new Point(0, 0);
_gradient.StartPoint = s_pointBottom;
_gradient.EndPoint = s_pointOrigin;
break;
default:
_gradient.StartPoint = new Point(0, 0);
_gradient.EndPoint = new Point(1, 1);
_gradient.StartPoint = s_pointOrigin;
_gradient.EndPoint = s_pointDiagonal;
break;
}
}
Expand Down Expand Up @@ -275,9 +281,12 @@ void DrawCustomViewChildren(View view, Point position)

if (view is Layout layout)
{
foreach (View item in layout.Children.Cast<View>())
foreach (View item in layout.Children)
{
DrawCustomViewChildren(item, new Point(item.X + position.X, item.Y + position.Y));
if (item is View childView)
{
DrawCustomViewChildren(childView, new Point(childView.X + position.X, childView.Y + position.Y));
}
}
}
else if (view is ContentView contentView && contentView.Content != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal partial class SfHorizontalContent
bool _isTapGestureRemoved;
UIPanGestureRecognizer? _panGesture;
LayoutViewExt? _nativeView;
static readonly System.Collections.Concurrent.ConcurrentDictionary<Type, bool> _drawActionTypeCache = new();

#endregion

Expand Down Expand Up @@ -80,7 +81,8 @@ void ITapGestureListener.ShouldHandleTap(object view)
var touchViewType = touchView?.GetType();
if (touchViewType is not null)
{
var hasDrawAction = touchViewType.GetProperties().Any(p => p.PropertyType == typeof(Action<ICanvas, RectF>));
var hasDrawAction = _drawActionTypeCache.GetOrAdd(touchViewType, type =>
type.GetProperties().Any(p => p.PropertyType == typeof(Action<ICanvas, RectF>)));
if (hasDrawAction)
{
this._canProcessTouch = false;
Expand Down
10 changes: 8 additions & 2 deletions maui/src/TextInputLayout/SfTextInputLayout.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,28 +161,34 @@ internal void OnTextInputViewTextChanged(object? sender, TextChangedEventArgs e)
if (sender is InputView)
{
Text = e.NewTextValue;
bool needsRedraw = false;

if (string.IsNullOrEmpty(Text) && !IsLayoutFocused)
{
if (!IsHintAlwaysFloated)
{
IsHintFloated = false;
IsHintDownToUp = true;
InvalidateDrawable();
needsRedraw = true;
}
}
else if (!string.IsNullOrEmpty(Text) && !IsHintFloated)
{
IsHintFloated = true;
IsHintDownToUp = false;
InvalidateDrawable();
needsRedraw = true;
}

SetCustomDescription(this.Content);

// Clear icon can't draw when isClearIconVisible property updated based on text.
// So here call the InvalidateDrawable to draw the clear icon.
if (Text?.Length <= 1)
{
needsRedraw = true;
}

if (needsRedraw)
{
InvalidateDrawable();
}
Expand Down
Loading