SystemNotification is lets you mimic the native iOS system notification in your SwiftUI apps.

Overview

SystemNotification


Version Platform Swift 5.3 MIT License Twitter: @danielsaidi

About SystemNotification

SystemNotification is lets you mimic the native iOS system notification (that is presented when e.g. toggling silent mode on and off) in your SwiftUI apps.

The result can look like this...or completely different:

These notifications have a default style, but can be customized to fit your specific app.

Installation

Swift Package Manager

https://github.com/danielsaidi/SystemNotification.git

CocoaPods

pod SystemNotification

Getting started

SystemNotification contains a SystemNotification view, that can be created with an isActive binding, an optional configuration and a custom view.

For instance:

let notification = SystemNotification(
    isActive: $isNotificationActive,
    configuration: SystemNotification.Configuration(edge: .bottom)) { _ in
        SystemNotificationMessage(
            icon: Image(systemName: "exclamationmark.triangle"), 
            title: "Alert", 
            text: "Something happened!",
            configuration: SystemNotificationMessage.Configuration(
                iconColor: .red
            )
        )
    }

You can use any view you like in the notification, but if you want to use the standard SystemNotificationMessage, you can just use this shorthand:

let notification = SystemNotification(
    icon: Image?,
    title: String,
    text: String,
    isActive: $isNotificationActive,
    configuration: SystemNotification.Configuration(edge: .bottom)) { isActive in
        SystemNotificationMessage(
            icon: Image(systemName: "exclamationmark.triangle"), 
            title: "Alert", 
            text: "Something happened!",
            configuration: SystemNotificationMessage.Configuration(
                iconColor: .red
            )
        )
    }

Once you have a notification, you can add it to any view, using the systemNotification modifier:

List(items)ย { item
   HStack { item.name }
}.systemNotification(notification)

The notification will be added above the view and docked outside of to the selected edge. When the isActive binding is set to true, it will slide in using the selected animation.

You can also use a SystemNotificationContext to easily present multiple notifications with a single systemNotification modifier:

let context = SystemNotificationContext()
context.present(notification1)
context.present(notification2)

// To use it, provide it instead of an `isActive` binding:
List(items)ย { item
   HStack { item.name }
}.systemNotification(context: context)

SystemNotification.Configuration

A SystemNotification can be configured with a SystemNotification.Configuration that specifies:

  • animation
  • backgroundColor
  • cornerRadius
  • edge
  • minWidth
  • duration
  • shadowRadius

You can customize these properties to control how the notification looks and behaves.

The default configuration makes the notification look and behave like the native one.

SystemNotificationMessage.Configuration

A SystemNotificationMessage view can be configured with a SystemNotificationMessage.Configuration instance that specifies:

  • iconColor
  • iconFont
  • padding
  • textColor
  • textFont
  • titleColor
  • titleFont

You can customize these properties to control how the notification message looks.

The default configuration makes the message look like the native one.

Demo app

This repo contains a basic demo app that demonstrates how to use the bottom sheet.

Just open the Demo project and run the app.

Contact me

Feel free to reach out if you have questions or if you want to contribute in any way:

License

SystemNotification is available under the MIT license. See LICENSE file for more info.

