Skip to content

Add Platform-Specific Option to Enable Snackbar on Windows#1780

Merged
TheCodeTraveler merged 11 commits intomainfrom
Move-Snackbar-Initializion-Logic-to-Sample-App
Mar 29, 2024
Merged

Add Platform-Specific Option to Enable Snackbar on Windows#1780
TheCodeTraveler merged 11 commits intomainfrom
Move-Snackbar-Initializion-Logic-to-Sample-App

Conversation

@TheCodeTraveler
Copy link
Copy Markdown
Collaborator

Snackbar now requires additional code to be added on Windows to the Package.appxmanifest file: MicrosoftDocs/CommunityToolkit#374

Currently, without adding this additional code to Package.appxmanifest, CommunityToolkit.Maui causes all Windows apps to crash on launch.

This PR adds Options.ShouldEnableSnackbarOnWidows to allow users to opt-in to enabling Snackbar on Windows, ensuring that they have added the additional required code to Package.appxmanifest.

var builder = MauiApp.CreateBuilder()
  .UseMauiCommunityToolkit(options =>
  {
    options.SetShouldEnableSnackbarOnWindows(true);
  })

Comment thread src/CommunityToolkit.Maui/Options.cs Outdated
Copy link
Copy Markdown
Contributor

@bijington bijington left a comment

Choose a reason for hiding this comment

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

Good work @brminnick I think we should either use the value parameter or remove it though.

@TheCodeTraveler
Copy link
Copy Markdown
Collaborator Author

Thanks Shaun! Good catch. Updated ✅

Comment thread src/CommunityToolkit.Maui/Options.cs Outdated
Comment thread src/CommunityToolkit.Maui/Options.cs
Copy link
Copy Markdown
Collaborator Author

@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 Shaun + Vlad! I think I'm happy with the implementation now.

We've added enough fail-safes to the code to assist future devs who haven't yet seen the platform-specific implementation docs for Snackbar on Windows. Hopefully throwing these exceptions at runtime will help folks find the docs instead of opening a new Issue on the repo.

And if they do open an issue for one of these InvalidOperationExceptions, we can just copy/paste the link from the stack trace, point them to the docs and close the issue.

Comment thread src/CommunityToolkit.Maui/Alerts/Snackbar/Snackbar.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Options.cs
pictos
pictos previously approved these changes Mar 28, 2024
@TheCodeTraveler TheCodeTraveler merged commit 51dc63a into main Mar 29, 2024
@TheCodeTraveler TheCodeTraveler deleted the Move-Snackbar-Initializion-Logic-to-Sample-App branch March 29, 2024 02:13
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 20, 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.

4 participants