Skip to content

Fix Breaking Changes Introduced in .NET MAUI Preview 14#325

Merged
TheCodeTraveler merged 5 commits intomainfrom
fix-warnings
Mar 17, 2022
Merged

Fix Breaking Changes Introduced in .NET MAUI Preview 14#325
TheCodeTraveler merged 5 commits intomainfrom
fix-warnings

Conversation

@VladislavAntonyuk
Copy link
Copy Markdown
Contributor

@VladislavAntonyuk VladislavAntonyuk commented Mar 15, 2022

Description of Change

  1. .NET MAUI Preview 14
  2. Update deprecated APIs to remove warnings like obsolete Device api

Linked Issues

  • Fixes #

PR Checklist

Additional information

Comment thread samples/CommunityToolkit.Maui.Sample/CommunityToolkit.Maui.Sample.csproj Outdated
Comment thread samples/CommunityToolkit.Maui.Sample/MauiProgram.cs
Comment thread src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj
Comment thread src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj Outdated
Comment thread src/CommunityToolkit.Maui.Core/Views/Alert/AlertView.macios.cs
Comment thread src/CommunityToolkit.Maui/CommunityToolkit.Maui.csproj Outdated
Comment thread src/CommunityToolkit.Maui/CommunityToolkit.Maui.csproj Outdated
@VladislavAntonyuk VladislavAntonyuk force-pushed the fix-warnings branch 2 times, most recently from 87b2d80 to cdf2e74 Compare March 15, 2022 11:46
Comment thread Directory.Build.props Outdated
@VladislavAntonyuk VladislavAntonyuk marked this pull request as ready for review March 15, 2022 18:40
Comment thread src/CommunityToolkit.Maui.Core/Views/PaddedButton.macios.cs Outdated
@VladislavAntonyuk VladislavAntonyuk force-pushed the fix-warnings branch 2 times, most recently from 48df87d to 0abeb86 Compare March 16, 2022 14:39
Comment thread src/CommunityToolkit.Maui/Alerts/Snackbar/Snackbar.windows.cs Outdated
@VladislavAntonyuk VladislavAntonyuk changed the title [Proposal] Update deprecated APIs to fix warnings [Preview 14] Update deprecated APIs to fix warnings Mar 16, 2022
Comment thread src/CommunityToolkit.Maui/Alerts/Toast/Toast.windows.cs Outdated
@VladislavAntonyuk VladislavAntonyuk changed the title [Preview 14] Update deprecated APIs to fix warnings Preview 14 Mar 16, 2022
Copy link
Copy Markdown
Collaborator

@TheCodeTraveler TheCodeTraveler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Vlad!!

Hopefully this'll be the last time we have to update nfloat 😅

And thanks for fixing our typos!!

Comment thread samples/CommunityToolkit.Maui.Sample/Pages/Base/BaseGalleryPage.cs
Comment on lines +18 to +22
public UIView ParentView => UIApplication.SharedApplication.ConnectedScenes.ToArray()
.Where(x => x.ActivationState == UISceneActivationState.ForegroundActive)
.Select(x => x as UIWindowScene)
.FirstOrDefault()?
.Windows.FirstOrDefault(x => x.IsKeyWindow) ?? throw new NullReferenceException("KeyWindow is not found");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just use .First() since it's the same as .FirstOrDefault() ?? throw new NullReferenceException()

Suggested change
public UIView ParentView => UIApplication.SharedApplication.ConnectedScenes.ToArray()
.Where(x => x.ActivationState == UISceneActivationState.ForegroundActive)
.Select(x => x as UIWindowScene)
.FirstOrDefault()?
.Windows.FirstOrDefault(x => x.IsKeyWindow) ?? throw new NullReferenceException("KeyWindow is not found");
public UIView ParentView => UIApplication.SharedApplication.ConnectedScenes.ToArray()
.Where(x => x.ActivationState == UISceneActivationState.ForegroundActive)
.Select(x => x as UIWindowScene)
.First()
.Windows.First(x => x.IsKeyWindow);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, another idea (and maybe this one is better because it'll help users more easily track down the Exception), we throw InvalidOperationException:

Suggested change
public UIView ParentView => UIApplication.SharedApplication.ConnectedScenes.ToArray()
.Where(x => x.ActivationState == UISceneActivationState.ForegroundActive)
.Select(x => x as UIWindowScene)
.FirstOrDefault()?
.Windows.FirstOrDefault(x => x.IsKeyWindow) ?? throw new NullReferenceException("KeyWindow is not found");
public UIView ParentView => UIApplication.SharedApplication.ConnectedScenes.ToArray()
.Where(x => x.ActivationState == UISceneActivationState.ForegroundActive)
.Select(x => x as UIWindowScene)
.FirstOrDefault()?
.Windows.FirstOrDefault(x => x.IsKeyWindow) ?? throw new InvalidOperationException("KeyWindow is not found");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this ToArray call?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the type of ConnectedScenes is NSSet<UIScene> and doesn't support Linq

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot use First() because we cast to UIWindowsScene and still need to check for null. I will change it to InvalidOperationException

Comment thread src/CommunityToolkit.Maui.Core/Views/Alert/AlertView.macios.cs
Comment thread src/CommunityToolkit.Maui.Core/Views/PaddedButton.macios.cs Outdated
Comment thread src/CommunityToolkit.Maui.Core/Views/PaddedLabel.macios.cs Outdated
Comment thread samples/CommunityToolkit.Maui.Sample/MauiProgram.cs Outdated
Comment thread samples/CommunityToolkit.Maui.Sample/MauiProgram.cs Outdated
Comment thread src/CommunityToolkit.Maui/HandlerImplementation/Popup/Popup.windows.cs Outdated
Comment thread src/CommunityToolkit.Maui/Views/WrapperControl.windows.cs Outdated
Comment thread src/CommunityToolkit.Maui/Views/WrapperControl.windows.cs Outdated
Comment thread samples/CommunityToolkit.Maui.Sample/MauiProgram.cs
@TheCodeTraveler
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Copy Markdown
Collaborator

@TheCodeTraveler TheCodeTraveler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Vlad!!

@TheCodeTraveler TheCodeTraveler enabled auto-merge (squash) March 17, 2022 15:59
@TheCodeTraveler TheCodeTraveler merged commit 1f00f20 into main Mar 17, 2022
@delete-merged-branch delete-merged-branch bot deleted the fix-warnings branch March 17, 2022 16:19
@TheCodeTraveler TheCodeTraveler changed the title Preview 14 Fix Breaking Changes Introduced in .NET MAUI Preview 14 Mar 17, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Nov 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants