:rotating_light: Attention Kotlin developers! Knot...
# feed
u
🚨 Attention Kotlin developers! Knotify is now Compose Native Notification! 🚀 This experimental multiplatform library lets you seamlessly add notifications across Android, Windows, and Linux, directly into your Compose Multiplatform apps! 🎉 Compose Native Notification uses a declarative approach with support for interactive callbacks on compatible platforms. Say goodbye to boilerplate code and hello to streamlined cross-platform notifications! Here’s a quick example of an interactive notification with an image and a button:
Copy code
Notification(
    title = "Hello Kotlin!",
    message = "This is a cross-platform notification :rocket:",
    largeImage = Res.getUri("drawable/notification_image.png"),
    onActivated = { Log.d("NotificationLog", "Notification activated!") },
    onDismissed = { reason -> Log.d("NotificationLog", "Notification dismissed: $reason") }
) {
    Button("Click Me!") {
        Log.d("NotificationLog", "Callback received with zero boilerplate!")
    }
}
Get started with Compose Native Notification today and bring smooth, interactive notifications to your multiplatform projects: https://github.com/kdroidFilter/ComposeNativeNotification 🚀 We can’t wait for your feedback!
kodee happy 6
K 5
🚀 3
a
awesome to see a notification library. i don't see a way to dismiss notifications. is that possible or planned? quick feedback on the api: from a first look, i thought that
Notification()
was a composable, but it's not. very odd choice to see composable looking code on a click listener, especially because i cannot really do much with it (ie set custom text or use my own composable in it)
u
That is to say? to make the notification disappear? if yes it is planned
👍 1
No it's not a composable since it's a native element that is created and is different for each platform, it's true that it may seem strange but it seemed intuitive to me to send notifications this way since ultimately it is a graphic element that is created However I don't understand what you mean by I can't do much with it, what could you do in a notification?
After as I wrote it is only a test and the api will surely change, I await feedbacks for that
a
No it's not a composable since it's a native element
composables are about kotlin code, not the underlying tech they use to render ui. glance for example is still composables but internally does the rending using android remoteviews which are 'antive elements'.
what could you do in a notification?
it not about what to do with a notification, but what can i do with composables. if it looks like a composable, i expect it to work as a composable (such as using my own components, such as Text(), animate colors as states etc)
u
I understand what you are saying, but what do you mind for example in my library to display a tray system? Does this bother you too?
Copy code
Tray(
        iconPath = iconPath,
        windowsIconPath = windowsIconPath,
        tooltip = "My Application",
        primaryAction = {
            Log.i(logTag, "Primary action triggered")
        },
        primaryActionLinuxLabel = "Open Application"
    ) {
        SubMenu(label = "Options") {
            Item(label = "Setting 1") {
                Log.i(logTag, "Setting 1 selected")
            }
            SubMenu(label = "Advanced Sub-options") {
                Item(label = "Advanced Option 1") {
                    Log.i(logTag, "Advanced Option 1 selected")
                }
                Item(label = "Advanced Option 2") {
                    Log.i(logTag, "Advanced Option 2 selected")
                }
            }
        }



        Item(label = "Exit", isEnabled = true) {
            Log.i(logTag, "Exiting the application")
            dispose()
            exitProcess(0)
        }

        Item(label = "Version 1.0.0", isEnabled = false)
    }
and otherwise what do you suggest? to rename the function to sendNotification() for example?
a
is that compose?
u
no
a
I don't know what I am looking at then, so it's confusing
u
because that's almost how jetbrains originally did it for the system tray https://github.com/JetBrains/compose-multiplatform/tree/master/tutorials/Tray_Notifications_MenuBar_new
a
what you linked (the jetbrains link) is compose
u
we cannot at all apply to these elements what we are used to with compose, neither text, nor modifier nor anything at all
a
the important bit here is that is a library for compose. i know how it works (ie composition) how to show/hide stuff.
if u are building for compose, providing composables etc makes sense. if you are not building a library for compose, the whole 'making it look like compose while it isn't', it's an author choice. doesn't let people understand how the library works. that's the confusing part
u
the important bit here is that is a library for compose. i know how it works (ie composition) how to show/hide stuff.
for my tray system, I planned that we could recompose it as we are used to, it will arrive soon. on the other hand for notifications, at the beginning I had called it Knotify, but as I had to integrate the shared resources of compose to create a unified api with android, I renamed it to compose native notification, but it is true that it was perhaps a mistake. Thank you very much in any case, but what would you advise me concretely?
Because for now, the notifications are static, however, later, I want to integrate components like the progressbar or media player notifications, and I plan to make them recompose as we do with compose. I don't know yet exactly how I'm going to do it though
a
what would you advise me concretely
advise about what exactly?
u
well you said that my library was confusing, what do you advise me to make it more intuitive?
a
my feedback was the api was confusing. either build on top of compose, or don't. right now it looks like compose but it isn't
👍 1
a
whoa this is killer, nice job!
😅 1
👀 1
s
This looks great, but I agree with @Alex Styl about the API design. These functions look a lot like
@Composable
functions (whether they emit UI or not doesn't matter). The stuff JetBrains did for the system tray on desktop were actual
@Composable
functions! Ones that responded to state changes, disappeared when the functions left the composition, etc... Your library functions aren't, but they follow the Compose naming conventions, and are imperative (not declarative) in nature. The DSL is awesome, just make e.g. function names
camelCase
instead of
PascalCase
, and clearly name imperative functions as such (e,g,
button
is a declarative function, it just declares that we want a button, but
notification
is imperative, it immediately runs side effects to show the notification). You could for example have a
notification
/
createNotification
function that simply returns a
Notification
class, but isn't sent immediately, until we call some sort of
send()
function. That would also make hiding notifications very easy, take the same object and call
hide()
. For the one you currently have, rename it to
sendNotification
(that takes a lambda as usual), which will send the notification immediately. Here's how this would look like:
u
@Skaldebane Thank you very much for the feedback, nothing to say, I agree with you 100%. I will do this next week