Coder Social home page Coder Social logo

uinotifications's Introduction

Features

  • Present your own custom view easily as an in-app Notification
  • Create custom presentation styles
  • Update content during presentation

Example

To run the example project, clone the repo, and open UINotifications-Example.xcodeproj from the Example directory.

Success styling Failure styling
Success Failure

Usage

Making a Notification

import UINotifications

let content = UINotificationContent(title: "My Custom Text", subtitle: "My subtitle", image: UIImage(named: "MyImage"))
let notification = UINotification(content: content, action: UINotificationCallbackAction(callback: {
    print("Tapped the notification!")
}))

let dismissTrigger = UINotificationDurationDismissTrigger(duration: 2.0)
UINotificationCenter.current.show(notification: notification, dismissTrigger: dismissTrigger)

Create a custom style

import UINotifications

enum NotificationStyle: UINotificationStyle {
    case success
    case failure
    
    var titleFont: UIFont {
        switch self {
        case .success:
            return .systemFont(ofSize: 15, weight: .semibold)
        case .failure:
            return .systemFont(ofSize: 13, weight: .regular)
        }
    }
    
    var subtitleFont: UIFont {
        return .systemFont(ofSize: 13, weight: .regular)
    }
    
    var titleTextColor: UIColor {
        switch self {
        case .success:
            return .black
        case .failure:
            return .white
        }
    }
    
    var subtitleTextColor: UIColor {
        return .darkGray
    }
    
    var backgroundColor: UIColor {
        switch self {
        case .success:
            return #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
        case .failure:
            return #colorLiteral(red: 1, green: 0.431372549, blue: 0.431372549, alpha: 1)
        }
    }
    
    /// The height of the notification which applies on the notification view.
    var height: UINotification.Height {
        switch self {
        case .success:
            return .navigationBar
        case .failure:
            return .statusBar
        }
    }

    /// Use this to set a max width to the notification view.
    var maxWidth: CGFloat? {
        return nil
    }
    
    /// When `true`, the notification is swipeable and tappable.
    var interactive: Bool {
        return true
    }
    
    var chevronImage: UIImage? {
        return #imageLiteral(resourceName: "iconToastChevron")
    }
}

And use it:

let notification = UINotification(content: myContent, style: CustomNotificationStyle.success)

Use a custom dismiss trigger

let manualDismissTrigger = UINotificationManualDismissTrigger()
UINotificationCenter.current.show(notification: notification, dismissTrigger: manualDismissTrigger)

/// Do other stuff..

manualDismissTrigger.trigger() // Dismiss

Create a custom UINotificationView

  • Create a custom view and inherit from UINotificationView
  • Set your custom view on the UINotificationCenter:
UINotificationCenter.current.configuration = UINotificationCenterConfiguration(
    defaultNotificationViewType: MyCustomNotificationView.self
)

Use a custom UIButton

By setting the button property on UINotification, you can simply add a button to the notification.

notification.button = UIButton(type: .system)

Button

Create a custom presenter

Create a custom presenter to manage presentation and dismiss animations.

  • Create a custom class which inherits from UINotificationPresenter.
  • Set your custom presenter on the UINotificationCenter:
UINotificationCenter.current.configuration = UINotificationCenterConfiguration(
    presenterType: MyCustomPresenter.self
)

Checkout UINotificationEaseOutEaseInPresenter for an example.

Allow duplicate requests

By default, notifications which are already queued will not be queued again. This is to prevent an endless loop of notifications being presented if they occur quickly after each other.

To disable this setting:

UINotificationCenter.current.configuration = UINotificationCenterConfiguration(
    isDuplicateQueueingAllowed: true
)

Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Installation

Swift Package Manager

The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

Manifest File

Add UINotifications as a package to your Package.swift file and then specify it as a dependency of the Target in which you wish to use it.

import PackageDescription

let package = Package(
    name: "MyProject",
    platforms: [
       .macOS(.v10_15)
    ],
    dependencies: [
        .package(url: "https://github.com/WeTransfer/UINotifications.git", .upToNextMajor(from: "1.3.0"))
    ],
    targets: [
        .target(
            name: "MyProject",
            dependencies: ["UINotifications"]),
        .testTarget(
            name: "MyProjectTests",
            dependencies: ["MyProject"]),
    ]
)

Xcode

To add UINotifications as a dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter the repository URL.

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate UINotifications into your Xcode project using Carthage, specify it in your Cartfile:

github "WeTransfer/UINotifications" ~> 1.00

Run carthage update to build the framework and drag the built UINotifications.framework into your Xcode project.

Manually

