Skip to content
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

Enable performance CAs for more Core classes #17524

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Core/src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# We can gradually add to this list until we're ready to activate enforcement
# for the entire project
# To run the performance CA on all files, replace the list of files with [*.cs]
[{Flex.cs,PlatformTouchGraphicsView.cs}]
[{Flex.cs,PlatformTouchGraphicsView.cs,MauiScrollView.cs,MauiSwipeView.cs,MauiWebViewClient.cs}]
dotnet_analyzer_diagnostic.category-Performance.severity = warning
10 changes: 5 additions & 5 deletions src/Core/src/Platform/Android/MauiScrollView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class MauiScrollView : NestedScrollView, IScrollBarView, NestedScrollView
MauiHorizontalScrollView? _hScrollView;
bool _isBidirectional;
ScrollOrientation _scrollOrientation = ScrollOrientation.Vertical;
ScrollBarVisibility _defaultHorizontalScrollVisibility = 0;
ScrollBarVisibility _defaultVerticalScrollVisibility = 0;
ScrollBarVisibility _horizontalScrollVisibility = 0;
ScrollBarVisibility _defaultHorizontalScrollVisibility;
ScrollBarVisibility _defaultVerticalScrollVisibility;
ScrollBarVisibility _horizontalScrollVisibility;

internal float LastX { get; set; }
internal float LastY { get; set; }
Expand Down Expand Up @@ -182,7 +182,7 @@ void IScrollBarView.AwakenScrollBars()
base.AwakenScrollBars();
}

bool IScrollBarView.ScrollBarsInitialized { get; set; } = false;
bool IScrollBarView.ScrollBarsInitialized { get; set; }

protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
{
Expand Down Expand Up @@ -415,7 +415,7 @@ void IScrollBarView.AwakenScrollBars()
base.AwakenScrollBars();
}

bool IScrollBarView.ScrollBarsInitialized { get; set; } = false;
bool IScrollBarView.ScrollBarsInitialized { get; set; }

protected override void OnScrollChanged(int l, int t, int oldl, int oldt)
{
Expand Down
14 changes: 7 additions & 7 deletions src/Core/src/Platform/Android/MauiSwipeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ bool ShouldInterceptScrollChildrenTouch(SwipeDirection swipeDirection)
return true;
}

bool ShouldInterceptScrollChildrenTouch(ViewGroup scrollView, bool isHorizontal)
static bool ShouldInterceptScrollChildrenTouch(ViewGroup scrollView, bool isHorizontal)
{
AView? scrollViewContent = scrollView.GetChildAt(0);

Expand All @@ -166,7 +166,7 @@ bool ShouldInterceptScrollChildrenTouch(ViewGroup scrollView, bool isHorizontal)
return true;
}

bool IsViewInBounds(AView view, int x, int y)
static bool IsViewInBounds(AView view, int x, int y)
{
ARect outRect = new ARect();
view.GetHitRect(outRect);
Expand Down Expand Up @@ -295,9 +295,9 @@ bool IsHorizontalSwipe()
return _swipeDirection == SwipeDirection.Left || _swipeDirection == SwipeDirection.Right;
}

bool IsValidSwipeItems(ISwipeItems? swipeItems)
static bool IsValidSwipeItems(ISwipeItems? swipeItems)
{
return swipeItems != null && swipeItems.Where(s => GetIsVisible(s)).Count() > 0;
return swipeItems != null && swipeItems.Any(GetIsVisible);
}

bool ProcessSwipingInteractions(MotionEvent? e)
Expand Down Expand Up @@ -463,7 +463,7 @@ bool TouchInsideContent(APointF point)
return touchContent;
}

bool TouchInsideContent(double x1, double y1, double x2, double y2, double x, double y)
static bool TouchInsideContent(double x1, double y1, double x2, double y2, double x, double y)
{
if (x > x1 && x < (x1 + x2) && y > y1 && y < (y1 + y2))
return true;
Expand Down Expand Up @@ -1034,7 +1034,7 @@ float GetSwipeThreshold(ISwipeItems swipeItems)
return ValidateSwipeThreshold(swipeThreshold);
}

bool GetIsVisible(ISwipeItem swipeItem)
static bool GetIsVisible(ISwipeItem swipeItem)
{
if (swipeItem is IView view)
return view.Visibility == Maui.Visibility.Visible;
Expand Down Expand Up @@ -1288,7 +1288,7 @@ void ProcessTouchSwipeItems(APointF point)
}
}

void ExecuteSwipeItem(ISwipeItem item)
static void ExecuteSwipeItem(ISwipeItem item)
{
if (item == null)
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Platform/Android/MauiWebViewClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public override void OnReceivedError(WebView? view, IWebResourceRequest? request
bool NavigatingCanceled(string? url) =>
!_handler.TryGetTarget(out var handler) || handler.NavigatingCanceled(url);

string GetValidUrl(string? url)
static string GetValidUrl(string? url)
{
if (string.IsNullOrEmpty(url))
return string.Empty;
Expand Down
8 changes: 4 additions & 4 deletions src/Core/src/Platform/Tizen/MauiSwipeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ void UpdateOffset(double swipeOffset)
}
}

void UpdateSwipeItemViewLayout(ISwipeItemView swipeItemView)
static void UpdateSwipeItemViewLayout(ISwipeItemView swipeItemView)
{
swipeItemView?.Handler?.ToPlatform().InvalidateMeasure(swipeItemView);
}
Expand Down Expand Up @@ -428,7 +428,7 @@ void Swipe()
}
}

