Giter Club home page Giter Club logo

crtoast's Introduction

CRToast

Build Status Pod Version Carthage compatible

CRToast is a library that allows you to easily create notifications that appear on top of or by pushing out the status bar or navigation bar. CRToast was originally based on CWStatusBarNotification.

demo

Requirements

CRToast uses ARC and requires iOS 7.0+. Works for iPhone and iPad.

Installation

CocoaPods

pod 'CRToast', '~> 0.0.7'

Carthage

github "cruffenach/CRToast"

Manual

Add the project or source files to your own project.

Usage

Notifications can be created through CRToastManager's showNotificationWithOptions:completionBlock: This will queue up a notification with the options specified. You provide options for your notification in a dictionary using the keys in CRToast.h

Example

This code

NSDictionary *options = @{
                          kCRToastTextKey : @"Hello World!",
                          kCRToastTextAlignmentKey : @(NSTextAlignmentCenter),
                          kCRToastBackgroundColorKey : [UIColor redColor],
                          kCRToastAnimationInTypeKey : @(CRToastAnimationTypeGravity),
                          kCRToastAnimationOutTypeKey : @(CRToastAnimationTypeGravity),
                          kCRToastAnimationInDirectionKey : @(CRToastAnimationDirectionLeft),
                          kCRToastAnimationOutDirectionKey : @(CRToastAnimationDirectionRight)
                          };
[CRToastManager showNotificationWithOptions:options
                            completionBlock:^{
                                NSLog(@"Completed");
                            }];

Generates this

Customization

CRToast is very customizable. Taking a hint from UIStringDrawing's drawInRect:withAttributes: book, notifications are created with dictionaries filled with all their options.

Customizing Appearance

CRToast allows for setting of

  • Left aligned image

Title and Subtitle text with:

  • Text Color
  • Text Font
  • Text Alignment
  • Text Color
  • Text Shadow Color
  • Text Shadow Offset
  • Text Max Number of Lines

Customizing Animation

CRToast also allows for animation customization. This includes.

  • Animation Type (Linear, Spring or Gravity)
  • Animation Physics Coefficients (Spring Damping, Spring Initial Velocity, Gravity Magnitude)
  • Presentation Type (Slide over bars or push content out)
  • Status visibility (Status bar on top or below)
  • Direction (Enter and exit in any direction)
  • Enter, Stay on Screen and Exit Timing

Touch Interactions

CRToast allows for any notification to respond to different types of touch interactions (tap, swipe). Interaction responders can be set as defaults or on a per notification basis. The types of interactions you can set up to respond to are:

CRToastInteractionTypeSwipeUp
CRToastInteractionTypeSwipeLeft
CRToastInteractionTypeSwipeDown
CRToastInteractionTypeSwipeRight
CRToastInteractionTypeTapOnce
CRToastInteractionTypeTapTwice
CRToastInteractionTypeTwoFingerTapOnce
CRToastInteractionTypeTwoFingerTapTwice

There are also wild card interaction types which cover a range of interactions

CRToastInteractionTypeSwipe
CRToastInteractionTypeTap
CRToastInteractionTypeAll

Any interaction can be responded to using a CRToastInteractionResponder, they can be made with the following constructor

+ (instancetype)interactionResponderWithInteractionType:(CRToastInteractionType)interactionType
                                   automaticallyDismiss:(BOOL)automaticallyDismiss
                                                  block:(void (^)(CRToastInteractionType interactionType))block;

You can set a collection of CRToastInteractionResponders as the object for the key kCRToastInteractionRespondersKey in defaults to have all notifications respond to a certain interaction, or on any given one to have the interaction responders just work for that one notification.

Persistent and Programmatically Dismissed Notifications

You can also dismiss the current notification at any time with

+ (void)dismissNotification:(BOOL)animated;

You can present notifications that must be dismissed by the user by passing @(DBL_MAX) for kCRToastTimeIntervalKey and setting up an interaction responder that will dismiss the notification.

