Coder Social home page Coder Social logo

afdropdownnotification's Introduction

AFDropdownNotification

Dropdown notification view for iOS

alt text

##Installation

If you're using CocoaPods, just add this line to your Podfile:

pod 'AFDropdownNotification', '~> 1.0'

If you're not, import these files to your project:

AFDropdownNotification.h
AFDropdownNotification.m

##Usage

First of all, init your AFDropdownNotification class and set your main class as AFDropdownNotificationDelegate:

AFDropdownNotification *notification = [[AFDropdownNotification alloc] init];
notification.notificationDelegate = self;

You can configure the title text with the titleText property, the subtitle text with subtitleText, an optional left image defined as image, and two optional buttons, with topButtonText and bottomButtonText. For example:

notification.titleText = @"Update available";
notification.subtitleText = @"Do you want to download the update of this file?";
notification.image = [UIImage imageNamed:@"update"];
notification.topButtonText = @"Accept";
notification.bottomButtonText = @"Cancel";

If you want to hide the notification by tapping it, set dimissOnTap to YES:

notification.dismissOnTap = YES;

To present it, you can choose if you want to use UIKit dynamics (which will include a subtle bounce) or a regular lineal UIKit animation:

[notification presentInView:self.view withGravityAnimation:YES];

Finally, to handle the buttons taps, implement the two methods defined by the delegate, -dropdownNotificationTopButtonTapped and -dropdownNotificationBottomButtonTapped.

-(void)dropdownNotificationTopButtonTapped {
 
    NSLog(@"Top button tapped");
}

-(void)dropdownNotificationBottomButtonTapped {

    NSLog(@"Bottom button tapped");
}

Also, you can use blocks:

[_notification listenEventsWithBlock:^(AFDropdownNotificationEvent event) {
       
    switch (event) {
        case AFDropdownNotificationEventTopButton:
            // Top button
            break;
                
        case AFDropdownNotificationEventBottomButton:
            // Bottom button
            break;
                
        case AFDropdownNotificationEventTap:
            // Tap
            break;
                
        default:
            break;
    }
}];

##TODO

  • Light theme
  • Autolayout support for rotation

##License AFDropdownNotification is under MIT license so feel free to use it!

##Author Made by Alvaro Franco. If you have any question, feel free to drop me a line at [email protected]

afdropdownnotification's People

Contributors

alvarofranco avatar havocked avatar ptitematil2 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  avatar  avatar  avatar  avatar  avatar  avatar

afdropdownnotification's Issues

Swipe to dismiss

This is a very nice notification banner!

One suggestion: make it dismissible via a swipe like the standard apple push notifications? Of course if this is implemented it should only be allowed if "tap to dismiss" is allowed as well. Perhaps this would best be done with a UIPanGestureRecognizer since it provides a pan velocity, which would be needed to appropriately dismiss the notification at the users flick speed?

Doesn't support rotation

If the user rotates their device while the notification is on screen, the notification will not resize itself. So it will be left in an awkward state or will be partly cut off.

Please fix the warning

Please fix the runtime warning:
"Multiple gravity behavior per animator is undefined and may assert in the future"

Doesn't work with Swift

I made a bridging header, imported this lib, and made this code

@IBAction func notificationTest(sender: AnyObject) {

    var notification = AFDropdownNotification()
    notification.notificationDelegate = self
    notification.titleText = "Update available";
    notification.subtitleText = "Do you want to download the update of this file?";
    notification.topButtonText = "Accept";
    notification.bottomButtonText = "Cancel";
    notification.dismissOnTap = true;
    notification.image = nil
    notification.presentInView(self.view, withGravityAnimation: true)
    NSLog(notification.description)
}

and nothing happens then i click button

Use without status bar

What is the best way to adjust the code if you don't have the status bar visible in your app? Currently the padding at the top assumes there is a status bar, so without one there is a bit of a gap.

Notification gone when click on any option in Action sheet

It is working fine almost in all screen but if action sheet open (with 2/3 option) in iphone during that time if Notification alert display on that screen. Till that its working fine. When i click on any option in action sheet, Notification gone from the existing screen. Is that any limitation ? please help me. due to only this issue i cant use this in my app. Please guide me.

Step to produce issue :

  1. Take one UIButton and open action sheet with 2/3 option.
  2. on that UIButton click event , open notification after 1/2 second. ex:
    [self performSelector:@selector(showNotification:) withObject:nil afterDelay:1];
  3. Now, Action sheet options and Notification both open in screen. When u click on any option from action sheet, notification gone and not fire any method of this..

Thanks in advance.

2 or more notifications cause a bug

I sent two notifications one after the other and when that happens, the notifications behind will become unclickable and stay will stay on top forever unless your force close the app.

Text on right if there is no image

  1. If user assigns no image, the text should move to right
  2. Number of buttons can be 1 or 2
  3. There should be someway to drag the notification up again to cancel it like facebook
  4. There should be someway to dismiss the notification after some provided time.

Didn't work for me

AFDropdownNotification *notification = [[AFDropdownNotification alloc] init];
notification.titleText = message;
notification.dismissOnTap = YES;
[notification presentInView:self.view withGravityAnimation:YES];

I don't need the buttons so I didn't set the delegate but it was not showing on my UITableViewController.

Method presentInView:(UIView *)view ....

Hi there,

First of all, thanks a lot for AFDropdownNotification.

I was just testing it on my universal app (iPhone portrait and iPad landscape). No problem for the iPhone.
However, on the iPad the notifications are shown on portrait mode even if my iPad is on landscape mode. I decided to take a look at your code and it appears that you don't use the parameter "view" in the method "presentInView". You add the notification to "[[UIApplication sharedApplication] keyWindow]".
It is kinda strange because on your demo app, it's working this way.

Could you please explain what I am missing here?

Thanks a lot

Cheers,

Thomas

trouble dismissing & presentInView function doesn't seem to do anything with the view arg

-(void)presentInView:(UIView *)view withGravityAnimation:(BOOL)animation {
function doesn't seem to do much with the view argument.

Also i'm having issue with the taps. not seeing the block get executed on tap

  @IBAction func showNotifAction(sender: AnyObject) {
        let dumView = UIView(frame: CGRect(origin: CGPointZero, size: CGSize(width: 100, height: 100)))
        dumView.backgroundColor = UIColor.redColor()

        testNotifications(dumView)
    }

    func testNotifications(inView: UIView) {

        let note = AFDropdownNotification()
        note.titleText = "Test run"
        note.subtitleText = "something needs your attention"
        note.image = UIImage.stockPhoto()
        note.topButtonText = "ToP"
        note.bottomButtonText = "bUttom"
        note.isImageRounded = true
        note.dismissOnTap = true

        note.listenEventsWithBlock { (event: AFDropdownNotificationEvent) in
            note.dismissWithGravityAnimation(true)
            switch event {
            default:
                log(event)

            }
        }

        log(inView)
        note.presentInView(inView, withGravityAnimation: false)

        dispatchMainDelayed(delay: 3) {
            //note.dismissWithGravityAnimation(true)
        }


    }
}

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.