Skip to content

Commit

Permalink
Merge pull request #1001 from unoplatform/dev/nr/loadingview
Browse files Browse the repository at this point in the history
chore: Updated analysers to v8 and fixed all errors (from new analyzers)
  • Loading branch information
nickrandolph authored Jan 16, 2024
2 parents 61b99c4 + dac3850 commit b6e4b69
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 31 deletions.
2 changes: 1 addition & 1 deletion samples/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.0-preview1.22518.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Debug" Version="5.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public App()
/// <param name="e">Details about the launch request and process.</param>
protected override async void OnLaunched(XamlLaunchActivatedEventArgs e)
{
#if __IOS__ && USE_UITESTS
#if __IOS__ && USE_UITESTS && !MACCATALYST
Xamarin.Calabash.Start();
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
<PackageVersion Include="Uno.UITest.Xamarin" Version="1.1.0-dev.70" />
<PackageVersion Include="Xamarin.UITest" Version="4.3.3" />
<PackageVersion Include="MSTest.TestFramework" Version="2.1.2" />
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.0-preview1.22518.1" />
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ public static void SetSelector(DependencyObject obj, Selector? value)

#region State Attached Property (private)
[DynamicDependency(nameof(SetState))]
// TODO: Review whether DependencyObject can be changed to TabBar
#pragma warning disable CA1859 // Use concrete types when possible for improved performance
private static TabBarSelectorBehaviorState? GetState(DependencyObject obj)
{
return (TabBarSelectorBehaviorState)obj.GetValue(StateProperty);
}

[DynamicDependency(nameof(GetState))]
// TODO: Review whether DependencyObject can be changed to TabBar
#pragma warning disable CA1859 // Use concrete types when possible for improved performance
private static void SetState(DependencyObject obj, TabBarSelectorBehaviorState? value)
#pragma warning restore CA1859 // Use concrete types when possible for improved performance
{
obj.SetValue(StateProperty, value);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Uno.Toolkit.UI/Behaviors/VisualStateManagerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public static class VisualStateManagerExtensions
typeof(VisualStateManagerExtensions),
new PropertyMetadata(default(string), OnStatesChanged));

private static readonly char[] separator = new char[] { ',', ';', ' ' };

/// <summary>
/// Sets the visual states of the control.
/// </summary>
Expand All @@ -72,7 +74,7 @@ private static void OnStatesChanged(DependencyObject sender, DependencyPropertyC
{
if (sender is Control control && e.NewValue is string { Length: >0 } value)
{
var states = value.Split(new char[] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries)
var states = value.Split(separator, StringSplitOptions.RemoveEmptyEntries)
.Where(x => !string.IsNullOrEmpty(x))
.Select(x => x.Trim())
.ToArray();
Expand All @@ -89,7 +91,7 @@ private static void OnStatesChanged(DependencyObject sender, DependencyPropertyC
anySuccessed |= success;
}

if (states.Any() && !anySuccessed)
if (states.Length != 0 && !anySuccessed)
{
WarnForMisplacedVisualStateGroups(control);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public partial class ExtendedSplashScreen
catch
{
var entry = Assembly.GetEntryAssembly();
var res = entry?.GetManifestResourceNames()?.FirstOrDefault(x => x.ToLower().Contains(WasmAppManifestFilename));
var res = entry?.GetManifestResourceNames()?.FirstOrDefault(x => x.ToLower().Contains(WasmAppManifestFilename, StringComparison.InvariantCultureIgnoreCase));
if (string.IsNullOrWhiteSpace(res))
{
return null;
Expand All @@ -125,8 +125,8 @@ public partial class ExtendedSplashScreen
{
return null;
}
var startIdx = manifestString.IndexOf("{") + 1;
var endIdx = manifestString.LastIndexOf("}") - 1;
var startIdx = manifestString.IndexOf('{') + 1;
var endIdx = manifestString.LastIndexOf('}') - 1;
manifestString = manifestString.Substring(startIdx, endIdx - startIdx); // Trim "var UnoAppManifest = " from the start of the file so we're left with just the JSON
var pairs = (from pair in manifestString.Trim().Split(',')
let bits = pair.Split(':')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private async Task InvalidateStack()

_isUpdatingStack = true;

while (_stackUpdates.Any())
while (_stackUpdates.Count != 0)
{
var navigation = _stackUpdates.Dequeue();
await UpdateStack(navigation.pageEntry, navigation.args);
Expand Down Expand Up @@ -187,7 +187,7 @@ private async Task UpdateStack(PageStackEntry? entry, NavigationEventArgs e)
_pageStack.Children.Insert(0, newPage);
}
}
break;
break;
}

_currentEntry = newEntry;
Expand All @@ -199,7 +199,9 @@ private static bool GetIsAnimated(PageStackEntry? entry)
return !(entry?.NavigationTransitionInfo is SuppressNavigationTransitionInfo);
}

#pragma warning disable CA1859 // Use concrete types when possible for improved performance - Returning Android.Views.Animations.AnimationSet only applicable on Android
private static Animation GetEnterAnimation()
#pragma warning restore CA1859 // Use concrete types when possible for improved performance
{
// Source:
// https://android.googlesource.com/platform/frameworks/base/+/android-cts-7.1_r5/core/res/res/anim/activity_open_enter.xml
Expand Down Expand Up @@ -236,7 +238,9 @@ private static Animation GetEnterAnimation()
return enterAnimation;
}

#pragma warning disable CA1859 // Use concrete types when possible for improved performance - Returning Android.Views.Animations.AnimationSet only applicable on Android
private static Animation GetExitAnimation()
#pragma warning restore CA1859 // Use concrete types when possible for improved performance
{
// Source:
// https://android.googlesource.com/platform/frameworks/base/+/android-cts-7.1_r5/core/res/res/anim/activity_close_exit.xml
Expand Down
8 changes: 4 additions & 4 deletions src/Uno.Toolkit.UI/Controls/TabBar/TabBarListPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ protected override Size MeasureOverride(Size availableSize)
var widthOfWidest = 0d;
var heightOfTallest = 0d;

var visibleChildren = Children.Where(IsVisible);
var visibleChildren = Children.Where(IsVisible).ToArray();

var count = visibleChildren.Count();
var count = visibleChildren.Length;
if (count < 1)
{
return availableSize.FiniteOrDefault(default);
Expand Down Expand Up @@ -95,8 +95,8 @@ protected override Size MeasureOverride(Size availableSize)

protected override Size ArrangeOverride(Size finalSize)
{
var visibleChildren = Children.Where(IsVisible);
var count = visibleChildren.Count();
var visibleChildren = Children.Where(IsVisible).ToArray();
var count = visibleChildren.Length;
if (count < 1)
{
return finalSize;
Expand Down
6 changes: 4 additions & 2 deletions src/Uno.Toolkit.UI/Helpers/ImageHelper.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace Uno.Toolkit.UI
{
internal static class ImageHelper
{
private static readonly char[] trimChars = new[] { '/' };

public static UIImage? FromUri(Uri? uri)
{
if (uri == null)
Expand All @@ -19,11 +21,11 @@ internal static class ImageHelper
}

var bundleName = Path.GetFileName(uri.AbsolutePath);
var bundlePath = uri.PathAndQuery.TrimStart(new[] { '/' });
var bundlePath = uri.PathAndQuery.TrimStart(trimChars);

var image = UIImage.FromFile(bundleName) ?? UIImage.FromFile(bundlePath);
return image;
}
}
}
#endif
#endif
13 changes: 7 additions & 6 deletions src/Uno.Toolkit.UI/Helpers/VisualTreeHelperEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal static partial class VisualTreeHelperEx
/// </summary>
/// <param name="reference">Any node of the visual tree</param>
public static string TreeGraph(this DependencyObject reference) => TreeGraph(reference, DebugVTNode);

/// <summary>
/// Produces a text representation of the visual tree, using the provided method of description.
/// </summary>
Expand Down Expand Up @@ -112,7 +112,7 @@ void Print(object o, int depth)
public static T? GetFirstAncestor<T>(this DependencyObject reference, Func<T, bool> predicate) => GetAncestors(reference)
.OfType<T>()
.FirstOrDefault(predicate);

/// <summary>
/// Returns the first ancestor of a specified type that satisfies the <paramref name="predicate"/>.
/// </summary>
Expand Down Expand Up @@ -374,21 +374,22 @@ public static IEnumerable<_View> GetDescendants(_View reference, Func<_View, boo
}

#if __IOS__
private static IEnumerable<_View> GetChildren(_View reference)
private static _View[] GetChildren(_View reference)
{
return reference.Subviews;
}
#elif __ANDROID__
private static IEnumerable<_View> GetChildren(_View reference)
private static _View[] GetChildren(_View reference)
{
if (reference is Android.Views.ViewGroup vg)
{
return Enumerable
.Range(0, vg.ChildCount)
.Select(vg.GetChildAt)!;
.Select(idx => vg.GetChildAt(idx)!)
.ToArray();
}

return Enumerable.Empty<_View>();
return Array.Empty<_View>();
}
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace Uno.Toolkit.UI
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "Converters")]
internal class InflateDimensionConverter : IValueConverter
internal sealed class InflateDimensionConverter : IValueConverter
{
public double Inflation { get; set; }
public double DefaultValue { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@
<Thickness x:Key="CupertinoBottomTabBarItemContentMargin">0,0,0,12</Thickness>
<Thickness x:Key="CupertinoBottomTabBarItemContentOnlyMargin">12,0</Thickness>

<StaticResource x:Key="CupertinoBottomTabBarBackground"
<StaticResource x:Key="CupertinoBottomTabBarBackground"
ResourceKey="CupertinoBottomTabBarBackgroundBrush" />

<StaticResource x:Key="CupertinoBottomTabBarBackground"
ResourceKey="SystemControlTransparentBrush" />
<StaticResource x:Key="CupertinoBottomTabBarBackgroundPointerOver"
<StaticResource x:Key="CupertinoBottomTabBarBackgroundPointerOver"
ResourceKey="SystemControlTransparentBrush" />
<StaticResource x:Key="CupertinoBottomTabBarBackgroundPressed"
ResourceKey="SystemControlTransparentBrush" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
<StaticResource x:Key="CupertinoSegmentedControlItemForegroundSelectedPressed"
ResourceKey="CupertinoSystemBackgroundBrush" />

<StaticResource x:Key="CupertinoSegmentedControlItemBorderBrush"
ResourceKey="CupertinoBlueBrush" />

<x:Double x:Key="CupertinoSegmentedControlFontSize">12</x:Double>
<FontFamily x:Key="CupertinoSegmentedControlFontFamily">SF Pro</FontFamily>
<x:Double x:Key="CupertinoSegmentedControlHeight">28</x:Double>
Expand Down

0 comments on commit b6e4b69

Please sign in to comment.