Comments
  • SystemNotification pops NavigationView if the user has navigated to a child view before the animation finishes

    SystemNotification pops NavigationView if the user has navigated to a child view before the animation finishes

    Environment:

    • SystemNotification v0.5.0
    • Xcode 13 with project targeting iOS 15.x

    It's most likely that I am doing something wrong here, but I am at a dead end, hence posing the question here. If it turns out to be something I am doing then it will be something good to make a note of and make it available as part of the documentation.

    My view somewhat looks like this

    ScrollView {
        ... deleted for simplicity
    }
    .navigationTitle("Title")
    .toolbar {
        /**
            Settings for the Controller
            */
        Button(action: {
            self.sheetContext.present(ControllerSettingsView())
        }) {
            Image(systemName: "gear")
        }
    }
    .onAppear {
        if (self.isFirstRun) {
            // Show a notification with the status
            self.showZoneStatusNotification()
            // Invalidate first run
            self.isFirstRun = false
        }
    }
    .onDisappear {
        // Stop the notification if the user flicks back
        // or forth from the view, if this isn't done you see
        // the notification even if the view is no longer active
        if(self.notificationContext.isActive) {
            self.notificationContext.dismiss()
        }
    }
    

    and is displayed in a NavigationView, the function that calls SystemNotification looks like

    private func showZoneStatusNotification() {
        if let status = self.sprinklerController.status {
            let statusNotification = SystemNotificationMessage(
                icon: Image(systemName: (status.online ? "checkmark.circle.fill":"bell.slash.fill")),
                title: "Title_ControllerHealth",
                text: status.summary!,
                configuration: .init(iconColor: (status.online ? .green:.red))
            )
            self.notificationContext.present(content: statusNotification)
        }
    }
    

    The notificationContext is bound to the NavigationView

    NavigationView {
        ControllerPickerView(
            sheetContext: self.sheetContext,
            notificationContext: self.notificationContext)
    }
    .navigationViewStyle(.automatic)
    .systemNotification(self.notificationContext)
    .sheet(context: self.sheetContext)
    

    and it's reference passed down to the children as a @StateObject. Note that I do use SwiftUIKit and the modifier follows the .systemNotification modifier (which i wouldn't think would be causing the issue).

    Video demo, I can make available the source and the app via TestFlight if it's of any use:

    opened by devraj 6
  • Fails to compile for macOS

    Fails to compile for macOS

    I just integrated the library as a Swift packing into a macOS project, and it fails to compile since the InsetGroupedListStyle being used in not available in macOS.

    Screenshot 2021-06-12 at 2 04 53 AM

    I think this needs a platform check :)

    opened by biocross 5
  • Type 'UIColor' has no member 'secondarySystemBackground'

    Type 'UIColor' has no member 'secondarySystemBackground'

    Getiing an error in private extension SystemNotification while compiling it for WatchOS with SwiftUI: Type 'UIColor' has no member 'secondarySystemBackground'

    bug 
    opened by 29satnam 1
  • Adjust the standard message dark mode appearance

    Adjust the standard message dark mode appearance

    The standard notification message needs som tweaks in dark mode.

    This is the library message:

    image

    while the native one looks like this:

    image

    The background and the message must become a little brighter.

    adjustment 
    opened by danielsaidi 1
  • Simplify presenting multiple notifications with a single modifier

    Simplify presenting multiple notifications with a single modifier

    This library should support presenting multiple types of messages with a single modifier. You can already do this today, by creating an observable object and let it specify the icon title and text, but I want this to be build into the library.

    opened by danielsaidi 0
  • Delayed presentations

    Delayed presentations

    Since we may want to present a notification when a screen is being presented, it would make sense to have the possibility to show the notification after a certain time interval.

    feature 
    opened by danielsaidi 0
  • SystemNotification shows on top of the parent as opposed to the currently presented Modal view

    SystemNotification shows on top of the parent as opposed to the currently presented Modal view

    This is again more a discussion than a bug report

    I am using SystemNotification and AlertContext and SheetContext from SwiftUIKit and they are configured on a NavigationView as such

        var body: some View {
            NavigationView {
                ControllerPickerView()
                    .environmentObject(self.sheetContext)
                    .environmentObject(self.notificationContext)
                    .environmentObject(self.alertContext)
            }
            .navigationViewStyle(.automatic)
            .alert(context: self.alertContext)
            .sheet(context: self.sheetContext)
            .systemNotification(self.notificationContext)
    }
    

    All works well when the Children call the Sheet, Alert or SystemNotification until I present a sheet

        private func showControllerSettings() {
            let controllerSettings = ControllerSettingsView(sprinklerController:
                                                                self.sprinklerController)
                                        .environmentObject(self.sheetContext)
                                        .environmentObject(self.alertContext)
                                        .environmentObject(self.notificationContext)
            self.sheetContext.present(controllerSettings)
        }
    

    if I raise a SystemNotification from the Modal, the notification does show but on the ControllerPicker view i.e behind the Modal view. This is the case for AlertContext as well, where it essentially does not show the Alert when triggered from the Modal.

    The modal does have a NavigationView (not sure if this has an effect)

    The only way I can get the SystemNotification to show is to apply the .systemNotification modifier to the NavigationView in the modal, resulting in something like this:

    IMG_2B1DE0155256-1

    I am wondering if this is the expected behaviour and if not what might I be configuring incorrectly to use SystemNotification from in a Modal

    opened by devraj 1
