Skip to content

SnackBar - #5

Merged
TheCodeTraveler merged 38 commits into
CommunityToolkit:mainfrom
VladislavAntonyuk:vantonyuk/snackbar
Nov 27, 2021
Merged

TheCodeTraveler merged 38 commits into
CommunityToolkit:mainfrom
VladislavAntonyuk:vantonyuk/snackbar

Conversation

@VladislavAntonyuk

@VladislavAntonyuk VladislavAntonyuk commented Jul 29, 2021 •

Copy link
Copy Markdown
Contributor

Fix #118

Platform Default setings Custom visual options
Android image image
iOS/MacCatalyst image image

@VladislavAntonyuk
VladislavAntonyuk marked this pull request as ready for review July 29, 2021 15:39
Comment thread src/CommunityToolkit.Maui/Platforms/Android/Views/SnackBar.cs Outdated
@pictos

pictos commented Jul 30, 2021

Copy link
Copy Markdown
Member

Hey there, please wait until we define what we will migrate to this repo and how. If I'm not wrong this repo isn't even with the XCT

@VladislavAntonyuk VladislavAntonyuk mentioned this pull request Sep 28, 2021
10 tasks
@VladislavAntonyuk

Copy link
Copy Markdown
Contributor Author

@pictos, @jfversluis, @brminnick please review.

Comment thread src/CommunityToolkit.Maui/Extensions/VisualElementExtension.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Extensions/VisualElementExtension.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Extensions/VisualElementExtension.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Views/Snackbar/SnackBar.android.cs Outdated
Comment thread src/CommunityToolkit.Maui/Views/Snackbar/SnackBar.android.cs Outdated
@jfversluis

Copy link
Copy Markdown
Member

Hey @maxkoshevoi would you mind using the code review feature and post all comments at once instead of each one separately and killing my notifications? :)

thanks!

@maxkoshevoi

Copy link
Copy Markdown
Contributor

Hi @jfversluis, sorry about that! 😅
Will use it from now on.

Comment thread src/CommunityToolkit.Maui/Views/Snackbar/SnackBar.android.cs Outdated
Comment thread src/CommunityToolkit.Maui/Views/Snackbar/Options/ToastOptions.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Views/Snackbar/Options/ToastOptions.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Views/Snackbar/Options/SnackBarActionOptions.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Views/Snackbar/Options/ToastOptions.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Views/Snackbar/Options/MessageOptions.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Views/Snackbar/Helpers/NativeSnackButton.ios.macos.cs Outdated
@VladislavAntonyuk

Copy link
Copy Markdown
Contributor Author

@brminnick Could you please update the task requirements according to the discussion (Use native Snackbar/toast for Android and popup for other platforms)

@TheCodeTraveler

Copy link
Copy Markdown
Collaborator

Thanks for the reminder! I'll update the detailed design this weekend.

Just curious - would you then be closing this PR and splitting it into two separate PRs; one for SnackBar and one for Toast?

@VladislavAntonyuk

Copy link
Copy Markdown
Contributor Author

actually, snack bar and toast only differ with the action button. maybe I will update this PR with the snack bar implementation only and then add toast.

@TheCodeTraveler TheCodeTraveler left a comment

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.

Thanks Vlad!

Just some quick semantic feedback since it looks like you're still working on it 🙌

Comment thread src/CommunityToolkit.Maui/Extensions/VisualElementExtension.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Extensions/VisualElementExtension.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Extensions/VisualElementExtension.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Extensions/VisualElementExtension.shared.cs Outdated
@VladislavAntonyuk VladislavAntonyuk changed the title SnackBar/Toast Draft SnackBar/Toast Nov 21, 2021
@VladislavAntonyuk VladislavAntonyuk changed the title Draft SnackBar/Toast Draft SnackBar Nov 21, 2021
Comment thread samples/CommunityToolkit.Maui.Sample/Pages/Views/SnackBarPage.xaml.cs Outdated
@VladislavAntonyuk

Copy link
Copy Markdown
Contributor Author

@brminnick what do you think if we split this feature on parts based on Platforms? for example this PR is only for Android. In that case we can deliver the feature earlier. possibly receive some feedback.

@pictos pictos left a comment

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.

@VladislavAntonyuk Do you plan to implement it using the handler approach? Using property mapper and all that jazz?

Comment thread src/CommunityToolkit.Maui/Views/BasePopupView.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Views/BasePopupView.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Views/Snackbar/SnackBar.shared.cs Outdated
Comment thread samples/CommunityToolkit.Maui.Sample/CommunityToolkit.Maui.Sample.csproj Outdated
@TheCodeTraveler

Copy link
Copy Markdown
Collaborator

@brminnick what do you think if we split this feature on parts based on Platforms? for example this PR is only for Android.

I think it's important to include all platforms in the pull request. Excluding platforms adds complexity and confusion for the users.

Do you plan to implement it using the handler approach?

💯 All custom controls in the .NET MAUI toolkit must be done using Handlers. We made a commitment to the community that we would always use Handlers and no Renderers.

Comment thread src/CommunityToolkit.Maui/CommunityToolkit.Maui.csproj Outdated
Comment thread src/CommunityToolkit.Maui/Alerts/Snackbar/SnackBar.shared.cs Outdated

@TheCodeTraveler TheCodeTraveler left a comment •

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.

Thanks Vlad!

The Windows Sample didn't work on my machine. Can you double check that?
Edit: User error

We also need more unit tests to ensure we've covered every public API on Snackbar and ISnackbar.

I also recommend moving the UI elements in Popup.macos.ios.cs to PopupView.macos.ios.cs. This'll ensure that Popup contains the functionality for the popup (eg timer, duration, show/dismiss), and that PopupView contains all of the UI elements.

Video of Snackbar on Windows Sample App

Here's an update video of the Snackbar on Windows.

FYI - clicking the Action Button opens a new instance of the app:

ScreenFlow

Comment thread samples/CommunityToolkit.Maui.Sample.sln Outdated
Comment thread src/CommunityToolkit.Maui/Views/Popup/SnackBar/ISnackbar.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Views/Popup/SnackBar/NativePopup.ios.macos.cs Outdated
Comment thread src/CommunityToolkit.Maui.UnitTests/Alerts/SnackBar_Tests.cs
Comment thread src/CommunityToolkit.Maui/Alerts/Snackbar/Snackbar.windows.cs
Comment thread src/CommunityToolkit.Maui/Views/Popup/Popup.ios.macos.cs Outdated
Comment thread src/CommunityToolkit.Maui/Views/Popup/Popup.ios.macos.cs Outdated
Comment thread src/CommunityToolkit.Maui/Alerts/Snackbar/SnackBar.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Alerts/Snackbar/SnackBar.shared.cs Outdated
Comment thread src/CommunityToolkit.Maui/Alerts/Snackbar/SnackBar.shared.cs
Comment thread src/CommunityToolkit.Maui/Alerts/Snackbar/Snackbar.ios.macos.cs Outdated
Comment thread src/CommunityToolkit.Maui/Views/Popup/Popup.ios.macos.cs
Comment thread src/CommunityToolkit.Maui/Views/Toast/Toast.ios.macos.cs Outdated
TheCodeTraveler and others added 3 commits November 27, 2021 13:58
Update class names, fix padding on apple, attempt to fix winui
@pictos

pictos commented Nov 27, 2021 •

Copy link
Copy Markdown
Member

@brminnick does this PR implements the pop-up control from XCT or will be a pop-up version of snackbar?

@VladislavAntonyuk

VladislavAntonyuk commented Nov 27, 2021 •

Copy link
Copy Markdown
Contributor Author

@pictos, it is a based popup (not specific to snackbar). Just RoundedUIView.
It allows adding any Children. It can be used for Popup like Container.

@pictos

pictos commented Nov 27, 2021 •

Copy link
Copy Markdown
Member

@VladislavAntonyuk but this will be limited to one action, and a text message, right?

Since I was on vacation I probably lost something in the way, so I just to make sure that this doesn't obsolete the pop-up control

@TheCodeTraveler

Copy link
Copy Markdown
Collaborator

Yup! That Popup class is a base class for Snackbar (which is basically just a popup that only contains Text and a Button).

@pictos I recommend leveraging Popup.ios.macos.cs for your implementation of Popup.shared.cs. You're obviously welcome to tweak it for your implementation.

We'll be sure to check that the Snackbar still works properly when reviewing the Popup PR 💯

@VladislavAntonyuk

VladislavAntonyuk commented Nov 27, 2021 •

Copy link
Copy Markdown
Contributor Author

Popup class here is just a container. it doesn't contain any code specific to snackbar. PopupView class can be used as a container for any content
Snackbar is limited to 1 action and 1 message

@pictos

pictos commented Nov 27, 2021

Copy link
Copy Markdown
Member

@brminnick I'm working on porting our pop-up to handler. That will take me a few more days, and I'll share a draft PR when I have the android part done. That way we can talk as a team and talk how that should like.

I was just concerned if one will overlap other, but looks like that isn't true.

I'll take a depper look on this PR asap to be more familiar with the control and architecture

@TheCodeTraveler

Copy link
Copy Markdown
Collaborator

Looks good to me! Excellent job, @VladislavAntonyuk!!

@pictos Do you want to give this one more review before we merge it?

@pictos

pictos commented Nov 27, 2021

Copy link
Copy Markdown
Member

@brminnick no, we can merge it. And I can rebate against my branch and take a look there.

:shipit:

@TheCodeTraveler
TheCodeTraveler merged commit 9fd9d89 into CommunityToolkit:main Nov 27, 2021
@VladislavAntonyuk
VladislavAntonyuk deleted the vantonyuk/snackbar branch November 27, 2021 18:32
@emorell96

Copy link
Copy Markdown

Thanks Vlad!

The Windows Sample didn't work on my machine. Can you double check that? Edit: User error

We also need more unit tests to ensure we've covered every public API on Snackbar and ISnackbar.

I also recommend moving the UI elements in Popup.macos.ios.cs to PopupView.macos.ios.cs. This'll ensure that Popup contains the functionality for the popup (eg timer, duration, show/dismiss), and that PopupView contains all of the UI elements.

Video of Snackbar on Windows Sample App

Here's an update video of the Snackbar on Windows.

FYI - clicking the Action Button opens a new instance of the app:

ScreenFlow

Was this ever figured out? I am using snackbar source code as inspiration for a custom implementation but I have the same issue. The MAUI app will just create a new window.

@pictos

pictos commented Apr 9, 2022

Copy link
Copy Markdown
Member

@emorell96 if I'm not wrong the fix for this is comming (:

@emorell96

emorell96 commented Apr 9, 2022 •

Copy link
Copy Markdown

@pictos is it this?

protected override void OnLaunched(LaunchActivatedEventArgs args)

So basically if a new process is started, the idea is to kill it as it starts?

Do you know if the events available in UWP are available on MAUI? Usually on UWP you can just override the OnActivated and hook up there in order to handle the activation as shown here: https://docs.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/send-local-toast?tabs=uwp#step-3-handling-activation

And if it's different with MAUI, is it possible to use ToastNotificationManagerCompat.OnActivated as shown in the docs?

The reason I ask is that I was trying to get this to work with setting the activation type to Background but then the Activated event wouldn't trigger.

@pictos

pictos commented Apr 9, 2022

Copy link
Copy Markdown
Member

@VladislavAntonyuk do you know the answers for this?

@emorell96

Copy link
Copy Markdown

@VladislavAntonyuk do you know the answers for this?

I just wanted to share a little what I've discovered after quite a bit of experimentation. I thought it might be useful for your nuget.

On Windows there's two kind of activations for UWP apps: foreground and background. The former will use the current app but you need to modify the package.appxmanifext file if you want to use ToastNotificationManagerCompat.OnActivated. You must both modify the appxmanifest as indicated here in order to make this work without opening a new window. The background activation uses background tasks instead but they require the background tasks to be either registered as an In-Process background task or Out-of-Process background task as shown here.

For my use case the background task sounded ideal, but I was unable to make it work with MAUI (at least for the In-Process Background tasks). I kept getting argument out of range exception.

I might try the out-of-process background tasks later.

In any case, one way I found to solve this issue using the foreground activation (the one currently used here), you need to make this change to the package.appxmanifest:

in the Package element this needs to be added:

xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10" 
xmlns:com="http://schemas.microsoft.com/appx/manifest/com/windows10"
IgnorableNamespaces="uap rescap com desktop"

Inside of the applications:

<Applications>
    <Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$">
      <uap:VisualElements />
     <Extensions>

        <!-- Specify which CLSID to activate when toast clicked -->
        <desktop:Extension Category="windows.toastNotificationActivation">
          <desktop:ToastNotificationActivation ToastActivatorCLSID="guid-used-in-maui-csproj" /> 
        </desktop:Extension>

        <!--Register COM CLSID LocalServer32 registry key-->
        <com:Extension Category="windows.comServer">
          <com:ComServer>
            <com:ExeServer Executable="filename-used-for-the-exe-usually-the-assembly-name.exe" Arguments="-ToastActivated" DisplayName="Toast activator">
              <com:Class Id="guid-used-in-maui-csproj" DisplayName="Toast activator"/>
            </com:ExeServer>
          </com:ComServer>
        </com:Extension>

      </Extensions>
    </Application>
  </Applications>

Using $targetnametoken$.exe for the executable in com:ExeServer didn't work. I had to manually enter the assembly name.

Finally I register in the MauiProgram.cs the event:

using Microsoft.Toolkit.Uwp.Notifications;
builder.
... (every other build action)
.ConfigureLifecycleEvents(configure =>
            {
				configure.AddWindows(c =>
				{
					c.OnLaunched((window, args) =>
					{
						ToastNotificationManagerCompat.OnActivated += WindowsNotificationService.OnActivated;
					});
                });
            });

I made this minimal repo that works:
https://github.com/emorell96/MauiWithWindowsToasts

Hope it helps.

Thanks for the replies!

@pictos

pictos commented Apr 9, 2022

Copy link
Copy Markdown
Member

@emorell96 do you mind to open a issue and move the last post into it?

@emorell96

Copy link
Copy Markdown

@pictos done: #353

@github-actions github-actions Bot locked and limited conversation to collaborators Nov 23, 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.

[Proposal] Snackbar

6 participants