Skip to content

Warning fixes #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CSNotificationView/CSNativeBlurView.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import <UIKit/UIKit.h>
#import "CSNotificationView_Private.h"

API_AVAILABLE(ios(8.0))
@interface CSNativeBlurView : UIVisualEffectView <CSNotificationViewBlurViewProtocol>

@end
10 changes: 9 additions & 1 deletion CSNotificationView/CSNativeBlurView.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ @implementation CSNativeBlurView

- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
if (@available(iOS 8.0, *)) {
self = [super initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
} else {
// Fallback on earlier versions
}if (@available(iOS 8.0, *)) {
self = [super initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
} else {
// Fallback on earlier versions
}
if (self) {
self.tintColorView = [[UIView alloc] initWithFrame:self.bounds];
self.tintColorView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
Expand Down
8 changes: 6 additions & 2 deletions CSNotificationView/CSNotificationView.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@

static CGFloat const kCSNotificationViewHeight = 50.0f;
static CGFloat const kCSNotificationViewSymbolViewSidelength = 44.0f;
static CGFloat const kCSNotificationViewCloseButtonWidth = 44.0f;
static CGFloat const kCSNotificationViewCloseButtonHeight = 44.0f;
static NSTimeInterval const kCSNotificationViewDefaultShowDuration = 2.0;

typedef NS_ENUM(NSInteger, CSNotificationViewStyle) {
CSNotificationViewStyleSuccess,
CSNotificationViewStyleError
};

typedef void(^CSVoidBlock)();
typedef void(^CSVoidBlock)(void);

@interface CSNotificationView : UIView

Expand Down Expand Up @@ -73,7 +75,7 @@ typedef void(^CSVoidBlock)();
* @param animated Should a change in `showing` be animated?
* @param completion `nil` or a callback called on the main thread after changes to the interface are completed.
*/
- (void)setVisible:(BOOL)showing animated:(BOOL)animated completion:(void (^)())completion;
- (void)setVisible:(BOOL)showing animated:(BOOL)animated completion:(void (^)(void))completion;

/**
* Convenience method to dismiss with a(nother) predefined style and / or message.
Expand All @@ -100,6 +102,8 @@ typedef void(^CSVoidBlock)();
* The label containing the message displayed to the user.
*/
@property (nonatomic, readonly) UILabel* textLabel;

@property (nonatomic, readonly) UIButton *closeButton;

@property (nonatomic, getter = isShowingActivity) BOOL showingActivity;

Expand Down
57 changes: 47 additions & 10 deletions CSNotificationView/CSNotificationView.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@

@implementation CSNotificationView

-(nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [self initWithCoder:aDecoder];
return self;
}

-(instancetype)initWithFrame:(CGRect)frame {
self = [self initWithFrame:frame];
return self;
}
#pragma mark + quick presentation

+ (void)showInViewController:(UIViewController*)viewController
Expand All @@ -29,7 +38,7 @@ + (void)showInViewController:(UIViewController*)viewController
note.image = image;
note.textLabel.text = message;

void (^completion)() = ^{[note setVisible:NO animated:YES completion:nil];};
void (^completion)(void) = ^{[note setVisible:NO animated:YES completion:nil];};
[note setVisible:YES animated:YES completion:^{
double delayInSeconds = duration;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
Expand Down Expand Up @@ -57,7 +66,7 @@ + (void)showInViewController:(UIViewController*)viewController
note.textLabel.textAlignment = textAlignment;
note.textLabel.text = message;

void (^completion)() = ^{[note setVisible:NO animated:YES completion:nil];};
void (^completion)(void) = ^{[note setVisible:NO animated:YES completion:nil];};
[note setVisible:YES animated:YES completion:^{
double delayInSeconds = duration;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
Expand Down Expand Up @@ -175,6 +184,14 @@ - (instancetype)initWithParentViewController:(UIViewController*)viewController
{
[self updateSymbolView];
}

//closeButton
{
_closeButton = [[UIButton alloc] init];
_closeButton.translatesAutoresizingMaskIntoConstraints = NO;
_closeButton.backgroundColor = [UIColor clearColor];
[self addSubview:_closeButton];
}
}

//Interaction
Expand Down Expand Up @@ -255,23 +272,28 @@ - (void)updateConstraints
CGFloat symbolViewWidth = self.symbolView.tag != kCSNotificationViewEmptySymbolViewTag ?
kCSNotificationViewSymbolViewSidelength : 0.0f;
CGFloat symbolViewHeight = kCSNotificationViewSymbolViewSidelength;


CGFloat closeButtonWidth = kCSNotificationViewCloseButtonWidth;
CGFloat closeButtonHeight = kCSNotificationViewCloseButtonHeight;

NSDictionary* metrics =
@{@"symbolViewWidth": [NSNumber numberWithFloat:symbolViewWidth],
@"symbolViewHeight":[NSNumber numberWithFloat:symbolViewHeight]};
@"symbolViewHeight":[NSNumber numberWithFloat:symbolViewHeight],
@"closeButtonWidth":@(closeButtonWidth),
@"closeButtonHeight":@(closeButtonHeight)};

[self addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"H:|-(4)-[_symbolView(symbolViewWidth)]-(5)-[_textLabel]-(10)-|"
constraintsWithVisualFormat:@"H:|-(4)-[_symbolView(symbolViewWidth)]-(5)-[_textLabel]-(5)-[_closeButton(closeButtonWidth)]-(10)-|"
options:0
metrics:metrics
views:NSDictionaryOfVariableBindings(_textLabel, _symbolView)]];
views:NSDictionaryOfVariableBindings(_textLabel, _symbolView,_closeButton)]];

[self addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"V:[_symbolView(symbolViewHeight)]"
options:0
metrics:metrics
views:NSDictionaryOfVariableBindings(_symbolView)]];
[self addConstraint:[NSLayoutConstraint
constraintWithItem:_symbolView
attribute:NSLayoutAttributeBottom
Expand All @@ -287,7 +309,22 @@ - (void)updateConstraints
toItem:_symbolView
attribute:NSLayoutAttributeCenterY
multiplier:1.0f constant:0]];


[self addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"V:[_closeButton(closeButtonHeight)]"
options:0
metrics:metrics
views:NSDictionaryOfVariableBindings(_closeButton)]];

