Skip to content

Commit ce37924

Browse files
authored
fix: FreakySwitch upgraded and .NET9 related changes (#170)
1 parent 97d49d3 commit ce37924

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+305
-219
lines changed
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
21
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 25.0.1703.2
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.13.35723.152 d17.13
54
MinimumVisualStudioVersion = 10.0.40219.1
65
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples", "Samples\Samples.csproj", "{FA323AEE-85A9-4D5D-9726-03C7D1FD71A2}"
76
EndProject
@@ -15,21 +14,18 @@ Global
1514
GlobalSection(ProjectConfigurationPlatforms) = postSolution
1615
{FA323AEE-85A9-4D5D-9726-03C7D1FD71A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1716
{FA323AEE-85A9-4D5D-9726-03C7D1FD71A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
17+
{FA323AEE-85A9-4D5D-9726-03C7D1FD71A2}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
1818
{FA323AEE-85A9-4D5D-9726-03C7D1FD71A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
1919
{FA323AEE-85A9-4D5D-9726-03C7D1FD71A2}.Release|Any CPU.Build.0 = Release|Any CPU
2020
{864B4829-7286-4921-A185-DA67FE0D1155}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2121
{864B4829-7286-4921-A185-DA67FE0D1155}.Debug|Any CPU.Build.0 = Debug|Any CPU
2222
{864B4829-7286-4921-A185-DA67FE0D1155}.Release|Any CPU.ActiveCfg = Release|Any CPU
2323
{864B4829-7286-4921-A185-DA67FE0D1155}.Release|Any CPU.Build.0 = Release|Any CPU
24-
{C80669FA-43B5-4B68-9819-30BFD1915031}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25-
{C80669FA-43B5-4B68-9819-30BFD1915031}.Debug|Any CPU.Build.0 = Debug|Any CPU
26-
{C80669FA-43B5-4B68-9819-30BFD1915031}.Release|Any CPU.ActiveCfg = Release|Any CPU
27-
{C80669FA-43B5-4B68-9819-30BFD1915031}.Release|Any CPU.Build.0 = Release|Any CPU
2824
EndGlobalSection
2925
GlobalSection(SolutionProperties) = preSolution
3026
HideSolutionNode = FALSE
3127
EndGlobalSection
3228
GlobalSection(ExtensibilityGlobals) = postSolution
3329
SolutionGuid = {3A49EF6E-4CF5-41B1-8F23-FCD2AC812C50}
3430
EndGlobalSection
35-
EndGlobal
31+
EndGlobal

MAUI.FreakyControls/MAUI.FreakyControls/Converters/InverseBoolConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class InverseBoolConverter : BaseOneWayValueConverter
66
{
77
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
88
{
9-
if (!(value is bool boolValue))
9+
if (value is not bool boolValue)
1010
{
1111
throw new ArgumentException("Value must be a boolean", nameof(value));
1212
}

MAUI.FreakyControls/MAUI.FreakyControls/Extensions/CollectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public static class CollectionExtensions
66
{
77
public static ObservableCollection<T> ToObservable<T>(this IEnumerable<T> col)
88
{
9-
return new ObservableCollection<T>(col);
9+
return [.. col];
1010
}
1111

1212
public static IEnumerable<(T item, int index)> WithIndex<T>(this IEnumerable<T> self) => self?.Select((item, index) => (item, index)) ?? new List<(T, int)>();

MAUI.FreakyControls/MAUI.FreakyControls/Extensions/StreamExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public static class StreamExtensions
44
{
55
public static MemoryStream GetMemoryStream(this Stream stream)
66
{
7-
MemoryStream memoryStream = new MemoryStream();
7+
MemoryStream memoryStream = new();
88
stream.CopyTo(memoryStream);
99
memoryStream.Position = 0;
1010
return memoryStream;

MAUI.FreakyControls/MAUI.FreakyControls/FreakyCropView/FreakyCropView.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

MAUI.FreakyControls/MAUI.FreakyControls/FreakyJumpList/FreakyJumpList.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,17 @@ private void DrawJumpList(SKPaintSurfaceEventArgs e)
186186
var currentIndex = index + 1;
187187
using var textPaint = new SKPaint()
188188
{
189-
TextSize = this.CharacterSize,
190-
TextAlign = SKTextAlign.Center,
189+
Color = currentAlphabet == this.SelectedCharacter ?
190+
SelectedCharacterColor.ToSKColor() : CharacterColor.ToSKColor()
191191
};
192-
textPaint.Color = currentAlphabet == this.SelectedCharacter ?
193-
SelectedCharacterColor.ToSKColor() : CharacterColor.ToSKColor();
192+
var skFont = new SKFont()
193+
{
194+
Size = this.CharacterSize,
195+
};
196+
SKTextAlign textAlign = SKTextAlign.Center;
194197
var point = new SKPoint((float)(info.Width / 2.0), (float)(info.Height / maxCount * currentIndex));
195198
charLocationDictionary.Add(currentAlphabet, point);
196-
canvas?.DrawText(currentAlphabet, point, textPaint);
199+
canvas?.DrawText(currentAlphabet, point, textAlign, skFont, textPaint);
197200
}
198201
}
199202

MAUI.FreakyControls/MAUI.FreakyControls/FreakySwitch/FreakySwitch.cs

Lines changed: 104 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ public class FreakySwitch : ContentView, IDisposable
1414

1515
private static readonly Color outlineColor = IsiOS ? Colors.LightGray : Colors.Black;
1616
private static readonly float outlineWidth = IsAndroid ? 6.0f : 3.0f;
17+
private static readonly float checkMarkWidth = 3.0f;
1718
private static readonly double width = 54.0d;
1819
private static readonly double height = 32.0d;
20+
private static readonly int animationDuration = 250; // ms
21+
private static readonly float thumbOffSizeFactor = IsAndroid ? (2.0f / 3.0f) : 1.0f;
1922

2023
private float animationProgress;
2124
private bool isAnimating;
@@ -47,15 +50,20 @@ private async Task AnimateThumbAsync()
4750

4851
//60 frames per sec... 60frames/sec
4952
const int frameRate = 60;
50-
const double totalDuration = 0.25; // 250 ms
53+
54+
double durationInSeconds = AnimationDuration / 1000.0;
55+
if (durationInSeconds <= 0)
56+
{
57+
durationInSeconds = 0.001d;
58+
}
5159

5260
// get the inverse of the framerate... (1/60) seconds/frame i.e. frame duration
5361
double frameDuration = 1.0 / frameRate;
5462

5563
while (animationProgress < 1.0f)
5664
{
5765
//update the percentage of the animation process
58-
animationProgress += (float)(frameDuration / totalDuration);
66+
animationProgress += (float)(frameDuration / durationInSeconds);
5967
skiaView.InvalidateSurface();
6068
await Task.Delay(TimeSpan.FromSeconds(frameDuration));
6169
}
@@ -85,16 +93,16 @@ private void DrawAnimatingState(SKCanvas canvas, SKRect bounds)
8593

8694
canvas.DrawRoundRect(bounds, bounds.Height / 2, bounds.Height / 2, backgroundPaint);
8795

88-
if (IsToggled)
96+
if (IsToggled)
8997
{
9098
var thumbWidth = bounds.Height * 0.8f;
9199
var thumbLeftOff = bounds.Left + (bounds.Height * 0.1f); // 10% padding
92100
var thumbLeftOn = bounds.Right - thumbWidth - (bounds.Height * 0.1f);
93101
var thumbLeft = thumbLeftOn - ((thumbLeftOn - thumbLeftOff) * animationProgress);
94102
var thumbTop = bounds.Top + ((bounds.Height - thumbWidth) / 2);
95-
var thumbRect = SKRect.Create(thumbLeft, thumbTop, thumbWidth, thumbWidth);
96-
97-
// Draw the switch thumb
103+
var thumbRect = SKRect.Create(thumbLeft, thumbTop, thumbWidth, thumbWidth);
104+
105+
// Draw the switch thumb
98106
var thumbPaint = new SKPaint
99107
{
100108
Color = ThumbOnColor.ToSKColor(),
@@ -125,14 +133,14 @@ private void DrawAnimatingState(SKCanvas canvas, SKRect bounds)
125133
private void HandlePaintSurface(object sender, SKPaintSurfaceEventArgs e)
126134
{
127135
var canvas = e.Surface.Canvas;
128-
canvas.Clear();
129-
136+
canvas.Clear();
137+
130138
if (isAnimating)
131139
{
132140
DrawAnimatingState(canvas, e.Info.Rect);
133141
}
134-
else
135-
{
142+
else
143+
{
136144
if (IsToggled)
137145
DrawOnState(canvas, e.Info.Rect);
138146
else
@@ -177,6 +185,24 @@ private void DrawOnState(SKCanvas canvas, SKRect bounds)
177185
IsAntialias = true
178186
};
179187
canvas.DrawRoundRect(thumbRect, thumbWidth / 2, thumbWidth / 2, thumbPaint); // Maintain circular shape
188+
189+
if (ShowCheckMark)
190+
{
191+
// Draw the checkmark
192+
var checkmarkPath = new SKPath();
193+
checkmarkPath.MoveTo(thumbLeft + (thumbWidth * 0.25f), thumbTop + (thumbWidth * 0.5f));
194+
checkmarkPath.LineTo(thumbLeft + (thumbWidth * 0.45f), thumbTop + (thumbWidth * 0.7f));
195+
checkmarkPath.LineTo(thumbLeft + (thumbWidth * 0.75f), thumbTop + (thumbWidth * 0.3f));
196+
197+
var checkmarkPaint = new SKPaint
198+
{
199+
Color = CheckMarkColor.ToSKColor(),
200+
IsAntialias = true,
201+
Style = SKPaintStyle.Stroke,
202+
StrokeWidth = CheckMarkWidth
203+
};
204+
canvas.DrawPath(checkmarkPath, checkmarkPaint);
205+
}
180206
}
181207

182208
private void DrawOffState(SKCanvas canvas, SKRect bounds)
@@ -197,10 +223,10 @@ private void DrawOffState(SKCanvas canvas, SKRect bounds)
197223
var thumbTop = bounds.Top + ((bounds.Height - thumbWidth) / 2); // Center the thumb vertically
198224
var thumbRect = SKRect.Create(thumbLeft, thumbTop, thumbWidth, thumbWidth); // Make the thumb circular
199225

200-
if (IsAndroid)
226+
if (ThumbOffSizeFactor > 0 && ThumbOffSizeFactor < 1)
201227
{
202-
// Reduce thumb size on Android in the off state to 2/3 of its original size
203-
var reducedThumbWidth = thumbWidth * (2.0f / 3.0f);
228+
// Reduce the thumb size in the off state to a fraction of its original size, as specified by ThumbOffSizeFactor
229+
var reducedThumbWidth = thumbWidth * ThumbOffSizeFactor;
204230
thumbLeft += (thumbWidth - reducedThumbWidth) / 2;
205231
thumbTop += (thumbWidth - reducedThumbWidth) / 2;
206232
thumbRect = SKRect.Create(thumbLeft, thumbTop, reducedThumbWidth, reducedThumbWidth);
@@ -226,6 +252,36 @@ private void DrawOffState(SKCanvas canvas, SKRect bounds)
226252
canvas.DrawRoundRect(outlineBounds, outlineBounds.Height / 2, outlineBounds.Height / 2, outlinePaint);
227253
}
228254

255+
public int AnimationDuration
256+
{
257+
get { return (int)GetValue(AnimationDurationProperty); }
258+
set { SetValue(AnimationDurationProperty, value); }
259+
}
260+
261+
public float ThumbOffSizeFactor
262+
{
263+
get { return (float)GetValue(ThumbOffSizeFactorProperty); }
264+
set { SetValue(ThumbOffSizeFactorProperty, value); }
265+
}
266+
267+
public bool ShowCheckMark
268+
{
269+
get { return (bool)GetValue(ShowCheckMarkProperty); }
270+
set { SetValue(ShowCheckMarkProperty, value); }
271+
}
272+
273+
public float CheckMarkWidth
274+
{
275+
get { return (float)GetValue(CheckMarkWidthProperty); }
276+
set { SetValue(CheckMarkWidthProperty, value); }
277+
}
278+
279+
public Color CheckMarkColor
280+
{
281+
get { return (Color)GetValue(CheckMarkColorProperty); }
282+
set { SetValue(CheckMarkColorProperty, value); }
283+
}
284+
229285
public Color OutlineColor
230286
{
231287
get => (Color)GetValue(OutlineColorProperty);
@@ -288,6 +344,41 @@ protected override void ChangeVisualState()
288344

289345
public event EventHandler<ToggledEventArgs> Toggled;
290346

347+
public static readonly BindableProperty AnimationDurationProperty =
348+
BindableProperty.Create(
349+
nameof(AnimationDuration),
350+
typeof(int),
351+
typeof(FreakySwitch),
352+
animationDuration);
353+
354+
public static readonly BindableProperty ThumbOffSizeFactorProperty =
355+
BindableProperty.Create(
356+
nameof(ThumbOffSizeFactor),
357+
typeof(float),
358+
typeof(FreakySwitch),
359+
thumbOffSizeFactor);
360+
361+
public static readonly BindableProperty ShowCheckMarkProperty =
362+
BindableProperty.Create(
363+
nameof(ShowCheckMark),
364+
typeof(bool),
365+
typeof(FreakySwitch),
366+
false);
367+
368+
public static readonly BindableProperty CheckMarkWidthProperty =
369+
BindableProperty.Create(
370+
nameof(CheckMarkWidth),
371+
typeof(float),
372+
typeof(FreakySwitch),
373+
checkMarkWidth);
374+
375+
public static readonly BindableProperty CheckMarkColorProperty =
376+
BindableProperty.Create(
377+
nameof(CheckMarkColor),
378+
typeof(Color),
379+
typeof(FreakySwitch),
380+
Colors.White);
381+
291382
public static readonly BindableProperty OutlineColorProperty =
292383
BindableProperty.Create(
293384
nameof(OutlineColor),

MAUI.FreakyControls/MAUI.FreakyControls/Helpers/DownloadHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private static async Task<Stream> DownloadStreamAsync(Uri uri, CancellationToken
2020

2121
// Do not remove this await otherwise the client will dispose before
2222
// the stream even starts
23-
return await StreamWrapper.GetStreamAsync(uri, cancellationToken, client).ConfigureAwait(false);
23+
return await StreamWrapper.GetStreamAsync(uri, client, cancellationToken).ConfigureAwait(false);
2424
}
2525
catch (Exception ex)
2626
{

MAUI.FreakyControls/MAUI.FreakyControls/Helpers/SizeOrScale.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ public SizeOrScale(float x, float y, SizeOrScaleType type, bool keepAspectRatio)
6060

6161
public bool KeepAspectRatio { get; set; }
6262

63-
public bool IsValid => X > 0 && Y > 0;
63+
public readonly bool IsValid => X > 0 && Y > 0;
6464

65-
public Size GetScale(float width, float height)
65+
public readonly Size GetScale(float width, float height)
6666
{
6767
if (Type == SizeOrScaleType.Scale)
6868
{
@@ -74,7 +74,7 @@ public Size GetScale(float width, float height)
7474
}
7575
}
7676

77-
public Size GetSize(float width, float height)
77+
public readonly Size GetSize(float width, float height)
7878
{
7979
if (Type == SizeOrScaleType.Scale)
8080
{

MAUI.FreakyControls/MAUI.FreakyControls/Maui.FreakyControls.csproj

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<TargetFrameworks>net8.0;net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
5-
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
4+
<TargetFrameworks>net9.0;net9.0-android;net9.0-ios;net9.0-maccatalyst</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net9.0-windows10.0.19041.0</TargetFrameworks>
66
<UseMaui>true</UseMaui>
77
<SingleProject>true</SingleProject>
88
<ImplicitUsings>enable</ImplicitUsings>
@@ -12,9 +12,9 @@
1212
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
1313
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
1414
<RootNamespace>Maui.FreakyControls</RootNamespace>
15-
<AssemblyVersion>0.5.0</AssemblyVersion>
16-
<AssemblyFileVersion>0.5.0</AssemblyFileVersion>
17-
<Version>0.5.0-pre</Version>
15+
<AssemblyVersion>0.5.2</AssemblyVersion>
16+
<AssemblyFileVersion>0.5.2</AssemblyFileVersion>
17+
<Version>0.5.2-pre</Version>
1818
<NeutralLanguage>en</NeutralLanguage>
1919
<!--Version of C# to use -->
2020
<PackageId>FreakyControls</PackageId>
@@ -42,10 +42,10 @@
4242
<LangVersion>latest</LangVersion>
4343
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
4444
</PropertyGroup>
45-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-ios|AnyCPU'">
45+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net9.0-ios|AnyCPU'">
4646
<CreatePackage>false</CreatePackage>
4747
</PropertyGroup>
48-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-ios|AnyCPU'">
48+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net9.0-ios|AnyCPU'">
4949
<CreatePackage>false</CreatePackage>
5050
</PropertyGroup>
5151
<ItemGroup>
@@ -139,11 +139,10 @@
139139
<Folder Include="Wrappers\" />
140140
</ItemGroup>
141141
<ItemGroup>
142-
<PackageReference Include="SkiaSharp.Views.Maui.Controls" Version="2.88.9" />
143-
<PackageReference Include="Svg.Skia" Version="1.0.0.19" />
142+
<PackageReference Include="SkiaSharp.Views.Maui.Controls" Version="3.116.1" />
143+
<PackageReference Include="Svg.Skia" Version="2.0.0.8" />
144144
<PackageReference Include="FreakyEffects" Version="0.1.2" />
145-
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.82" />
146-
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.82" />
145+
<PackageReference Include="Microsoft.Maui.Controls" Version="9.0.0" />
147146
</ItemGroup>
148147
<ItemGroup>
149148
<MauiXaml Update="Shared\FreakySignatureView\SignaturePadView.xaml">

0 commit comments

Comments
 (0)