Skip to content

Commit

Permalink
feat!: Bump to net6 preview 13.2
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This update contains binary breaking changes to follow
.NET 6 Mobile iOS/macOS/Catalyst API changes. It requires Visual Studio
2022 17.2 Preview 1 or later and cannot work on previous VS 2022 releases.
  • Loading branch information
jeromelaban committed Feb 16, 2022
1 parent a2ce826 commit dee6870
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 31 deletions.
27 changes: 18 additions & 9 deletions build/ci/templates/dotnet6-install-mac.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
parameters:
DotNetVersion: '6.0.200-preview.22055.15'
DotNetVersion: '6.0.200'
UnoCheck_Version: '1.1.0-dev.22'
UnoCheck_Manifest: 'https://raw.githubusercontent.com/unoplatform/uno.check/4b89f56d8fa3f2cdd980425dcc8cbc4db1249d99/manifests/uno.ui-preview.manifest.json'
UnoCheck_Manifest: 'https://raw.githubusercontent.com/unoplatform/uno.check/90603a57991621c9998fa66534a14e5bf470acc4/manifests/uno.ui-preview.manifest.json'
Dotnet_Root: '/usr/local/share/dotnet/'
Dotnet_Tools: '~/.dotnet/tools'

Expand All @@ -20,14 +20,23 @@ steps:
version: 3.1.x
installationPath: ${{ parameters.Dotnet_Root }}

- bash: |
export PATH="${{ parameters.Dotnet_Root }}:${{ parameters.Dotnet_Tools }}:$PATH"
curl -L https://raw.githubusercontent.com/dotnet/install-scripts/7a9d5dcab92cf131fc2d8977052f8c2c2d540e22/src/dotnet-install.sh > dotnet-install.sh
sh dotnet-install.sh --version ${{ parameters.DotNetVersion }} --install-dir $DOTNET_ROOT --verbose
dotnet --list-sdks
echo "##vso[task.setvariable variable=PATH]$PATH"
displayName: install .NET ${{ parameters.DotNetVersion }}
## Required until .NET 6 installs properly using UseDotnet
## using preview builds
# - bash: |
# export PATH="${{ parameters.Dotnet_Root }}:${{ parameters.Dotnet_Tools }}:$PATH"
# curl -L https://raw.githubusercontent.com/dotnet/install-scripts/11b4eebe23d871c074364940d301c3eb53e7c7ec/src/dotnet-install.sh > dotnet-install.sh
# sh dotnet-install.sh --version ${{ parameters.DotNetVersion }} --install-dir $DOTNET_ROOT --verbose
# dotnet --list-sdks
# echo "##vso[task.setvariable variable=PATH]$PATH"
# displayName: install .NET ${{ parameters.DotNetVersion }}
# retryCountOnTaskFailure: 3

- task: UseDotNet@2
displayName: 'Use .NET Core SDK ${{ parameters.DotNetVersion }}'
retryCountOnTaskFailure: 3
inputs:
packageType: sdk
version: ${{ parameters.DotNetVersion }}

- template: jdk-setup.yml

Expand Down
25 changes: 16 additions & 9 deletions build/ci/templates/dotnet6-install-windows.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
parameters:
DotNetVersion: '6.0.200-preview.22055.15'
DotNetVersion: '6.0.200'
UnoCheck_Version: '1.1.0-dev.22'
UnoCheck_Manifest: 'https://raw.githubusercontent.com/unoplatform/uno.check/4b89f56d8fa3f2cdd980425dcc8cbc4db1249d99/manifests/uno.ui-preview.manifest.json'
UnoCheck_Manifest: 'https://raw.githubusercontent.com/unoplatform/uno.check/90603a57991621c9998fa66534a14e5bf470acc4/manifests/uno.ui-preview.manifest.json'

steps:

## Required until .NET 6 installs properly on Windows using UseDotnet
- powershell: |
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri "https://dot.net/v1/dotnet-install.ps1" -OutFile dotnet-install.ps1
& .\dotnet-install.ps1 -Version ${{ parameters.DotNetVersion }} -InstallDir "$env:ProgramFiles\dotnet\" -Verbose
& dotnet --list-sdks
displayName: Install .NET ${{ parameters.DotNetVersion }}
errorActionPreference: stop
## using preview builds
#- powershell: |
# $ProgressPreference = 'SilentlyContinue'
# Invoke-WebRequest -Uri "https://dot.net/v1/dotnet-install.ps1" -OutFile dotnet-install.ps1
# & .\dotnet-install.ps1 -Version ${{ parameters.DotNetVersion }} -InstallDir "$env:ProgramFiles\dotnet\" -Verbose
# & dotnet --list-sdks
# displayName: Install .NET ${{ parameters.DotNetVersion }}
# errorActionPreference: stop
# retryCountOnTaskFailure: 3
- task: UseDotNet@2
displayName: 'Use .NET Core SDK ${{ parameters.DotNetVersion }}'
retryCountOnTaskFailure: 3
inputs:
packageType: sdk
version: ${{ parameters.DotNetVersion }}

- template: jdk-setup.yml

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ public static AcquireTokenInteractiveParameterBuilder WithUnoHelpers(this Acquir
#if __WASM__
builder.WithCustomWebUi(WasmWebUi.Instance);
#elif __MACOS__
#if NET6_0_OR_GREATER
// WithUnoHelpers is not yet supported for macOS on .NET 6
// builder.WithParentActivityOrWindow(Windows.UI.Xaml.Window.Current.Content.Window);
#else
builder.WithParentActivityOrWindow(Windows.UI.Xaml.Window.Current.Content.Window);
#endif
#endif
return builder;
}
Expand Down
11 changes: 11 additions & 0 deletions src/Uno.UI/Extensions/Matrix3x2Extensions.iOSmacOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal static class Matrix3x2Extensions
public static CATransform3D ToTransform3D(this Matrix3x2 matrix)
=> new CATransform3D
{
#if !NET6_0_OR_GREATER
// Note: The transformation X and Y (M31 and M32) are on the fourth row of 4x4 transform matrix.
// Note2: As we cannot assume that there is no marshaling on each value we set, we set only the
// needed values for an affine transform (3x2).
Expand All @@ -19,6 +20,16 @@ public static CATransform3D ToTransform3D(this Matrix3x2 matrix)
m21 = matrix.M21, m22 = matrix.M22, // m23 = 0, m24 = 0,
/*m31 = 0, m32 = 0,*/ m33 = 1, // m34 = 0,
m41 = matrix.M31, m42 = matrix.M32, /*m43 = 0,*/ m44 = 1
#else
// Note: The transformation X and Y (M31 and M32) are on the fourth row of 4x4 transform matrix.
// Note2: As we cannot assume that there is no marshaling on each value we set, we set only the
// needed values for an affine transform (3x2).

M11 = matrix.M11, M12 = matrix.M12, // m13 = 0, m14 = 0,
M21 = matrix.M21, M22 = matrix.M22, // m23 = 0, m24 = 0,
/*m31 = 0, m32 = 0,*/ M33 = 1, // m34 = 0,
M41 = matrix.M31, M42 = matrix.M32, /*m43 = 0,*/ M44 = 1
#endif
};
}
}
4 changes: 4 additions & 0 deletions src/Uno.UI/Services/ResourceService.iOSmacOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ private string GetLocalizedStringOrDefault(string id, NSBundle bundle)
// If key is nil and value is non-nil, returns value.
// If key is not found and value is nil or an empty string, returns key.
// If key is not found and value is non-nil and not empty, return value.
#if NET6_0_OR_GREATER
var localizedString = bundle.GetLocalizedString(id, KeyNotFoundValue, null);
#else
#pragma warning disable CS0618 // Type or member is obsolete
var localizedString = bundle.LocalizedString(id, KeyNotFoundValue, null);
#pragma warning restore CS0618 // Type or member is obsolete
#endif

