-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix avoiding when automaticallyAdjustsScrollViewInsets is enabled
- Loading branch information
1 parent
90c32a4
commit 135a885
Showing
14 changed files
with
337 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// | ||
// ContenInsetAutoChangeTest.m | ||
// EKKeyboardAvoiding | ||
// | ||
// Created by Evgeniy Kirpichenko on 10/30/13. | ||
// Copyright (c) 2013 Evgeniy Kirpichenko. All rights reserved. | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import "EKFakeKeyboard.h" | ||
#import "EKFakeKeyboardFrameListener.h" | ||
|
||
#import "EKKeyboardAvoidingProvider.h" | ||
|
||
@interface ContenInsetAutoChangeTest : XCTestCase | ||
@property (nonatomic, strong) EKKeyboardAvoidingProvider *avoidingProvider; | ||
@property (nonatomic, strong) UIScrollView *scrollView; | ||
|
||
@property (nonatomic) UIEdgeInsets portraitAutomaticInset; | ||
@property (nonatomic) UIEdgeInsets landscapeAutomaticInset; | ||
|
||
@property (nonatomic) CGRect portraitFrame; | ||
@property (nonatomic) CGRect landscapeFrame; | ||
@end | ||
|
||
@implementation ContenInsetAutoChangeTest | ||
|
||
- (void)setUp | ||
{ | ||
[super setUp]; | ||
|
||
self.portraitAutomaticInset = UIEdgeInsetsMake(64, 0, 49, 0); | ||
self.landscapeAutomaticInset = UIEdgeInsetsMake(52, 0, 49, 0); | ||
|
||
self.portraitFrame = CGRectMake(0, 0, 320, 568); | ||
self.landscapeFrame = CGRectMake(0, 0, 568, 320); | ||
|
||
self.scrollView = [[UIScrollView alloc] init]; | ||
self.avoidingProvider = [[EKKeyboardAvoidingProvider alloc] initWithScrollView:self.scrollView]; | ||
self.avoidingProvider.keyboardListener = [EKFakeKeyboardFrameListener new]; | ||
|
||
[self.avoidingProvider startAvoiding]; | ||
[self rotateScrollToPortraitOrientation]; | ||
} | ||
|
||
- (void)tearDown | ||
{ | ||
[self.avoidingProvider stopAvoiding]; | ||
[super tearDown]; | ||
} | ||
|
||
- (void)testInitialContentInset | ||
{ | ||
UIEdgeInsets expectedInset = UIEdgeInsetsMake(64, 0, 49, 0); | ||
XCTAssertEqual([self.scrollView contentInset], expectedInset); | ||
} | ||
|
||
- (void)testRotationToLandscape | ||
{ | ||
[self rotateScrollToLandscapeOrientation]; | ||
|
||
XCTAssertEqual([self.scrollView frame], self.landscapeFrame); | ||
XCTAssertEqual([self.scrollView contentInset], self.landscapeAutomaticInset); | ||
} | ||
|
||
- (void)testPortraitRotateAndShowKeyboard | ||
{ | ||
[self rotateScrollToPortraitOrientation]; | ||
[EKFakeKeyboard showWithFrame:CGRectMake(0, 352, 320, 216)]; | ||
|
||
UIEdgeInsets expectedInset = UIEdgeInsetsMake(64, 0, 216, 0); | ||
XCTAssertEqual([self.scrollView contentInset], expectedInset); | ||
} | ||
|
||
- (void)testLandscapeRotateAndShowKeyboard | ||
{ | ||
[self rotateScrollToLandscapeOrientation]; | ||
[EKFakeKeyboard showWithFrame:CGRectMake(0, 158, 568, 162)]; | ||
|
||
UIEdgeInsets expectedInset = UIEdgeInsetsMake(52, 0, 162, 0); | ||
XCTAssertEqual([self.scrollView contentInset], expectedInset); | ||
} | ||
|
||
- (void)testLandscapeShowKeyboardAndRotate | ||
{ | ||
[EKFakeKeyboard showWithFrame:CGRectMake(0, 352, 568, 162)]; | ||
[self rotateScrollToLandscapeOrientation]; | ||
[EKFakeKeyboard showWithFrame:CGRectMake(0, 158, 568, 162)]; | ||
|
||
UIEdgeInsets expectedInset = UIEdgeInsetsMake(52, 0, 162, 0); | ||
XCTAssertEqual([self.scrollView contentInset], expectedInset); | ||
} | ||
|
||
#pragma mark - helpers | ||
|
||
- (void)updateContentInset:(UIEdgeInsets)contentInset { | ||
[[self scrollView] setContentInset:contentInset]; | ||
} | ||
|
||
- (void)rotateScrollToPortraitOrientation | ||
{ | ||
[self.scrollView setFrame:self.portraitFrame]; | ||
[self.scrollView setContentInset:self.portraitAutomaticInset]; | ||
} | ||
|
||
- (void)rotateScrollToLandscapeOrientation | ||
{ | ||
[self.scrollView setFrame:self.landscapeFrame]; | ||
[self.scrollView setContentInset:self.landscapeAutomaticInset]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
EKKeyboardAvoiding-UnitTests/EKAvoidingInsetCalculatorTest.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// EKAvoidingInsetCalculatorTest.m | ||
// EKKeyboardAvoiding | ||
// | ||
// Created by Evgeniy Kirpichenko on 11/15/13. | ||
// Copyright (c) 2013 Evgeniy Kirpichenko. All rights reserved. | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import "EKAvoidingInsetCalculator.h" | ||
|
||
@interface EKAvoidingInsetCalculatorTest : XCTestCase | ||
@property (nonatomic, strong) EKAvoidingInsetCalculator *calculator; | ||
@end | ||
|
||
@implementation EKAvoidingInsetCalculatorTest | ||
|
||
- (void)setUp | ||
{ | ||
[super setUp]; | ||
|
||
self.calculator = [EKAvoidingInsetCalculator new]; | ||
} | ||
|
||
- (void)testViewFrameFullyContainsKeyboardFrame | ||
{ | ||
self.calculator.scrollViewFrame = CGRectMake(0, 0, 568, 320); | ||
self.calculator.keyboardFrame = CGRectMake(320, 0, 216, 320); | ||
self.calculator.scrollViewInset = UIEdgeInsetsMake(10, 0, 20, 0); | ||
|
||
UIEdgeInsets insets = [self.calculator calculateAvoidingInset]; | ||
XCTAssertEqual(insets, UIEdgeInsetsZero, @"shouldn't calculate any extra inset"); | ||
} | ||
|
||
- (void)testKeyboardFrameContainsViewFrame | ||
{ | ||
self.calculator.scrollViewFrame = CGRectMake(0, 352, 320, 216); | ||
self.calculator.keyboardFrame = CGRectMake(0, 352, 320, 216); | ||
self.calculator.scrollViewInset = UIEdgeInsetsMake(10, 0, 20, 0); | ||
|
||
UIEdgeInsets insets = [self.calculator calculateAvoidingInset]; | ||
XCTAssertEqual(insets, UIEdgeInsetsZero, @"shouldn't calculate any extra inset"); | ||
} | ||
|
||
@end |
Oops, something went wrong.