If you prefer not to use any of the aforementioned dependency managers, you can integrate UINotifications into your project manually.

Embedded Framework

  • Open up Terminal, cd into your top-level project directory, and run the following command "if" your project is not initialized as a git repository:

    $ git init
  • Add UINotifications as a git submodule by running the following command:

    $ git submodule add https://github.com/WeTransfer/UINotifications.git
  • Open the new UINotifications folder, and drag the UINotifications.xcodeproj into the Project Navigator of your application's Xcode project.

    It should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.

  • Select the UINotifications.xcodeproj in the Project Navigator and verify the deployment target matches that of your application target.

  • Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.

  • In the tab bar at the top of that window, open the "General" panel.

  • Click on the + button under the "Embedded Binaries" section.

  • Select UINotifications.framework.

  • And that's it!

    The UINotifications.framework is automagically added as a target dependency, linked framework and embedded framework in a copy files build phase which is all you need to build on the simulator and a device.


Release Notes

See CHANGELOG.md for a list of changes.

License

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

uinotifications's People

Contributors

amirdew avatar avdlee avatar basthomas avatar bermannoah avatar boris-em avatar kairadiagne avatar kevinrenskers avatar peagasilva avatar renssies avatar samuelbeek avatar wetransferplatform avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uinotifications's Issues

False warning "SwiftLint not installed"

I always get the warning SwiftLint not installed, download from https://github.com/realm/SwiftLint when building the example app, even though SwiftLint is installed globally on my computer.

~/Workspace $ which swiftlint
/opt/homebrew/bin/swiftlint

Demo UI issues

  • When entering content the button will become unreachable. The keyboard does not hide or the view should be scrollable.
  • In landscape the view should be scrollable

Chevron image does not have a set size

The user-provided chevron image is used by the library as-is and is not scaled down to fit the banner.

The following example gif is from a project that provides the library with a 512 x 512 image.

uinotifications_image_bug

The following is printed in the debug area:

2017-07-20 19:28:13.246143-0400 <PROJECT NAME>[36820:1464190] [LayoutConstraints] Unable to simultaneously satisfy constraints.
	Probably at least one of the constraints in the following list is one you don't want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don't expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x608000088ed0 UIImageView:0x7f868850c650.width == 512   (active)>",
    "<NSLayoutConstraint:0x608000089010 H:|-(20)-[UILabel:0x7f868850bd10'My Custom Text'](LTR)   (active, names: '|':UINotifications.UINotificationView:0x7f868850b6f0 )>",
    "<NSLayoutConstraint:0x608000088cf0 H:[UILabel:0x7f868850bd10'My Custom Text']-(20)-[UIImageView:0x7f868850c650](LTR)   (active)>",
    "<NSLayoutConstraint:0x608000088d40 UIImageView:0x7f868850c650.right == UINotifications.UINotificationView:0x7f868850b6f0.right - 20   (active)>",
    "<NSLayoutConstraint:0x6080000899c0 H:|-(0)-[UINotifications.UINotificationView:0x7f868850b6f0](LTR)   (active, names: '|':UIView:0x7f868850e670 )>",
    "<NSLayoutConstraint:0x608000089a10 UINotifications.UINotificationView:0x7f868850b6f0.right == UIView:0x7f868850e670.right   (active)>",
    "<NSLayoutConstraint:0x608000089dd0 'UIView-Encapsulated-Layout-Width' UIView:0x7f868850e670.width == 414   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x608000088ed0 UIImageView:0x7f868850c650.width == 512   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

Remove the UIWindow if not used

Right now, the UINotificationPresentationWindow is always visible and makes it hard to debug with apps like Reveal, as it's always the top layer.

Add accessibility notification support for in-app notifications

These in-app notifications don't come with UIAcessibility announcements/notifications, making them quite very easy to miss for VoiceOver users; make sure we post a notification for them, like ±so:

UIAccessibility.post(notification: .announcement, argument: notification.title)

when showing the notification.

Cannot tap in-app notifications on iPhone X

This issue is specific to iPhone X: users cannot tap on in-app notifications.

To easily reproduce:

  • Create 2 boards
  • Open one board, select item(s) and tap "Move"
  • A notification will appear at the top of the screan
  • Tap it

When taping the notification, the user should be taken to the board view.
Instead, either nothing happens or the elements under the notifications are taped (like "Share").

Prevent duplicate notification presentation

When a notification is presented and a new notification is added to the queue, it should not be handled if the content is the same.

This is maybe something which should be part of a setting.

Smaller assets

Right now there's a banner image in the Examples' project asset catalog that is an astonishing 48MB. Let's try to make that smaller 👍.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.