Releases(0.5.3)
  • 0.5.3(Sep 7, 2022)

    ๐Ÿ’ก Behavior changes

    • SystemNotificationContext present now has an optional configuration.
    • SystemNotificationContext now uses its own configuration if none is provided.
    Source code(tar.gz)
    Source code(zip)
  • 0.5.2(Jul 6, 2022)

  • 0.5.1(Jul 6, 2022)

  • 0.5.0(Jan 21, 2022)

    This release greatly improves how notifications are presented and dismissed and simplifies usage.

    The demo app now uses a local package, which makes it a lot easier to develop the library.

    ๐Ÿ“– Documentation

    SystemNotification has a brand new DocC documentation.

    Due to the new documentation, the package now requires Swift 5.5.

    โœจ New features

    • SystemNotificationContext has a new completion-based dismiss function.
    • SystemNotificationMessageConfiguration has new iconTextSpacing and titleTextSpacing properties.
    • SystemNotificationUIKitOverlay is a new view that simplifies adding a system notification to a UIKit view.
    • View+SystemNotification has a new parameter-based extension that replaces the old notification-based one.

    ๐Ÿ’ก Behavior changes

    • SystemNotificationMessageConfiguration is adjusted to make a message look more like an iPhone system notification.
    • Presenting a new notification first dismisses the current notification, if any.
    • The auto-dismiss logic is moved from the system notification to the notification context.

    ๐Ÿ› Bug fixes

    • This version fixes a bug, where the message configuration padding was incorrectly applied.

    ๐Ÿ—‘ Deprecated

    • The notification-based systemNotification(:) function is deprecated.

    ๐Ÿ’ฅ Breaking changes

    • SystemNotification+Message has been deprecated.
    • SystemNotificationConfiguration minWidth is no longer used and has been removed.
    • View+SystemNotification has deprecated the SystemNotification-based extension.
    Source code(tar.gz)
    Source code(zip)
  • 0.4.3(Sep 15, 2021)

    โœจ New features

    • SystemNotificationConfiguration has a new isSwipeToDismissEnabled parameter.
    • SystemNotification can now be swiped to be dismissed, if isSwipeToDismissEnabled is true.
    Source code(tar.gz)
    Source code(zip)
  • 0.4.2(Sep 13, 2021)

  • 0.4.1(Sep 13, 2021)

  • 0.4.0(Aug 4, 2021)

    โœจ New features

    • The context-based view modifier no longer requires a context parameter name.

    ๐Ÿ—‘ Deprecated

    • systemNotification(context:) is deprecated.

    ๐Ÿ› Bug fixes

    • This version fixes a bug, where the configuration duration wasn't applied.
    • This version fixes a bug, where the default dark mode background was transparent.
    Source code(tar.gz)
    Source code(zip)
  • 0.3.2(Jun 15, 2021)

  • 0.3.1(Jun 8, 2021)

    Thanks to Christian Mitteldorf, system notifications now use localized string keys, which makes it super simple to create localized notifications. The demo is updated with an example.

    Source code(tar.gz)
    Source code(zip)
  • 0.3.0(Jun 4, 2021)

    This release has some breaking name changes and makes it easier to present multiple notifications with a single modifier.

    โœจ New features

    • SystemNotificationContext makes it easy to present multiple notifications with a single modifier.

    ๐Ÿ’ฅ Breaking changes

    • SystemNotification.Configuration has been renamed to SystemNotificationConfiguration
    • SystemNotificationMessage.Configuration has been renamed to SystemNotificationMessageConfiguration
    Source code(tar.gz)
    Source code(zip)
  • 0.2.0(Jun 2, 2021)

    This release improves platform supports, adds convenience utils and tweaks design.

    โœจ New features

    • The library now supports macOS, tvOS and watchOS as well.
    • SystemNotification.Configuration has new shadow properties.

    ๐Ÿ’ก Behavior changes

    • The configuration types are no longed nested, to avoid generic limitations.

    ๐ŸŽจ Design changes

    • SystemNotification.Configuration has removed the background opacity modifier.
    • SystemNotification.Configuration has now applies a more subtle standard shadow.
    • SystemNotificationMessage.Configuration now uses title3 as standard icon font.

    ๐Ÿ› Bug fixes

    • The corner radius now works even when no image is provided.
    Source code(tar.gz)
    Source code(zip)
  • 0.1.0(Jun 1, 2021)

Owner
Daniel Saidi
Freelance software engineer with focus on mobile products and Apple platforms like iOS, tvOS and watchOS.
Daniel Saidi
OS X and iOS application and framework to play with the Apple Push Notification service (APNs)

Pusher OS X and iOS application and framework to play with the Apple Push Notification service (APNs) Installation Install the Mac app using Homebrew

noodlewerk 6.2k Dec 22, 2022
FNotify - Notification Library For iOS