Setting Defaults

There are sane defaults set for all properties, however you can set a default set of options for your application's notifications using CRToastManagers's setDefaultOptions:.

License

The MIT License (MIT)

Copyright (c) 2013 Collin Ruffenach

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

crtoast's People

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  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

crtoast's Issues

Queued notifications are not removed and keeps showing the 2nd one

I am showing toast when received push notifications.

When multi push received in short time when previous toast is showing, only the 1st and 2nd one got showed. A quick debug shows that when 2nd is showed it is not removed from the queue array. The count keeps growing but 2nd never got removed so I guess it's executing the 2nd forever.

iOS 8 and latest cocoapods CRToast.

How to round corners? / Access to UIView

I'm trying to add rounded corners to the notification but finding it pretty challenging. Any ideas how I could access the UIView to modify lower level parameters?

Change text after Notification has been displayed

Hi,
great work with CRToast, everything is working fine, but I am missing a feature. Is there a way to change the text of the image after the notification has been displayed?

May you implement something like this?

Thanks for your work!!

Tap and Swiper Gesture Recognizers

Would be nice to have configurable tap and gesture recognizers available. Per notification configuration would be cool there as well.

Presenting several toasts quickly causes animation to stop

Having several toast pop-up at the same time causes the following error in the console Multiple gravity behavior per animator is undefined and may assert in the future and causes the toast to not perform the out animation.

Here is the current setup:

    NSDictionary *options = @{
                              kCRToastTextKey : @"You now have 5 credits",
                              kCRToastTextAlignmentKey : @(NSTextAlignmentCenter),
                              kCRToastTextColorKey : [UIColor redColor],
                              kCRToastBackgroundColorKey : [UIColor blackColor],
                              kCRToastAnimationInTypeKey : @(CRToastAnimationTypeGravity),
                              kCRToastAnimationOutTypeKey : @(CRToastAnimationTypeGravity),
                              kCRToastAnimationInDirectionKey : @(CRToastAnimationDirectionLeft),
                              kCRToastAnimationOutDirectionKey : @(CRToastAnimationDirectionRight),
                              kCRToastNotificationTypeKey : @(CRToastTypeNavigationBar),
                              kCRToastNotificationPresentationTypeKey : @(CRToastPresentationTypePush),
                              kCRToastTimeIntervalKey : @1,
                              kCRToastFontKey : [UIFont systemFontOfSize:24]
                              };
    [CRToastManager showNotificationWithOptions:options
                                completionBlock:^{

                                }];

working examples of responders?

Are there any examples of setting up the responders? I am not quite seeing it (moderately new to iOS) and trying to best layout things to manage remote pushes into an active app. I poked around other libraries that have local blocks for managing taps etc, and get that, but this setup is not sinking in yet. It is crucial that i track the notification payload that must be acted on if the user taps the toast..

Don't redisplay toast that is already showing

I needed the following hack in order to prevent the same toast message from being displayed over and over.

id manager = [CRToastManager valueForKeyPath:@"manager"];
id notification = [manager valueForKeyPath:@"notification"];
NSString *existingTitle = [notification valueForKeyPath:@"text"];
NSString *existingSubtitle = [notification valueForKeyPath:@"subtitleText"];
if ([existingTitle isEqualToString:title] && [existingSubtitle isEqualToString:message]) {
    return;
}

The problem is that if the same message is displayed often, it keeps animating away and back again. I would prefer that it is ignored or that the old toast is replaced without animation.

Is there a better way of achieving my goal?

[Feature Request] Showing activity indicator view

A common scenario would be:
A user click login button and CRToast showing with UIActivityIndicator spinning with 'Please wait' message. and after the user logged in, CRToast will be used again to show 'Logged in' message with green background.

Thank you

Status Bar getting cut off

