Skip to content
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
9 changes: 8 additions & 1 deletion CRToast/CRToastLayoutHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#import <Foundation/Foundation.h>
#import "CRToast.h" // For NS_ENUM values
#import "CRToastView.h"

/**
`BOOL` to determine if the frame is automatically adjusted for orientation. iOS 8 automatically accounts for orientation when getting frame where as iOS 7 does not.
Expand Down Expand Up @@ -111,7 +112,13 @@ static CGFloat CRGetNotificationViewHeightForOrientation(CRToastType type, CGFlo
case CRToastTypeStatusBar:
return CRGetStatusBarHeightForOrientation(orientation);
case CRToastTypeNavigationBar:
return CRGetStatusBarHeightForOrientation(orientation) + CRGetNavigationBarHeightForOrientation(orientation);
{
CGFloat height = CRGetStatusBarHeightForOrientation(orientation) + CRGetNavigationBarHeightForOrientation(orientation);
if (IsIPhoneX) {
height = MAX(88, height);
}
return height;
}
case CRToastTypeCustom:
return preferredNotificationHeight;
}
Expand Down
29 changes: 29 additions & 0 deletions CRToast/CRToastView.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,35 @@
#import <UIKit/UIKit.h>
#import "CRToast.h"

#ifndef kScreenWidth
#define kScreenWidth ([[UIScreen mainScreen] bounds].size.width)
#endif

#ifndef kScreenHeight
#define kScreenHeight ([[UIScreen mainScreen] bounds].size.height)
#endif

#ifndef IsIPhoneX
#define IsIPhoneX (isIPhoneXScreen())
#endif

#ifndef kNaviBarHeightOffset
#define kNaviBarHeightOffset (IsIPhoneX ? 24 : 0)
#endif

static inline BOOL isIPhoneXScreen (void) {
if (@available(iOS 11.0, *)) {
UIEdgeInsets edgInsets = [UIApplication sharedApplication].keyWindow.safeAreaInsets;

if (edgInsets.top > 0 &&
edgInsets.bottom > 0) {
return YES;
}
}

return NO;
}

/**
Calculate the width of the view given all necessary values of the given `CRToastView`s properties

Expand Down
15 changes: 9 additions & 6 deletions CRToast/CRToastView.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ @interface CRToastView ()
static CGFloat CRImageViewFrameXOffsetForAlignment(CRToastAccessoryViewAlignment alignment, CGFloat preferredPadding, CGSize contentSize) {
CGFloat imageSize = contentSize.height;
CGFloat xOffset = 0;

if (alignment == CRToastAccessoryViewAlignmentLeft) {
xOffset = preferredPadding;
} else if (alignment == CRToastAccessoryViewAlignmentCenter) {
Expand All @@ -39,8 +39,8 @@ static CGFloat CRImageViewFrameXOffsetForAlignment(CRToastAccessoryViewAlignment

static CGFloat CRContentXOffsetForViewAlignmentAndWidth(CRToastAccessoryViewAlignment imageAlignment, CGFloat imageXOffset, CGFloat imageWidth, CGFloat preferredPadding) {
return ((imageWidth == 0 || imageAlignment != CRToastAccessoryViewAlignmentLeft) ?
kCRStatusBarViewNoImageLeftContentInset + preferredPadding :
imageXOffset + imageWidth);
kCRStatusBarViewNoImageLeftContentInset + preferredPadding :
imageXOffset + imageWidth);
}

static CGFloat CRToastWidthOfViewWithAlignment(CGFloat height, BOOL showing, CRToastAccessoryViewAlignment alignment, CGFloat preferredPadding) {
Expand All @@ -65,7 +65,7 @@ CGFloat CRContentWidthForAccessoryViewsWithAlignments(CGFloat fullContentWidth,

width -= CRToastWidthOfViewWithAlignment(fullContentHeight, showingImage, imageAlignment, preferredPadding);
width -= CRToastWidthOfViewWithAlignment(fullContentHeight, showingActivityIndicator, activityIndicatorAlignment, preferredPadding);

if (!showingImage && !showingActivityIndicator) {
width -= (kCRStatusBarViewNoImageLeftContentInset + kCRStatusBarViewNoImageRightContentInset);
width -= (preferredPadding + preferredPadding);
Expand Down Expand Up @@ -132,6 +132,8 @@ - (void)layoutSubviews {
CGFloat preferredPadding = self.toast.preferredPadding;

CGFloat statusBarYOffset = self.toast.displayUnderStatusBar ? (CRGetStatusBarHeight()+CRStatusBarViewUnderStatusBarYOffsetAdjustment) : 0;
statusBarYOffset += kNaviBarHeightOffset;

contentFrame.size.height = CGRectGetHeight(contentFrame) - statusBarYOffset;

self.backgroundView.frame = self.bounds;
Expand All @@ -152,11 +154,11 @@ - (void)layoutSubviews {
if (self.toast.showActivityIndicator) {
CGFloat centerX = CRCenterXForActivityIndicatorWithAlignment(self.toast.activityViewAlignment, CGRectGetHeight(contentFrame), CGRectGetWidth(contentFrame), preferredPadding);
self.activityIndicator.center = CGPointMake(centerX,
CGRectGetMidY(contentFrame) + statusBarYOffset);
CGRectGetMidY(contentFrame) + statusBarYOffset);

[self.activityIndicator startAnimating];
x = MAX(CRContentXOffsetForViewAlignmentAndWidth(self.toast.activityViewAlignment, imageXOffset, CGRectGetHeight(contentFrame), preferredPadding), x);

[self bringSubviewToFront:self.activityIndicator];
}

Expand Down Expand Up @@ -302,3 +304,4 @@ - (void)setToast:(CRToast *)toast {
}

@end

4 changes: 3 additions & 1 deletion Example/CRToastDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
ORGANIZATIONNAME = "Collin Ruffenach";
TargetAttributes = {
5E2FFB5218367C01003333F8 = {
DevelopmentTeam = 7AM27DZVQU;
DevelopmentTeam = Q2T8K3RPZ5;
};
};
};
Expand Down Expand Up @@ -376,6 +376,7 @@
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = Q2T8K3RPZ5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "CRToastDemo/CRToastDemo-Prefix.pch";
GCC_WARN_PEDANTIC = YES;
Expand All @@ -401,6 +402,7 @@
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = Q2T8K3RPZ5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "CRToastDemo/CRToastDemo-Prefix.pch";
GCC_WARN_PEDANTIC = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>