FNotify Notification Library For IOS FNotify.mov Requirements: xcode 12+ swift 5

Frameworks 1 Jan 9, 2022
Add the 'Hide Notification Badges' Focus mode setting from iOS to macOS

FocusPlsNoBadges Add the 'Hide Notification Badges' Focus mode setting from iOS to macOS, in a really gross and hacky way. Getting started Build the X

Ayden Panhuyzen 18 Dec 14, 2022
Chanify is a safe and simple notification tools. This repository is iOS clinet for Chanify.

Chanify English | ็ฎ€ไฝ“ไธญๆ–‡ Chanify is a safe and simple notification tools. For developers, system administrators, and everyone can push notifications wit

Chanify 156 Jan 4, 2023
SNPnotificationBar - Notification Bar for ios

SNPnotificationBar Screenshot Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements S

Ahmad Almasri 7 Nov 20, 2019
๐Ÿคจ Apple Push Notification service tutorial

APNsTutorial-iOS ?? Apple Push Notification service tutorial ๋‹จ์ˆœํžˆ ์ˆœ์„œ๋ฅผ ๋”ฐ๋ผ์„œ ๊ฐ€๋ฉด ๋  ์ค„ ์•Œ์•˜๋Š”๋ฐ ์•Œ์•„์•ผํ•  ๊ฒƒ๋„ ์žˆ์—ˆ๊ณ  ๊ฒฝ์šฐ์— ๋”ฐ๋ผ์„œ ์š”๊ตฌํ•˜๋Š” ํŒŒ์ผ๋„ ๋‹ฌ๋ž๋‹ค. ๊ทธ๋Ÿฌ๋‹ˆ ์ฒœ์ฒœํžˆ ์ฝ์–ด์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค. ๋จผ์ € ์–ด๋–ค ์„œ๋ฒ„ ํ™˜๊ฒฝ

Hyungyu Kim 11 Dec 28, 2022
How to Add Local Push Notification With timeInterval & Test On Simulator

Technicalisto How to Add Local Push Notification With timeInterval & Test On Simulator In Project Target ( Signing & Capapilities ) Add Capapility : 1

Aya Baghdadi 0 Jun 24, 2022
Custom notification view

Custom notification view

Ivan Kopiev 2 Sep 15, 2022
OS X app for sending push with Apple Push Notification service (APNs)

pushHandle OS X app for sending push with Apple Push Notification service (APNs) About This app was created just to allow painless testing of push not

hbk3 3 Nov 17, 2022
The debug application for Apple Push Notification Service (APNs).

Knuff The debug application for Apple Push Notification Service (APNs). Download the latest version Features Send push notifications to APNS (Apple Pu

Knuff 5.2k Dec 26, 2022
APNSUtil is makes code simple using apple push notification service

APNSUtil APNSUtil makes code simple settings and landing for apple push notification service. Features Using apple push notification service simply No

Steve Kim 30 Mar 24, 2022
Roar - Let's reskin Notification Center

Roar Let's reskin Notification Center. See this blog post. Thanks Big thanks to

Tyler Hall 8 Mar 15, 2022
ToDoAppCoreData - MVVM + Core Data + Local Notification

ToDo App Features MVVM + Core Data + Local Notification Screen recordings Creadi

Watery Desert 22 Nov 28, 2022
A Swift Library for Dynamic Island Push Notification.

Push Notification With Dynamic Island Handle Push Notification with Dynamic Island ?? Descreption: Since there is not library for Apple Push Notificat

Amir Diafi 5 Nov 12, 2022
Joseph Miller 0 Jan 7, 2022
Gently notifies you about 'important' GitHub notifications

OctoBlast Gently notifies you about important GitHub notifications Setup Personal access token Head to preferences, and pop in your a new GitHub perso

Jason Watson 6 Nov 14, 2022
See all your scheduled local notifications in one place

ScheduledNotificationsViewController Nice Photon is available for hire! Talk to

Nice Photon 171 Oct 8, 2022
A fully customizable library to easily display Animated Toast Messages in iOS using Swift!

CustomToastView-swift A fully customizable library to easily display Animated Toast Messages in iOS using Swift! Preview - All the custom toasts you c

Leticia Rodriguez 13 Aug 20, 2022
Library to send mock remote notifications to the iOS simulator

SimulatorRemoteNotifications SimulatorRemoteNotifications is a library to send mock remote notifications to the iOS simulator. The library extends UIA

Arnaud Coomans 1.4k Dec 20, 2022