I'm getting the Status Bar showing up all weird.
screen shot 2014-04-30 at 8 35 13 pm
I'm just using the regular code in viewWillAppear... any ideas?
NSDictionary *options = @{
kCRToastTextKey : [NSString stringWithFormat:@"Hello World!"],
kCRToastTextAlignmentKey : @(NSTextAlignmentCenter),
kCRToastBackgroundColorKey : [UIColor blueColor],
kCRToastAnimationInTypeKey : @(CRToastAnimationTypeGravity),
kCRToastAnimationOutTypeKey : @(CRToastAnimationTypeGravity),
kCRToastAnimationInDirectionKey : @(CRToastAnimationDirectionLeft),
kCRToastAnimationOutDirectionKey : @(CRToastAnimationDirectionRight)
};
[CRToastManager showNotificationWithOptions:options
completionBlock:^{
NSLog(@"Completed");
}];

NSInternalInconsistencyException

I am calling CRToast from UIViewcontroller with below code;

(void) userParamsSaved {
NSDictionary *options = @{
kCRToastTextKey : @"Hello World!",
kCRToastTextAlignmentKey : @(NSTextAlignmentCenter),
kCRToastBackgroundColorKey : [UIColor redColor],
kCRToastAnimationInTypeKey : @(CRToastAnimationTypeGravity),
kCRToastAnimationOutTypeKey : @(CRToastAnimationTypeGravity),
kCRToastAnimationInDirectionKey : @(CRToastAnimationDirectionLeft),
kCRToastAnimationOutDirectionKey : @(CRToastAnimationDirectionRight)
};
[CRToastManager showNotificationWithOptions:options
completionBlock:^{}];

}
and get

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid size {320, 0} for item <CRToastView: 0x1093935f0; frame = (-320 0; 320 0); userInteractionEnabled = NO; layer = <CALayer: 0x10932fd70>> in Dynamics'

what i am missing?

CRToast ignores the hidden state of the status bar

I've integrated CRToast into an existing project with little issue.

But, I have noticed that CRToast will awkwardly drop in the status bar. It does this even if the ViewController from which it was incanted has explicitly hidden the status bar (it seems to be from whatever mechanism one prefers — either from IB or from specifically preferring the status bar to be hidden programmatically). In this case, CRToast pops in and in so doing, unhides the status bar, pushes the entire view down by the 20 pixels and so forth. When it's done and pops out, the status bar is still there and then unceremoniously — disappears, shifting the view back to where it's meant to be.

Is this normal, or have I missed some specific setting? I think I've tried most that sound like they should tame this behavior. Happy to debug or provide more details.

Strange display in landscape on iPad

Launch your app on landscape on the iPad, and show a notification. See the result.
Rotate to portrait, and rotate back to landscape - the notification is shown correctly.

Subtitle in Toast

Maybe add an option, to specify a subtitle, that can be displayed together with the notification text?

Snapshot view animations have artifacts, look glitchy

The view that temporarily shows up during the animate-out is quite glitchy with some artifacts. For example, it often shows the iPhone's main screen's top bar instead of the current app's top bar. And for iPhone 6/6+, it shows a zoomed-in version of the status bar which looks awkwardly oversized.

I was able to hot-fix this by doing the following:

Change:

return underStatusBar ? [[UIApplication sharedApplication].keyWindow.rootViewController.view snapshotViewAfterScreenUpdates:YES] : [[UIScreen mainScreen] snapshotViewAfterScreenUpdates:YES];

to:

return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1000, 500)];

under (in crtoast.m):

static UIView *CRStatusBarSnapShotView(BOOL underStatusBar)

This fixed the animate-out artifact. The CRToast appears to take a screenshot of the iPhone's main screen OR the current screen, and then replaces that with the animate-out view. But if you just return an empty view as I do above, it appears to work OK.

Thoughts?

Add support for iOS 7 light status bar

