Skip to content

Commit

Permalink
Add inset on drag and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dostrander committed Feb 19, 2021
1 parent bdf2298 commit 604dc2b
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ jobs:
strategy:
matrix:
run-config:
- { xcode_version: '10.3', simulator: 'name=iPad (5th generation),OS=12.4' }
- { xcode_version: '10.3', simulator: 'name=iPhone 8,OS=12.4' }
- { xcode_version: '11.7', simulator: 'name=iPhone SE (2nd generation),OS=13.7' }
- { xcode_version: '12.2', simulator: 'name=iPhone SE (2nd generation),OS=14.2' }
- { xcode_version: '11.7', simulator: 'name=iPhone 8,OS=13.7' }
- { xcode_version: '12.2', simulator: 'name=iPad Pro (12.9-inch) (4th generation),OS=14.2' }

steps:
- name: Checkout Project
Expand Down
11 changes: 11 additions & 0 deletions KIF Tests/ScrollViewTests_ViewTestActor.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import <KIF/KIF.h>
#import "KIFTestStepValidation.h"
#import "UIAccessibilityElement-KIFAdditions.h"
#import "UIView-KIFAdditions.h"

@interface ScrollViewTests_ViewTestActor : KIFTestCase
@end
Expand Down Expand Up @@ -37,4 +39,13 @@ - (void)testScrollingToTapOffscreenTextView
[[viewTester usingLabel:@"TextView"] tap];
}

- (void)testScrollingDownAndUp
{
[[viewTester usingLabel:@"Long Scroll View"] scrollByFractionOfSizeHorizontal:0 vertical:-1];
[[viewTester usingLabel:@"Bottom Label"] waitForView];

[[viewTester usingLabel:@"Long Scroll View"] scrollByFractionOfSizeHorizontal:0 vertical:1];
[[viewTester usingLabel:@"Top Label"] waitForView];
}

@end
19 changes: 19 additions & 0 deletions Sources/KIF/Classes/KIFUITestActor.m
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,25 @@ - (void)scrollAccessibilityElement:(UIAccessibilityElement *)element inView:(UIV
scrollStart.x -= scrollDisplacement.x / 2;
scrollStart.y -= scrollDisplacement.y / 2;

// Scrolling does not work if we are at the end of the view
// So if our scroll start is equal to the heigh, inset 5
if (scrollStart.x == CGRectGetWidth(elementFrame)) {
if (scrollDisplacement.x < 0) {
scrollStart.x -= CGRectGetWidth(elementFrame) * 0.05;
} else {
scrollStart.x += CGRectGetWidth(elementFrame) * 0.05;
}

}

if (scrollStart.y == CGRectGetHeight(elementFrame)) {
if (scrollDisplacement.y < 0) {
scrollStart.y -= CGRectGetHeight(elementFrame) * 0.05;
} else {
scrollStart.y += CGRectGetHeight(elementFrame) * 0.05;
}
}

[viewToScroll dragFromPoint:scrollStart displacement:scrollDisplacement steps:kNumberOfPointsInScrollPath];

[self waitForAnimationsToFinish];
Expand Down
7 changes: 6 additions & 1 deletion Test Host/Base.lproj/MainStoryboard.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1683,15 +1683,20 @@ Line Break
<rect key="frame" x="0.0" y="0.0" width="414" height="808"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="SLR-Kl-7v1">
<rect key="frame" x="20" y="382" width="374" height="216"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
</scrollView>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vCe-NZ-HE8">
<rect key="frame" x="106" y="304" width="200" height="200"/>
<rect key="frame" x="107" y="8" width="200" height="200"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
</scrollView>
</subviews>
<color key="backgroundColor" red="1" green="0.99997437000274658" blue="0.99999129772186279" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<navigationItem key="navigationItem" title="ScrollViews" id="SpZ-dM-ZUT"/>
<connections>
<outlet property="longScrollview" destination="SLR-Kl-7v1" id="All-XX-BDv"/>
<outlet property="scrollView" destination="vCe-NZ-HE8" id="dda-Sp-2kA"/>
</connections>
</viewController>
Expand Down
20 changes: 20 additions & 0 deletions Test Host/ScrollViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import <UIKit/UIKit.h>

@interface ScrollViewController : UIViewController<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *longScrollview;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@end

Expand All @@ -23,6 +24,25 @@ - (void)viewDidLoad
self.scrollView.contentSize = CGSizeMake(2000, 2000);
self.scrollView.delegate = self;

self.longScrollview.accessibilityLabel = @"Long Scroll View";
CGFloat longScrollViewHeight = CGRectGetHeight(self.longScrollview.bounds) * 2;
self.longScrollview.contentSize = CGSizeMake(CGRectGetWidth(self.longScrollview.bounds), longScrollViewHeight);
self.longScrollview.backgroundColor = UIColor.redColor;

UILabel *topLabel = [[UILabel alloc] init];
topLabel.text = @"THIS IS THE TOP";
topLabel.accessibilityLabel = @"Top Label";
topLabel.textAlignment = UITextAlignmentCenter;
[self.longScrollview addSubview:topLabel];
topLabel.frame = CGRectMake(0, 0, CGRectGetWidth(self.longScrollview.bounds), 40);

UILabel *bottomLabel = [[UILabel alloc] init];
bottomLabel.text = @"THIS IS THE BOTTOM";
bottomLabel.accessibilityLabel = @"Bottom Label";
bottomLabel.textAlignment = UITextAlignmentCenter;
[self.longScrollview addSubview:bottomLabel];
bottomLabel.frame = CGRectMake(0, longScrollViewHeight - 40, CGRectGetWidth(self.longScrollview.bounds), 40);

UIButton *bottomButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[bottomButton setTitle:@"Down" forState:UIControlStateNormal];
bottomButton.backgroundColor = [UIColor greenColor];
Expand Down

0 comments on commit 604dc2b

Please sign in to comment.