if (localizedString == KeyNotFoundValue)
{
Expand Down
8 changes: 7 additions & 1 deletion src/Uno.UI/UI/Xaml/Application.macOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ private void SetCurrentLanguage()

partial void ObserveSystemThemeChanges()
{
NSDistributedNotificationCenter.GetDefaultCenter().AddObserver(
NSDistributedNotificationCenter
#if NET6_0_OR_GREATER
.DefaultCenter
#else
.GetDefaultCenter()
#endif
.AddObserver(
this,
_modeSelector,
_themeChangedNotification,
Expand Down
7 changes: 6 additions & 1 deletion src/Uno.UI/UI/Xaml/Controls/MenuFlyout/MenuFlyout.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ public partial class MenuFlyout
private static DependencyProperty CancelTextIosOverrideProperty = ToolkitHelper.GetProperty("Uno.UI.Toolkit.MenuFlyoutExtensions", "CancelTextIosOverride");

#pragma warning disable CS0618 // Type or member is obsolete
private string LocalizedCancelString => NSBundle.FromIdentifier("com.apple.UIKit").LocalizedString("Cancel", null);
private string LocalizedCancelString => NSBundle.FromIdentifier("com.apple.UIKit")
#if NET6_0_OR_GREATER
.GetLocalizedString("Cancel", null);
#else
.LocalizedString("Cancel", null);
#endif
#pragma warning restore CS0618 // Type or member is obsolete

internal protected override void Open()
Expand Down
19 changes: 17 additions & 2 deletions src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,14 @@ private Size LayoutTypography(Size size)
}

_textContainer.Size = size;
return _layoutManager.GetUsedRectForTextContainer(_textContainer).Size;

#if NET6_0_OR_GREATER
return _layoutManager.GetUsedRect
#else
return _layoutManager.GetUsedRectForTextContainer
#endif

(_textContainer).Size;
}
else
{
Expand All @@ -344,9 +351,17 @@ private int GetCharacterIndexAtPoint(Point point)
// Find the tapped character's index
var partialFraction = (nfloat)0;
var pointInTextContainer = new CGPoint(point.X - _drawRect.X, point.Y - _drawRect.Y);

#if NET6_0_OR_GREATER
var characterIndex = (int)_layoutManager.GetCharacterIndex
(pointInTextContainer, _layoutManager.TextContainers.FirstOrDefault(), out partialFraction);
#else
#pragma warning disable CS0618 // Type or member is obsolete (For VS2017 compatibility)
var characterIndex = (int)_layoutManager.CharacterIndexForPoint(pointInTextContainer, _layoutManager.TextContainers.FirstOrDefault(), ref partialFraction);
var characterIndex = (int)_layoutManager.CharacterIndexForPoint
(pointInTextContainer, _layoutManager.TextContainers.FirstOrDefault(), ref partialFraction);
#pragma warning restore CS0618 // Type or member is obsolete
#endif


return characterIndex;
}
Expand Down
23 changes: 20 additions & 3 deletions src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.macOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ public override void DrawRect(CGRect rect)
// While DrawBackgroundForGlyphRange will draw the background mark for specified Glyphs DrawGlyphsForGlyphRange will draw the actual Glyphs.

// Note: This part of the code is called only under very specific situations. For most of the scenarios DrawString is used to draw the text.
_layoutManager?.DrawGlyphsForGlyphRange(new NSRange(0, (nint)_layoutManager.NumberOfGlyphs), _drawRect.Location);
#if NET6_0_OR_GREATER
_layoutManager?.DrawGlyphs
#else
_layoutManager?.DrawGlyphsForGlyphRange
#endif
(new NSRange(0, (nint)_layoutManager.NumberOfGlyphs), _drawRect.Location);
}
else
{
Expand Down Expand Up @@ -366,7 +371,13 @@ private Size LayoutTypography(Size size)
_textContainer.Size = size;
// Required for GetUsedRectForTextContainer to return a value.
_layoutManager.GetGlyphRange(_textContainer);
return _layoutManager.GetUsedRectForTextContainer(_textContainer).Size;
return _layoutManager
#if NET6_0_OR_GREATER
.GetUsedRect
#else
.GetUsedRectForTextContainer
#endif
(_textContainer).Size;
}
else
{
Expand All @@ -390,9 +401,15 @@ private int GetCharacterIndexAtPoint(Point point)
var partialFraction = (nfloat)0;
var pointInTextContainer = new CGPoint(point.X - _drawRect.X, point.Y - _drawRect.Y);

#if NET6_0_OR_GREATER
var characterIndex = (int)_layoutManager.GetCharacterIndex
(pointInTextContainer, _layoutManager.TextContainers.FirstOrDefault(), out partialFraction);
#else
#pragma warning disable CS0618 // Type or member is obsolete (For VS2017 compatibility)
var characterIndex = (int)_layoutManager.CharacterIndexForPoint(pointInTextContainer, _layoutManager.TextContainers.FirstOrDefault(), ref partialFraction);
var characterIndex = (int)_layoutManager.CharacterIndexForPoint
(pointInTextContainer, _layoutManager.TextContainers.FirstOrDefault(), ref partialFraction);
#pragma warning restore CS0618 // Type or member is obsolete
#endif

return characterIndex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,16 @@ private UnoCoreAnimation CreateCoreAnimation(
private NSValue ToCASkewTransform(float angleX, float angleY)
{
var matrix = CGAffineTransform.MakeIdentity();
matrix.yx = (float)Math.Tan(MathEx.ToRadians(angleY));
matrix.xy = (float)Math.Tan(MathEx.ToRadians(angleX));
var b = (float)Math.Tan(MathEx.ToRadians(angleY));
var c = (float)Math.Tan(MathEx.ToRadians(angleX));

#if NET6_0_OR_GREATER
matrix.B = b;
matrix.C = c;
#else
matrix.yx = b;
matrix.xy = c;
#endif

return NSValue.FromCATransform3D(CATransform3D.MakeFromAffine(matrix));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Media/ImageSource.macOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private void DownloadUsingPlatformDownloader()

#pragma warning disable CS0618
// fallback on the platform's loader
using (var data = NSData.FromUrl(url, NSDataReadingOptions.Coordinated, out error))
using (var data = NSData.FromUrl(url, NSDataReadingOptions.Mapped, out error))
#pragma warning restore CS0618
{
if (error != null)
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UWP/ApplicationModel/Contacts/ContactPicker.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public partial class ContactPicker
private async Task<Contact[]> PickContactsAsync(bool multiple, CancellationToken token)
{
var window = UIApplication.SharedApplication.KeyWindow;
var controller = window.RootViewController;
var controller = window?.RootViewController;
if (controller == null)
{
throw new InvalidOperationException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ void Start()
private class PresentationContextProviderToSharedKeyWindow : NSObject, IASWebAuthenticationPresentationContextProviding
{
#if __IOS__
public UIWindow GetPresentationAnchor(ASWebAuthenticationSession session) => UIApplication.SharedApplication.KeyWindow;
public UIWindow GetPresentationAnchor(ASWebAuthenticationSession session) => UIApplication.SharedApplication.KeyWindow!;
#else
public NSWindow GetPresentationAnchor(ASWebAuthenticationSession session) => NSApplication.SharedApplication.KeyWindow;
public NSWindow GetPresentationAnchor(ASWebAuthenticationSession session) => NSApplication.SharedApplication.KeyWindow!;
#endif
}

Expand Down

0 comments on commit dee6870

Please sign in to comment.