[self addConstraint:[NSLayoutConstraint
constraintWithItem:_closeButton
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:self
attribute:NSLayoutAttributeBottom
multiplier:1.0f constant:0]];


[super updateConstraints];
}

Expand All @@ -311,11 +348,11 @@ -(void)handleTapInView:(UITapGestureRecognizer*)tapGestureRecognizer

#pragma mark - presentation

- (void)setVisible:(BOOL)visible animated:(BOOL)animated completion:(void (^)())completion
- (void)setVisible:(BOOL)visible animated:(BOOL)animated completion:(void (^)(void))completion
{
if (_visible != visible) {

NSTimeInterval animationDuration = animated ? 0.4 : 0.0;
NSTimeInterval animationDuration = animated ? 0.7 : 0.0;

CGRect startFrame, endFrame;
[self animationFramesForVisible:visible startFrame:&startFrame endFrame:&endFrame];
Expand Down
1 change: 0 additions & 1 deletion CSNotificationView/CSNotificationView_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ static NSString * kCSNavigationBarBoundsKeyPath = @"parentNavigationController.n
#pragma mark - presentation
@property (nonatomic, weak) UIViewController* parentViewController;
@property (nonatomic, strong) UINavigationController* parentNavigationController; //Has to be strong-referenced because CSNotificationView does KVO on parentNavigationController
@property (nonatomic, getter = isVisible) BOOL visible;

#pragma mark - content views
@property (nonatomic, strong, readonly) UIView* symbolView; // is updated by -(void)updateSymbolView
Expand Down
Loading