Skip to content
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

Replace code deprecated in iOS7 #237

Open
wants to merge 3 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 32 additions & 2 deletions Example/TSMessages/TSDemoViewController.m
Expand Up @@ -19,10 +19,40 @@ - (void)viewDidLoad

[TSMessage setDefaultViewController:self];
[TSMessage setDelegate:self];
self.wantsFullScreenLayout = YES;
[self setFullscreenLayout:YES];

[self.navigationController.navigationBar setTranslucent:YES];
}

- (void)setFullscreenLayout:(bool)wantsFullscreen {
if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) {
if (wantsFullscreen) {
self.edgesForExtendedLayout = UIRectEdgeAll;
}
else {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
}
else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
self.wantsFullScreenLayout = wantsFullscreen;
#pragma clang diagnostic pop
}
}

- (bool)isFullscreen {
if ([self respondsToSelector:@selector(edgesForExtendedLayout)] && self.edgesForExtendedLayout == UIRectEdgeAll) {
return YES;
}
else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
return self.wantsFullScreenLayout;
#pragma clang diagnostic pop
}
}

- (IBAction)didTapError:(id)sender
{
[TSMessage showNotificationWithTitle:NSLocalizedString(@"Something failed", nil)
Expand Down Expand Up @@ -82,7 +112,7 @@ - (IBAction)didTapToggleNavigationBarAlpha:(id)sender

- (IBAction)didTapToggleWantsFullscreen:(id)sender
{
self.wantsFullScreenLayout = !self.wantsFullScreenLayout;
[self setFullscreenLayout:![self isFullscreen]];
[self.navigationController.navigationBar setTranslucent:!self.navigationController.navigationBar.isTranslucent];
}

Expand Down
73 changes: 41 additions & 32 deletions Pod/Classes/TSMessage.m
Expand Up @@ -151,17 +151,17 @@ + (void)prepareNotificationToBeShown:(TSMessageView *)messageView
{
NSString *title = messageView.title;
NSString *subtitle = messageView.subtitle;

for (TSMessageView *n in [TSMessage sharedMessage].messages)
{
if (([n.title isEqualToString:title] || (!n.title && !title)) && ([n.subtitle isEqualToString:subtitle] || (!n.subtitle && !subtitle)))
{
return; // avoid showing the same messages twice in a row
}
}

[[TSMessage sharedMessage].messages addObject:messageView];

if (!notificationActive)
{
[[TSMessage sharedMessage] fadeInCurrentNotification];
Expand All @@ -183,33 +183,42 @@ - (id)init
- (void)fadeInCurrentNotification
{
if ([self.messages count] == 0) return;

notificationActive = YES;

TSMessageView *currentView = [self.messages objectAtIndex:0];

__block CGFloat verticalOffset = 0.0f;

void (^addStatusBarHeightToVerticalOffset)() = ^void() {

if (currentView.messagePosition == TSMessageNotificationPositionNavBarOverlay){
return;
}

CGSize statusBarSize = [UIApplication sharedApplication].statusBarFrame.size;
verticalOffset += MIN(statusBarSize.width, statusBarSize.height);
};

if ([currentView.viewController isKindOfClass:[UINavigationController class]] || [currentView.viewController.parentViewController isKindOfClass:[UINavigationController class]])
{
UINavigationController *currentNavigationController;

if([currentView.viewController isKindOfClass:[UINavigationController class]])
currentNavigationController = (UINavigationController *)currentView.viewController;
else
currentNavigationController = (UINavigationController *)currentView.viewController.parentViewController;

BOOL isViewIsUnderStatusBar = [[[currentNavigationController childViewControllers] firstObject] wantsFullScreenLayout];

BOOL isViewIsUnderStatusBar;
if ([[[currentNavigationController childViewControllers] firstObject] respondsToSelector:@selector(edgesForExtendedLayout)]) {
isViewIsUnderStatusBar = [[currentNavigationController childViewControllers] firstObject].edgesForExtendedLayout == UIRectEdgeAll;
}
else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
isViewIsUnderStatusBar = [[[currentNavigationController childViewControllers] firstObject] wantsFullScreenLayout];
#pragma clang diagnostic pop
}
if (!isViewIsUnderStatusBar && currentNavigationController.parentViewController == nil) {
isViewIsUnderStatusBar = ![TSMessage isNavigationBarInNavigationControllerHidden:currentNavigationController]; // strange but true
}
Expand Down Expand Up @@ -237,17 +246,17 @@ - (void)fadeInCurrentNotification
addStatusBarHeightToVerticalOffset();
}
}

CGPoint toPoint;
if (currentView.messagePosition != TSMessageNotificationPositionBottom)
{
CGFloat navigationbarBottomOfViewController = 0;

if (self.delegate && [self.delegate respondsToSelector:@selector(messageLocationOfMessageView:)])
{
navigationbarBottomOfViewController = [self.delegate messageLocationOfMessageView:currentView];
}

toPoint = CGPointMake(currentView.center.x,
navigationbarBottomOfViewController + verticalOffset + CGRectGetHeight(currentView.frame) / 2.0);
}
Expand All @@ -260,14 +269,14 @@ - (void)fadeInCurrentNotification
}
toPoint = CGPointMake(currentView.center.x, y);
}

if (self.delegate && [self.delegate respondsToSelector:@selector(customizeMessageView:)])
{
[self.delegate customizeMessageView:currentView];
}



dispatch_block_t animationBlock = ^{
currentView.center = toPoint;
if (![TSMessage iOS7StyleEnabled]) {
Expand All @@ -277,7 +286,7 @@ - (void)fadeInCurrentNotification
void(^completionBlock)(BOOL) = ^(BOOL finished) {
currentView.messageIsFullyDisplayed = YES;
};

if (![TSMessage iOS7StyleEnabled]) {
[UIView animateWithDuration:kTSMessageAnimationDuration
delay:0.0
Expand All @@ -295,12 +304,12 @@ - (void)fadeInCurrentNotification
completion:completionBlock];
#endif
}

if (currentView.duration == TSMessageNotificationDurationAutomatic)
{
currentView.duration = kTSMessageAnimationDuration + kTSMessageDisplayTime + currentView.frame.size.height * kTSMessageExtraDisplayTimePerPixel;
}

if (currentView.duration != TSMessageNotificationDurationEndless)
{
dispatch_async(dispatch_get_main_queue(), ^
Expand Down Expand Up @@ -334,7 +343,7 @@ - (void)fadeOutNotification:(TSMessageView *)currentView animationFinishedBlock:
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(fadeOutNotification:)
object:currentView];

CGPoint fadeOutToPoint;
if (currentView.messagePosition != TSMessageNotificationPositionBottom)
{
Expand All @@ -345,7 +354,7 @@ - (void)fadeOutNotification:(TSMessageView *)currentView animationFinishedBlock:
fadeOutToPoint = CGPointMake(currentView.center.x,
currentView.viewController.view.bounds.size.height + CGRectGetHeight(currentView.frame)/2.f);
}

[UIView animateWithDuration:kTSMessageAnimationDuration animations:^
{
currentView.center = fadeOutToPoint;
Expand All @@ -355,19 +364,19 @@ - (void)fadeOutNotification:(TSMessageView *)currentView animationFinishedBlock:
} completion:^(BOOL finished)
{
[currentView removeFromSuperview];

if ([self.messages count] > 0)
{
[self.messages removeObjectAtIndex:0];
}

notificationActive = NO;

if ([self.messages count] > 0)
{
[self fadeInCurrentNotification];
}

if(animationFinished) {
animationFinished();
}
Expand All @@ -382,7 +391,7 @@ + (BOOL)dismissActiveNotification
+ (BOOL)dismissActiveNotificationWithCompletion:(void (^)())completion
{
if ([[TSMessage sharedMessage].messages count] == 0) return NO;

dispatch_async(dispatch_get_main_queue(), ^
{
if ([[TSMessage sharedMessage].messages count] == 0) return;
Expand Down Expand Up @@ -429,7 +438,7 @@ + (NSArray *)queuedMessages
+ (UIViewController *)defaultViewController
{
__strong UIViewController *defaultViewController = _defaultViewController;

if (!defaultViewController) {
defaultViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
}
Expand All @@ -445,7 +454,7 @@ + (BOOL)iOS7StyleEnabled
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
iOS7SDK = YES;
#endif

_useiOS7Style = ! (TS_SYSTEM_VERSION_LESS_THAN(@"7.0") || !iOS7SDK);
});
return _useiOS7Style;
Expand Down
2 changes: 1 addition & 1 deletion TSMessages.podspec
Expand Up @@ -23,7 +23,7 @@ There are 4 different types already set up for you: Success, Error, Warning, Mes
s.source = { :git => "https://github.com/KrauseFx/TSMessages.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/KrauseFx'

s.platform = :ios, '5.0'
s.platform = :ios, '7.0'
s.requires_arc = true

s.source_files = 'Pod/Classes'
Expand Down