void ExecuteSwipeItem(ISwipeItem item)
static void ExecuteSwipeItem(ISwipeItem item)
{
if (item == null)
return;
Expand Down Expand Up @@ -717,12 +717,12 @@ bool ValidateSwipeDirection()
return IsValidSwipeItems(swipeItems);
}

bool IsValidSwipeItems(ISwipeItems? swipeItems)
static bool IsValidSwipeItems(ISwipeItems? swipeItems)
{
return swipeItems != null && swipeItems.Where(s => GetIsVisible(s)).Any();
}

bool GetIsVisible(ISwipeItem swipeItem)
static bool GetIsVisible(ISwipeItem swipeItem)
{
if (swipeItem is IView view)
return view.Visibility == Maui.Visibility.Visible;
Expand Down
30 changes: 10 additions & 20 deletions src/Core/src/Platform/iOS/MauiSwipeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public void HandlePan(UIPanGestureRecognizer panGestureRecognizer)
}
}

UIView CreateEmptyContent()
static UIView CreateEmptyContent()
{
var emptyContentView = new UIView
{
Expand All @@ -274,7 +274,7 @@ bool IsHorizontalSwipe()
return _swipeDirection == SwipeDirection.Left || _swipeDirection == SwipeDirection.Right;
}

bool IsValidSwipeItems(ISwipeItems? swipeItems)
static bool IsValidSwipeItems(ISwipeItems? swipeItems)
{
return swipeItems != null && swipeItems.Any(GetIsVisible);
}
Expand Down Expand Up @@ -402,7 +402,7 @@ internal void UpdateSwipeTransitionMode(SwipeTransitionMode swipeTransitionMode)
_swipeTransitionMode = swipeTransitionMode;
}

void UpdateSwipeItemInsets(UIButton button, float spacing = 0.0f)
static void UpdateSwipeItemInsets(UIButton button, float spacing = 0.0f)
{
if (button.ImageView?.Image == null)
return;
Expand Down Expand Up @@ -536,17 +536,7 @@ bool TouchInsideContent(CGPoint point)
if (_contentView == null)
return false;

bool touchContent = TouchInsideContent(_contentView.Frame.Left, _contentView.Frame.Top, _contentView.Frame.Width, _contentView.Frame.Height, point.X, point.Y);

return touchContent;
}

bool TouchInsideContent(double x1, double y1, double x2, double y2, double x, double y)
{
if (x > x1 && x < (x1 + x2) && y > y1 && y < (y1 + y2))
return true;

return false;
return _contentView.Frame.Contains(point);
}

ISwipeItems? GetSwipeItemsByDirection()
Expand Down Expand Up @@ -778,7 +768,7 @@ void ValidateSwipeThreshold()
foreach (var swipeItem in swipeItems)
{
if (GetIsVisible(swipeItem))
ExecuteSwipeItem(swipeItem);
MauiSwipeView.ExecuteSwipeItem(swipeItem);
}

if (swipeItems.SwipeBehaviorOnInvoked != SwipeBehaviorOnInvoked.RemainOpen)
Expand Down Expand Up @@ -996,7 +986,7 @@ bool ValidateSwipeDirection()
return false;

var swipeItems = GetSwipeItemsByDirection();
return IsValidSwipeItems(swipeItems);
return MauiSwipeView.IsValidSwipeItems(swipeItems);
}

double GetSwipeOffset(CGPoint initialPoint, CGPoint endPoint)
Expand Down Expand Up @@ -1039,9 +1029,9 @@ void ProcessTouchSwipeItems(CGPoint point)
var swipeItemX = swipeItemRect.Left;
var swipeItemY = swipeItemRect.Top;

if (TouchInsideContent(swipeItemX, swipeItemY, swipeItemRect.Width, swipeItemRect.Height, point.X, point.Y))
if (swipeItemRect.Contains(point))
{
ExecuteSwipeItem(swipeItem);
MauiSwipeView.ExecuteSwipeItem(swipeItem);

if (swipeItems.SwipeBehaviorOnInvoked != SwipeBehaviorOnInvoked.RemainOpen)
ResetSwipe();
Expand Down Expand Up @@ -1078,7 +1068,7 @@ void ProcessTouchSwipeItems(CGPoint point)

if (controller.ChildViewControllers.Any())
{
var childs = controller.ChildViewControllers.Count();
var childs = controller.ChildViewControllers.Length;

for (int i = 0; i < childs; i++)
{
Expand All @@ -1095,7 +1085,7 @@ void ProcessTouchSwipeItems(CGPoint point)
return null;
}

void ExecuteSwipeItem(ISwipeItem item)
static void ExecuteSwipeItem(ISwipeItem item)
{
if (item == null)
return;
Expand Down