Skip to content

Commit 604dc2b

Browse files
committed
Add inset on drag and tests
1 parent bdf2298 commit 604dc2b

File tree

5 files changed

+58
-4
lines changed

5 files changed

+58
-4
lines changed

.github/workflows/build.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ jobs:
2020
strategy:
2121
matrix:
2222
run-config:
23-
- { xcode_version: '10.3', simulator: 'name=iPad (5th generation),OS=12.4' }
2423
- { xcode_version: '10.3', simulator: 'name=iPhone 8,OS=12.4' }
25-
- { xcode_version: '11.7', simulator: 'name=iPhone SE (2nd generation),OS=13.7' }
26-
- { xcode_version: '12.2', simulator: 'name=iPhone SE (2nd generation),OS=14.2' }
24+
- { xcode_version: '11.7', simulator: 'name=iPhone 8,OS=13.7' }
25+
- { xcode_version: '12.2', simulator: 'name=iPad Pro (12.9-inch) (4th generation),OS=14.2' }
2726

2827
steps:
2928
- name: Checkout Project

KIF Tests/ScrollViewTests_ViewTestActor.m

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#import <KIF/KIF.h>
1010
#import "KIFTestStepValidation.h"
11+
#import "UIAccessibilityElement-KIFAdditions.h"
12+
#import "UIView-KIFAdditions.h"
1113

1214
@interface ScrollViewTests_ViewTestActor : KIFTestCase
1315
@end
@@ -37,4 +39,13 @@ - (void)testScrollingToTapOffscreenTextView
3739
[[viewTester usingLabel:@"TextView"] tap];
3840
}
3941

42+
- (void)testScrollingDownAndUp
43+
{
44+
[[viewTester usingLabel:@"Long Scroll View"] scrollByFractionOfSizeHorizontal:0 vertical:-1];
45+
[[viewTester usingLabel:@"Bottom Label"] waitForView];
46+
47+
[[viewTester usingLabel:@"Long Scroll View"] scrollByFractionOfSizeHorizontal:0 vertical:1];
48+
[[viewTester usingLabel:@"Top Label"] waitForView];
49+
}
50+
4051
@end

Sources/KIF/Classes/KIFUITestActor.m

+19
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,25 @@ - (void)scrollAccessibilityElement:(UIAccessibilityElement *)element inView:(UIV
13111311
scrollStart.x -= scrollDisplacement.x / 2;
13121312
scrollStart.y -= scrollDisplacement.y / 2;
13131313

1314+
// Scrolling does not work if we are at the end of the view
1315+
// So if our scroll start is equal to the heigh, inset 5
1316+
if (scrollStart.x == CGRectGetWidth(elementFrame)) {
1317+
if (scrollDisplacement.x < 0) {
1318+
scrollStart.x -= CGRectGetWidth(elementFrame) * 0.05;
1319+
} else {
1320+
scrollStart.x += CGRectGetWidth(elementFrame) * 0.05;
1321+
}
1322+
1323+
}
1324+
1325+
if (scrollStart.y == CGRectGetHeight(elementFrame)) {
1326+
if (scrollDisplacement.y < 0) {
1327+
scrollStart.y -= CGRectGetHeight(elementFrame) * 0.05;
1328+
} else {
1329+
scrollStart.y += CGRectGetHeight(elementFrame) * 0.05;
1330+
}
1331+
}
1332+
13141333
[viewToScroll dragFromPoint:scrollStart displacement:scrollDisplacement steps:kNumberOfPointsInScrollPath];
13151334

13161335
[self waitForAnimationsToFinish];

Test Host/Base.lproj/MainStoryboard.storyboard

+6-1
Original file line numberDiff line numberDiff line change
@@ -1683,15 +1683,20 @@ Line Break
16831683
<rect key="frame" x="0.0" y="0.0" width="414" height="808"/>
16841684
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
16851685
<subviews>
1686+
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="SLR-Kl-7v1">
1687+
<rect key="frame" x="20" y="382" width="374" height="216"/>
1688+
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
1689+
</scrollView>
16861690
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="vCe-NZ-HE8">
1687-
<rect key="frame" x="106" y="304" width="200" height="200"/>
1691+
<rect key="frame" x="107" y="8" width="200" height="200"/>
16881692
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
16891693
</scrollView>
16901694
</subviews>
16911695
<color key="backgroundColor" red="1" green="0.99997437000274658" blue="0.99999129772186279" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
16921696
</view>
16931697
<navigationItem key="navigationItem" title="ScrollViews" id="SpZ-dM-ZUT"/>
16941698
<connections>
1699+
<outlet property="longScrollview" destination="SLR-Kl-7v1" id="All-XX-BDv"/>
16951700
<outlet property="scrollView" destination="vCe-NZ-HE8" id="dda-Sp-2kA"/>
16961701
</connections>
16971702
</viewController>

Test Host/ScrollViewController.m

+20
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import <UIKit/UIKit.h>
1010

1111
@interface ScrollViewController : UIViewController<UIScrollViewDelegate>
12+
@property (weak, nonatomic) IBOutlet UIScrollView *longScrollview;
1213
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
1314
@end
1415

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

27+
self.longScrollview.accessibilityLabel = @"Long Scroll View";
28+
CGFloat longScrollViewHeight = CGRectGetHeight(self.longScrollview.bounds) * 2;
29+
self.longScrollview.contentSize = CGSizeMake(CGRectGetWidth(self.longScrollview.bounds), longScrollViewHeight);
30+
self.longScrollview.backgroundColor = UIColor.redColor;
31+
32+
UILabel *topLabel = [[UILabel alloc] init];
33+
topLabel.text = @"THIS IS THE TOP";
34+
topLabel.accessibilityLabel = @"Top Label";
35+
topLabel.textAlignment = UITextAlignmentCenter;
36+
[self.longScrollview addSubview:topLabel];
37+
topLabel.frame = CGRectMake(0, 0, CGRectGetWidth(self.longScrollview.bounds), 40);
38+
39+
UILabel *bottomLabel = [[UILabel alloc] init];
40+
bottomLabel.text = @"THIS IS THE BOTTOM";
41+
bottomLabel.accessibilityLabel = @"Bottom Label";
42+
bottomLabel.textAlignment = UITextAlignmentCenter;
43+
[self.longScrollview addSubview:bottomLabel];
44+
bottomLabel.frame = CGRectMake(0, longScrollViewHeight - 40, CGRectGetWidth(self.longScrollview.bounds), 40);
45+
2646
UIButton *bottomButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
2747
[bottomButton setTitle:@"Down" forState:UIControlStateNormal];
2848
bottomButton.backgroundColor = [UIColor greenColor];

0 commit comments

Comments
 (0)