When using a white status bar, the text goes black right before the notifications show until right after they disappear and then flashes back to white.

iOS 8, 1px gap

Starting with iOS 8, i can see a 1px gap on top of the navigation bar. Looks like the status bar is coming through.

Stackable notifications

I think it would be cool to have an option, to make a toast "stackable".
Meaning, that it doesn't prevent other toasts from being displayed.

p.e. when posting something (so an action that requires internet and may take some time) and displaying a toast in the statusbar as an indicator, this could be stackable, so that other notification toasts can still be displayed on top of it.

In case you like the idea, I would give it a try and implement it. (although it probably only makes sense to start the work on this, after the refactored CRToastManager API is there, right?)

Hidden Status Bar bug

In my application, the default is to have the status bar hidden, but when I show a notification, the status bar re-appears and is animated with the notification.

`CRGetStatusBarHeight()` sometimes returns `0`

In looking into some status bar bugs I noticed that when in a Navigation Controller where the View Controller has hidden the status bar CRGetStatusBarHeight() returns 0. When the View Controller is presented directly with the status bar hidden, it returns a correct value (20).

This is causing some strange behaviour differences in user apps and the demo app.

Slide under Status Bar

I haven't noticed any apps or libraries with notifications like this that don't obscure the status bar, that is a feature I'd like to see.

red_notification_under

Toast not animating unless Notification Center is open

