cruffenach / crtoast Goto Github PK
View Code? Open in Web Editor NEWA modern iOS toast view that can fit your notification needs
License: MIT License
A modern iOS toast view that can fit your notification needs
License: MIT License
If needed, I'd be glad to help tag, resolve, or close issues.
I'm sure other contributors would be up for it too.
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.
cc @Viirus
I find it cleaner to have screenshots and other static files for the README in a github pages branch.
I prepared one in my fork but I cannot create a PR that creates a new branch. https://github.com/Ashton-W/CRToast/tree/gh-pages
Note the branch should be an orphan git checkout --orphan gh-pages
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.
Currently it is centered in its available bounds but not centered in the notification
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:^{
}];
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
I am wondering is there a switch that I can turn off queueing? So, all the notification will be displayed as soon as it being sent out, despite how many notifications are before it.
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.
Is there any way to have the KCRToastTextKey show a string variable?
For example:
kCRToastTextKey : @"Hello %@!"
Thanks!
Would be nice to have configurable tap and gesture recognizers available. Per notification configuration would be cool there as well.
If you set self.navigationItem.prompt
the navigation bar increases in height. This is not taken into account by CRToast.
I guess this problem is also seen when rotating. See #73 (comment)
Starting with iOS 8, i can see a 1px gap on top of the navigation bar. Looks like the status bar is coming through.
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.
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:
[CRToastManager showNotificationWithMessage:@"Initial notification" completionBlock:nil];
is run[CRToastManager dismissNotification:NO]; [CRToastManager showNotificationWithMessage:@"Another notification" completionBlock:nil];
is runI 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.
Additionally to linear and spring it would be cool to have an animation type, that uses the uikit dynamics gravity
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
CRToastPresentationTypePush
isn't respected when kCRToastUnderStatusBarKey
is YES
.
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.
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!!
Maybe add an option, to specify a subtitle, that can be displayed together with the notification text?
I start showing a notification right before the HTTP request, and when the request finishes I hide the toast using:
[CRToastManager dismissNotification:NO];
If the notification is not done animating, then the whole application dies.
How i disable rotation?
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?
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.
The notification message textbox is hidden and the view cannot be scrolled in iPhone 3.5 inch
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?
I'm getting the Status Bar showing up all weird.
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");
}];
It would be nice if we can make our own UIView and inject in the notification bar.
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?)
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.
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 differentwindowLevel
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 whenCRToast
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 useUIWindowLevelStatusBar
without settingkCRToastUnderStatusBarKey
toNO
. What do you think?
I am using this code to display a banner over the status bar which works fine but always outputs the error below:
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");
}];
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
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?
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?
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;
}
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.
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.
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.
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..
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.