Skip to content

Commit

Permalink
Merge branch 'refactor'
Browse files Browse the repository at this point in the history
Conflicts:
	Tests/Unit Tests/CRToastManagerTests.m
  • Loading branch information
dmiedema committed Jan 4, 2015
2 parents de74b8d + ec348c5 commit 727366f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 24 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: objective-c
before_install:
- brew outdated xctool || brew upgrade xctool
xcode_workspace: CRToastDemo.xcworkspace
# xcode_project: CRToastDemo.xcodeproj
xcode_scheme: CRToastTests
xcode_sdk:
- iphonesimulator7.0
Expand Down
6 changes: 0 additions & 6 deletions CRToast/CRToast.m
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,6 @@ @implementation CRToast

+ (void)initialize {
if (self == [CRToast class]) {

#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1
kCRFrameAutoAdjustedForOrientation = (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1);
kCRUseSizeClass = kCRFrameAutoAdjustedForOrientation;
#endif

kCRFontDefault = [UIFont systemFontOfSize:12];
kCRTextColorDefault = [UIColor whiteColor];
kCRTextShadowOffsetDefault = CGSizeZero;
Expand Down
48 changes: 38 additions & 10 deletions CRToast/CRToastLayoutHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,47 @@
#import <Foundation/Foundation.h>
#import "CRToast.h" // For NS_ENUM values

#pragma mark - Variables
#ifndef NSFoundationVersionNumber_iOS_7_1
#define NSFoundationVersionNumber_iOS_7_1 1047.25
#endif
/* Taken from NSObjCRuntime.h */
#define CR_NSFoundationVersionNumber_iOS_7_1 NSFoundationVersionNumber_iOS_7_1

static BOOL CRHorizontalSizeClassRegular() {
if (floor(NSFoundationVersionNumber) > CR_NSFoundationVersionNumber_iOS_7_1) {
/* What this is really doing
Also supress the warnings around possible leaks with those.
This is super ugly.
*/
// return [UIScreen mainScreen].traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassRegular;
// kCRFrameAutoAdjustedForOrientation = (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1);
// kCRUseSizeClass = kCRFrameAutoAdjustedForOrientation;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
NSInteger sizeClass = (NSInteger)[[[UIScreen mainScreen] performSelector:NSSelectorFromString(@"traitCollection")] performSelector:NSSelectorFromString(@"horizontalSizeClass")];
#pragma clang diagnostic pop
return sizeClass == 2; // UIUserInterfaceSizeClassRegular = 2
}
return NO;
}

/**
`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.
If/when iOS 7 support is dropped this check will no longer be necessary
*/
static BOOL kCRFrameAutoAdjustedForOrientation = NO;
static inline BOOL CRFrameAutoAdjustedForOrientation() {
return (floor(NSFoundationVersionNumber) > CR_NSFoundationVersionNumber_iOS_7_1);
}

/**
`BOOL` to determine if we can use size classes for determining layout.
`BOOL` to determine if we can use size classes for determining layout.
Only available in iOS 8 so we don't want to attempt to use size classes if we're not running iOS 8
*/
static BOOL kCRUseSizeClass = NO;
static inline BOOL CRUseSizeClass() {
return (floor(NSFoundationVersionNumber) > CR_NSFoundationVersionNumber_iOS_7_1);
}

#pragma mark - Variables
/// Default height of the status bar + 1 pixel
static CGFloat const CRNavigationBarDefaultHeight = 45.0f;
/// Height of the status bar in landscape orientation/compact size class + 1 pixel
Expand All @@ -39,7 +68,7 @@ static UIInterfaceOrientation CRGetDeviceOrientation() {
static CGFloat CRGetStatusBarHeightForOrientation(UIInterfaceOrientation orientation) {
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];

if (kCRFrameAutoAdjustedForOrientation) {
if (CRFrameAutoAdjustedForOrientation()) {
return CGRectGetHeight(statusBarFrame);
}

Expand All @@ -52,7 +81,7 @@ static CGFloat CRGetStatusBarHeightForOrientation(UIInterfaceOrientation orienta
static CGFloat CRGetStatusBarWidthForOrientation(UIInterfaceOrientation orientation) {
CGRect mainScreenBounds = [UIScreen mainScreen].bounds;

if (kCRFrameAutoAdjustedForOrientation) {
if (CRFrameAutoAdjustedForOrientation()) {
return CGRectGetWidth(mainScreenBounds);
}

Expand All @@ -74,9 +103,8 @@ static CGFloat CRGetStatusBarWidth() {
*/
static CGFloat CRGetNavigationBarHeightForOrientation(UIInterfaceOrientation orientation) {
BOOL regularHorizontalSizeClass = NO;
if (kCRUseSizeClass) {
UITraitCollection *traitCollection = [[UIScreen mainScreen] traitCollection];
regularHorizontalSizeClass = traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassRegular;
if (CRUseSizeClass()) {
regularHorizontalSizeClass = CRHorizontalSizeClassRegular();
}
return (UIDeviceOrientationIsPortrait(orientation) ||
UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad || regularHorizontalSizeClass) ?
Expand Down Expand Up @@ -162,7 +190,7 @@ static CGRect CRStatusBarViewFrame(CRToastType type, CRToastAnimationDirection d
static CGRect CRGetNotificationContainerFrame(UIInterfaceOrientation statusBarOrientation, CGSize notificationSize) {
CGRect containerFrame = CGRectMake(0, 0, notificationSize.width, notificationSize.height);

if (!kCRFrameAutoAdjustedForOrientation) {
if (!CRFrameAutoAdjustedForOrientation()) {
switch (statusBarOrientation) {
case UIInterfaceOrientationLandscapeLeft: {
containerFrame = CGRectMake(0, 0, notificationSize.height, notificationSize.width);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>D2F83304-488E-459E-B356-C6C630672DEF</string>
<string>7F910191-1339-43F0-B1FC-D31AB0696A1D</string>
<key>IDESourceControlProjectName</key>
<string>CRToastDemo</string>
<key>IDESourceControlProjectOriginsDictionary</key>
Expand Down
7 changes: 0 additions & 7 deletions Tests/Unit Tests/CRToastManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ - (void)testNotificationIdentifiers {
XCTAssertFalse([identifiers containsObject:@"test"], @"identifiers should not contain an identifier 'test'.");
}

- (void)testPerformanceExample {
// This is an example of a performance test case.
[self measureBlock:^{
// Put the code you want to measure the time of here.
}];
}

#pragma mark - Setup
- (void)setUp {
[super setUp];
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit Tests/CRToastViewTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,14 @@ - (void)testWidthWithLeftAndRight {
XCTAssertTrue(width == 100, @"Width with left & right item should be 200 (full width - (height x 2)). Instead was %f", width);
}

/*
// Causes travis to fail against iOS 7/7.1 SDK
- (void)testPerformanceExample {
[self measureBlock:^{
CRContentWidthForAccessoryViewsWithAlignments(300, 100, YES, CRToastAccessoryViewAlignmentLeft, YES, CRToastAccessoryViewAlignmentRight);
}];
}
*/

#pragma mark - Setup
- (void)setUp {
Expand Down

0 comments on commit 727366f

Please sign in to comment.