When testing my application, the toast is only animated when the notification center top bar is down or being pulled down. When it is up the animation stops. I am not sure whether this is some kind of problem with cocos2d or iOS 7.1 (havn't tested on 7.0)

Device: iPad Air
iOS Version: 7.1

The toast is dismissible with a swipe even if the responder is not set

I have this error with the demo app.
If you check "Dismissible with Tap" then show a toast, you are able to dismiss it with a tap. The console then shows:

Dismissed with Tap Once interaction

However, you can also dismiss it with a swipe:

Dismissed with Swipe Left interaction

Which you should not be able to do.

Frosted liveBlur background option

It would be cool to have the notification view have the iOS 7 frosted blur effect, we could incorporate the background color as a tint too.

I'll have a go at a PR but wanted to make it open for discussion first.

Shadow parameters are ignored?

Changing the shadow parameters for the text and subtitle text don't appear to do anything. It looks like they should be set in the setToast method.

  • (void)setToast:(CRToast *)toast {
    _toast = toast;
    _label.text = toast.text;
    _label.font = toast.font;
    _label.textColor = toast.textColor;
    _label.textAlignment = toast.textAlignment;
    _label.numberOfLines = toast.textMaxNumberOfLines;

    _label.shadowOffset = toast.textShadowOffset; // NEW
    _label.shadowColor = toast.textShadowColor; // NEW

    if (toast.subtitleText != nil) {
    _subtitleLabel.text = toast.subtitleText;
    _subtitleLabel.font = toast.subtitleFont;
    _subtitleLabel.textColor = toast.subtitleTextColor;
    _subtitleLabel.textAlignment = toast.subtitleTextAlignment;
    _subtitleLabel.numberOfLines = toast.subtitleTextMaxNumberOfLines;

    _subtitleLabel.shadowOffset = toast.subtitleTextShadowOffset;   // NEW
    _subtitleLabel.shadowColor = toast.subtitleTextShadowColor; // NEW
    

    }
    _imageView.image = toast.image;
    self.backgroundColor = toast.backgroundColor;
    }

Dismissing notification without animation broken

When I call + (void)dismissNotification:(BOOL)animated; with animated param set to NO then my current notification doesn't disappear with the current release (v0.0.6).

Here's what happens within my app:

  • user taps button
  • [CRToastManager showNotificationWithMessage:@"Initial notification" completionBlock:nil]; is run
  • toast message animates in
  • user taps button again
  • [CRToastManager dismissNotification:NO]; [CRToastManager showNotificationWithMessage:@"Another notification" completionBlock:nil]; is run
  • the first notification (stating "Initial notification") still stays
  • until it animates out after the default delay
  • the second notification animates in (stating "Another notification")
  • it stays until it animates out after the delay

I would have expected the initial notification to immediately disappear and the second notification to animate in immediately after that. But the first notification doesn't disappear by calling the dismissNotification method with param NO at all.

iOS 8 issue

After updating to iOS 8 the toast are presented just once, doesn't matter how manny times I call [CRToastManager showNotificationWithOptions:options completionBlock:^{}] with the same options dictionary.

Configurable Window Level

See #70

A similar idea could be applied to the UIWindowLevelStatusBar level also if you want to.

Could you advise further on this @angelolloqui , should we do this and why.

Well... I think we should do it also, but I did not because it needs to be tested I guess. The main problem I see are new windows like the keyboard or a movie player in fullscreen, that could be somehow affected, but I think they will have a lower windowLevel. The "why" is because each window should be in a different windowLevel to determine the z-index position. From Apple:

A window belongs to a level—typically, UIWindowLevelNormal—that represents where it sits on the z-axis relative to other windows

Right now your window is presented above because you are adding it later, but it is better to just use this property. Besides, as explained, some third party components assume that the main app window is on UIWindowLevelNormal which I think is a valid assumption, but does not happen when CRToast is used under the status bar.

I'm also wondering if this amount (+1) should be configurable so users can adjust it for compatibility with other code. Do I understand this correctly?

That is actually a good idea. This way we let the developers to decide the index position and in case they have other windows it will help them. I would set +1 by default and add it as a new property to the options dict. My only doubt is that it will mess a little with the kCRToastUnderStatusBarKey key because then the dev could use UIWindowLevelStatusBar without setting kCRToastUnderStatusBarKey to NO. What do you think?

Request GitHub remove `twg/CRToast` from Fork Network

I don't fully understand what is going on in this repo : https://github.com/twg/CRToast.

If you look at the branch list it seems there are apps being developed in the same repo as their CRToast fork : https://github.com/twg/CRToast/tree/playoffStandings.

You may have noticed their Pull Requests for their apps are being linked to issues and PRs in this repo, eg: #44.

I contacted GitHub about this and they said

Thank you for contacting us. Being able to reference other repositories in a network is a functionality for repository networks in GitHub. If the owner of the parent repository would prefer that the references to stop, they can contact us to have us remove the fork from the network.

ping @cruffenach.

Error when displaying banner and option CRToastInteractionTypeAll

I am using this code to display a banner over the status bar which works fine but always outputs the error below:

CODE:

NSDictionary *options = @{
kCRToastTextKey : text,
kCRToastTextAlignmentKey : @(NSTextAlignmentCenter),
kCRToastFontKey : HelveticaNeue_Light(12),
kCRToastTextColorKey : [UIColor whiteColor],
kCRToastBackgroundColorKey : lightBlueColor,
kCRToastAnimationInTypeKey : @(CRToastAnimationTypeGravity),
kCRToastAnimationOutTypeKey : @(CRToastAnimationTypeGravity),
kCRToastInteractionRespondersKey : @(CRToastInteractionTypeAll),
kCRToastAnimationInDirectionKey : @(CRToastAnimationDirectionTop),
kCRToastAnimationOutDirectionKey : @(CRToastAnimationDirectionTop),
kCRToastTimeIntervalKey : @(5.0),
};
[CRToastManager showNotificationWithOptions:options
completionBlock:^{
//NSLog(@"Completed");
}];

LOG:

2014-08-22 10:33:47.354 App[30022:60b] [CRToast] : ERROR given 240 for key kCRToastInteractionRespondersKey was expecting Class NSArray but got Class __NSCFNumber, passing default on instead

Gravity Animation Type

Additionally to linear and spring it would be cool to have an animation type, that uses the uikit dynamics gravity

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.